Skip to content

Commit

Permalink
Merge pull request #12 from timonf/transcoder-upgrade
Browse files Browse the repository at this point in the history
Support for Symfony >= 4, PHP 7.4 / 8
  • Loading branch information
jojoguru authored Oct 19, 2021
2 parents 4f9fe8b + 332d6ad commit 4b89e97
Show file tree
Hide file tree
Showing 45 changed files with 256 additions and 180 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "Test"

on:
push:
pull_request:
schedule:
- cron: '0 03 * * 1' # At 03:00 on Monday.

jobs:
tests:
name: "Tests"

runs-on: ${{ matrix.operating-system }}

strategy:
matrix:
dependencies: ["lowest", "highest"]
php-version:
- "7.4"
- "8.0"
- "8.1"
operating-system: ["ubuntu-latest"]

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"

- name: "Cache dependencies"
uses: "actions/cache@v2"
with:
path: "~/.composer/cache"
key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-"

- name: "Install lowest dependencies"
if: ${{ matrix.dependencies == 'lowest' }}
run: "composer update --prefer-lowest --prefer-dist --no-interaction --no-progress --no-suggest"

- name: "Install highest dependencies"
if: ${{ matrix.dependencies == 'highest' }}
run: "composer update --prefer-dist --no-interaction --no-progress --no-suggest"

- name: "Unit tests"
run: "vendor/bin/phpunit"

- name: "Coding style"
run: "vendor/bin/phpcs --report=summary"

- name: "Static analysis"
run: "vendor/bin/phpstan --no-progress"
6 changes: 0 additions & 6 deletions .scrutinizer.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
Transcoder Library
==================

[![SensioLabsInsight](https://insight.sensiolabs.com/projects/101113a8-06da-4547-aae8-cc9c77027c5b/mini.png)](https://insight.sensiolabs.com/projects/101113a8-06da-4547-aae8-cc9c77027c5b)
[![Build Status](https://travis-ci.org/brainbits/transcoder.png?branch=master)](https://travis-ci.org/brainbits/transcoder)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/brainbits/transcoder/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/brainbits/transcoder/?branch=master)
[![Scrutinizer Code Coverage](https://scrutinizer-ci.com/g/brainbits/transcoder/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/brainbits/transcoder/?branch=master)
[![Latest Stable Version](https://poser.pugx.org/brainbits/transcoder/v/stable.svg)](https://packagist.org/packages/brainbits/transcoder)
[![Total Downloads](https://poser.pugx.org/brainbits/transcoder/downloads.svg)](https://packagist.org/packages/brainbits/transcoder)
[![Dependency Status](https://www.versioneye.com/php/brainbits:transcoder/master/badge.svg)](https://www.versioneye.com/php/brainbits:transcoder/master)
[![Tests](https://github.com/brainbits/transcoder/actions/workflows/test.yml/badge.svg)](https://github.com/brainbits/transcoder/actions)

The Transcoder Library provides methods to transcode data.
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@
}
],
"require": {
"php": "^7.1",
"php": "^7.4|^8.0",
"psr/log": "^1.0",
"symfony/process": "^2.8|^3.0"
"symfony/process": ">=4.4"
},
"require-dev": {
"phpunit/phpunit": "^6.0"
"phpunit/phpunit": "^9.5",
"phpspec/prophecy-phpunit": "^2.0",
"squizlabs/php_codesniffer": "^3.6",
"brainbits/phpcs-standard": "^5.0",
"phpstan/phpstan": "^0.12.99",
"brainbits/phpstan-rules": "^2.0"
},
"autoload": {
"psr-4": { "Brainbits\\Transcoder\\": "src/" }
Expand All @@ -34,7 +39,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
"dev-master": "4.0-dev"
}
}
}
10 changes: 10 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
<file extension="php">src/</file>
<arg name="basepath" value="." />
<arg name="colors" />
<rule ref="Brainbits">
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix" />
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix" />
</rule>
</ruleset>
9 changes: 9 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
checkMissingIterableValueType: false
level: max
paths:
- src
bootstrapFiles:
- vendor/autoload.php
includes:
- vendor/brainbits/phpstan-rules/rules.neon
10 changes: 2 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
syntaxCheck="true">
convertWarningsToExceptions="true">
<testsuite name="transcoder">
<directory>tests</directory>
<directory suffix=".php">tests</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
20 changes: 13 additions & 7 deletions src/Decoder/Bzip2Decoder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

/*
* This file is part of the brainbits transcoder package.
Expand All @@ -15,38 +15,44 @@

use Brainbits\Transcoder\Exception\DecodeFailedException;

use function bzdecompress;
use function is_string;

/**
* Bzip2 decoder.
*/
class Bzip2Decoder implements DecoderInterface
{
const TYPE = 'bzip2';
public const TYPE = 'bzip2';

public function decode(string $data): string
{
$data = bzdecompress($data);

if ($this->isErrorCode($data)) {
throw new DecodeFailedException("bzdecompress failed.");
throw new DecodeFailedException('bzdecompress failed.');
}

if (!$data) {
throw new DecodeFailedException("bzdecompress returned no data.");
throw new DecodeFailedException('bzdecompress returned no data.');
}

if (!is_string($data)) {
throw new DecodeFailedException('bzdecompress returned error code.');
}

return $data;
}

public function supports(?string $type): bool
{
return self::TYPE === $type;
return $type === self::TYPE;
}

/**
* @param mixed $result
*
* @return bool
*/
// phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
private function isErrorCode($result): bool
{
return $result === -1 || $result === -2 || $result === -3 || $result === -5 || $result === -6 ||
Expand Down
2 changes: 1 addition & 1 deletion src/Decoder/DecoderInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

/*
* This file is part of the brainbits transcoder package.
Expand Down
16 changes: 8 additions & 8 deletions src/Decoder/DecoderResolver.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

/*
* This file is part of the brainbits transcoder package.
Expand All @@ -13,23 +13,23 @@

namespace Brainbits\Transcoder\Decoder;

use RuntimeException;
use Brainbits\Transcoder\Exception\RuntimeException;

use function sprintf;

/**
* Decoder resolver.
* Resolves decoders based on supported type.
*/
class DecoderResolver implements DecoderResolverInterface
{
/**
* @var DecoderInterface[]
*/
private $decoders = array();
/** @var DecoderInterface[] */
private array $decoders = [];

/**
* @param DecoderInterface[] $decoders
*/
public function __construct(array $decoders = array())
public function __construct(array $decoders = [])
{
foreach ($decoders as $decoder) {
$this->addDecoder($decoder);
Expand All @@ -44,7 +44,7 @@ public function resolve(?string $type): DecoderInterface
}
}

throw new RuntimeException("No decoder supports the requested type $type");
throw new RuntimeException(sprintf('No decoder supports the requested type %s', (string) $type));
}

private function addDecoder(DecoderInterface $decoder): void
Expand Down
2 changes: 1 addition & 1 deletion src/Decoder/DecoderResolverInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

/*
* This file is part of the brainbits transcoder package.
Expand Down
10 changes: 6 additions & 4 deletions src/Decoder/DeflateDecoder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

/*
* This file is part of the brainbits transcoder package.
Expand All @@ -15,26 +15,28 @@

use Brainbits\Transcoder\Exception\DecodeFailedException;

use function gzinflate;

/**
* Deflate decoder.
*/
class DeflateDecoder implements DecoderInterface
{
const TYPE = 'deflate';
public const TYPE = 'deflate';

public function decode(string $data): string
{
$data = gzinflate($data);

if (!$data) {
throw new DecodeFailedException("gzinflate returned no data.");
throw new DecodeFailedException('gzinflate returned no data.');
}

return $data;
}

public function supports(?string $type): bool
{
return self::TYPE === $type;
return $type === self::TYPE;
}
}
10 changes: 6 additions & 4 deletions src/Decoder/GzipDecoder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

/*
* This file is part of the brainbits transcoder package.
Expand All @@ -15,26 +15,28 @@

use Brainbits\Transcoder\Exception\DecodeFailedException;

use function gzdecode;

/**
* Gzip decoder.
*/
class GzipDecoder implements DecoderInterface
{
const TYPE = 'gzip';
public const TYPE = 'gzip';

public function decode(string $data): string
{
$data = gzdecode($data);

if (!$data) {
throw new DecodeFailedException("gzinflate returned no data.");
throw new DecodeFailedException('gzinflate returned no data.');
}

return $data;
}

public function supports(?string $type): bool
{
return self::TYPE === $type;
return $type === self::TYPE;
}
}
6 changes: 3 additions & 3 deletions src/Decoder/NullDecoder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

/*
* This file is part of the brainbits transcoder package.
Expand All @@ -18,7 +18,7 @@
*/
class NullDecoder implements DecoderInterface
{
const TYPE = 'null';
public const TYPE = 'null';

public function decode(string $data): string
{
Expand All @@ -27,6 +27,6 @@ public function decode(string $data): string

public function supports(?string $type): bool
{
return null === $type || self::TYPE === $type;
return $type === null || $type === self::TYPE;
}
}
Loading

0 comments on commit 4b89e97

Please sign in to comment.