From d0d32322fca1b26c46cf0275b5e70e561914ddee Mon Sep 17 00:00:00 2001 From: timonf <546813+timonf@users.noreply.github.com> Date: Tue, 12 Oct 2021 17:08:00 +0200 Subject: [PATCH 1/5] allow symfony 4 or higher, use phpunit 9.5, raise minimum php version to 7.4, remove sensiolabs insight --- .travis.yml | 3 ++- README.md | 1 - composer.json | 7 ++++--- src/Decoder/SevenzDecoder.php | 7 +++---- src/Encoder/SevenzEncoder.php | 7 +++---- tests/Decoder/Bzip2DecoderTest.php | 10 +++++----- tests/Decoder/DecoderResolverTest.php | 13 +++++++------ tests/Decoder/DeflateDecoderTest.php | 8 ++++---- tests/Decoder/GzipDecoderTest.php | 8 ++++---- tests/Decoder/NullDecoderTest.php | 6 +++--- tests/Decoder/SevenzDecoderTest.php | 10 +++++----- tests/Encoder/Bzip2EncoderTest.php | 2 +- tests/Encoder/DeflateEncoderTest.php | 6 +++--- tests/Encoder/EncoderResolverTest.php | 8 +++++--- tests/Encoder/GzipEncoderTest.php | 6 +++--- tests/Encoder/NullEncoderTest.php | 6 +++--- tests/Encoder/SevenzEncoderTest.php | 8 ++++---- tests/TranscoderFactoryTest.php | 12 +++++++----- tests/TranscoderTest.php | 8 +++++--- 19 files changed, 71 insertions(+), 65 deletions(-) diff --git a/.travis.yml b/.travis.yml index ef7e0c7..8898cc0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ language: php php: - - 7.1 + - 7.4 + - 8.0 - nightly matrix: diff --git a/README.md b/README.md index b80dc48..e2fcc26 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ 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) diff --git a/composer.json b/composer.json index 42d2c28..0976094 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,13 @@ } ], "require": { - "php": "^7.1", + "php": ">=7.4", "psr/log": "^1.0", - "symfony/process": "^2.8|^3.0" + "symfony/process": ">=4.0" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.5", + "phpspec/prophecy-phpunit": "^2.0" }, "autoload": { "psr-4": { "Brainbits\\Transcoder\\": "src/" } diff --git a/src/Decoder/SevenzDecoder.php b/src/Decoder/SevenzDecoder.php index 3cc62be..66033c9 100644 --- a/src/Decoder/SevenzDecoder.php +++ b/src/Decoder/SevenzDecoder.php @@ -15,7 +15,6 @@ use Brainbits\Transcoder\Exception\DecodeFailedException; use Symfony\Component\Process\Process; -use Symfony\Component\Process\ProcessBuilder; /** * 7z decoder. @@ -57,11 +56,11 @@ public function supports(?string $type): bool private function getProcess(string $data): Process { - $processBuilder = new ProcessBuilder( + $process = new Process( [$this->executable, 'e', '-si', '-so', '-an', '-txz', '-m0=lzma2', '-mx=9', '-mfb=64', '-md=32m'] ); - $processBuilder->setInput($data); + $process->setInput($data); - return $processBuilder->getProcess(); + return $process; } } diff --git a/src/Encoder/SevenzEncoder.php b/src/Encoder/SevenzEncoder.php index f0310cd..e8887b4 100644 --- a/src/Encoder/SevenzEncoder.php +++ b/src/Encoder/SevenzEncoder.php @@ -15,7 +15,6 @@ use Brainbits\Transcoder\Exception\EncodeFailedException; use Symfony\Component\Process\Process; -use Symfony\Component\Process\ProcessBuilder; /** * 7z encoder. @@ -57,11 +56,11 @@ public function supports(?string $type): bool private function getProcess(string $data): Process { - $processBuilder = new ProcessBuilder( + $process = new Process( [$this->executable, 'a', '-si', '-so', '-an', '-txz', '-m0=lzma2', '-mx=9', '-mfb=64', '-md=32m'] ); - $processBuilder->setInput($data); + $process->setInput($data); - return $processBuilder->getProcess(); + return $process; } } diff --git a/tests/Decoder/Bzip2DecoderTest.php b/tests/Decoder/Bzip2DecoderTest.php index be27768..9591a15 100644 --- a/tests/Decoder/Bzip2DecoderTest.php +++ b/tests/Decoder/Bzip2DecoderTest.php @@ -25,12 +25,12 @@ class Bzip2DecoderTest extends TestCase */ private $decoder; - protected function setUp() + protected function setUp(): void { $this->decoder = new Bzip2Decoder(); } - public function testDecode() + public function testDecode(): void { $testString = 'a string to be decompressed'; $encodedString = bzcompress($testString); @@ -40,7 +40,7 @@ public function testDecode() $this->assertSame($testString, $result); } - public function testDecodeThrowsErrorOnEmptyResult() + public function testDecodeThrowsErrorOnEmptyResult(): void { $this->expectException(DecodeFailedException::class); @@ -52,7 +52,7 @@ public function testDecodeThrowsErrorOnEmptyResult() $this->assertSame($testString, $result); } - public function testDecodeError() + public function testDecodeError(): void { $this->expectException(DecodeFailedException::class); @@ -61,7 +61,7 @@ public function testDecodeError() $this->decoder->decode($testString); } - public function testSupports() + public function testSupports(): void { $this->assertTrue($this->decoder->supports('bzip2')); $this->assertFalse($this->decoder->supports('foo')); diff --git a/tests/Decoder/DecoderResolverTest.php b/tests/Decoder/DecoderResolverTest.php index 460be1e..7a591b9 100644 --- a/tests/Decoder/DecoderResolverTest.php +++ b/tests/Decoder/DecoderResolverTest.php @@ -15,6 +15,7 @@ use Brainbits\Transcoder\Decoder\DecoderResolver; use Brainbits\Transcoder\Tests\TranscoderTestHelper; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use RuntimeException; @@ -23,12 +24,13 @@ */ class DecoderResolverTest extends TestCase { + use ProphecyTrait; use TranscoderTestHelper; /** * @expectedException RuntimeException */ - public function testResolveThrowsRuntimeExceptionWithoutDecoders() + public function testResolveThrowsRuntimeExceptionWithoutDecoders(): void { $this->expectException(RuntimeException::class); @@ -37,11 +39,10 @@ public function testResolveThrowsRuntimeExceptionWithoutDecoders() $resolver->resolve('test'); } - /** - * @expectedException RuntimeException - */ - public function testResolveRuntimeExceptionWithoutMatchingDecoder() + public function testResolveRuntimeExceptionWithoutMatchingDecoder(): void { + $this->expectException(RuntimeException::class); + $decoder = $this->prophesizeDecoder(); $decoder->supports('test') ->shouldBeCalled() @@ -52,7 +53,7 @@ public function testResolveRuntimeExceptionWithoutMatchingDecoder() $resolver->resolve('test'); } - public function testResolveReturnsCorrectDecoder() + public function testResolveReturnsCorrectDecoder(): void { $decoder = $this->prophesizeDecoder(); $decoder->supports('test') diff --git a/tests/Decoder/DeflateDecoderTest.php b/tests/Decoder/DeflateDecoderTest.php index 39840ed..ded0d83 100644 --- a/tests/Decoder/DeflateDecoderTest.php +++ b/tests/Decoder/DeflateDecoderTest.php @@ -25,12 +25,12 @@ class DeflateDecoderTest extends TestCase */ private $decoder; - protected function setUp() + protected function setUp(): void { $this->decoder = new DeflateDecoder(); } - public function testDecode() + public function testDecode(): void { $testString = 'a string to be decompressed'; $encodedString = gzdeflate($testString); @@ -40,7 +40,7 @@ public function testDecode() $this->assertSame($testString, $result); } - public function testDecodeThrowsErrorOnEmptyResult() + public function testDecodeThrowsErrorOnEmptyResult(): void { $this->expectException(DecodeFailedException::class); @@ -52,7 +52,7 @@ public function testDecodeThrowsErrorOnEmptyResult() $this->assertSame($testString, $result); } - public function testSupports() + public function testSupports(): void { $this->assertTrue($this->decoder->supports('deflate')); $this->assertFalse($this->decoder->supports('foo')); diff --git a/tests/Decoder/GzipDecoderTest.php b/tests/Decoder/GzipDecoderTest.php index af947f9..7d828c2 100644 --- a/tests/Decoder/GzipDecoderTest.php +++ b/tests/Decoder/GzipDecoderTest.php @@ -25,12 +25,12 @@ class GzipDecoderTest extends TestCase */ private $decoder; - protected function setUp() + protected function setUp(): void { $this->decoder = new GzipDecoder(); } - public function testDecode() + public function testDecode(): void { $testString = 'a string to be decompressed'; $encodedString = gzencode($testString); @@ -40,7 +40,7 @@ public function testDecode() $this->assertSame($testString, $result); } - public function testDecodeThrowsErrorOnEmptyResult() + public function testDecodeThrowsErrorOnEmptyResult(): void { $this->expectException(DecodeFailedException::class); @@ -52,7 +52,7 @@ public function testDecodeThrowsErrorOnEmptyResult() $this->assertSame($testString, $result); } - public function testSupports() + public function testSupports(): void { $this->assertTrue($this->decoder->supports('gzip')); $this->assertFalse($this->decoder->supports('foo')); diff --git a/tests/Decoder/NullDecoderTest.php b/tests/Decoder/NullDecoderTest.php index fa083ce..f01c3bf 100644 --- a/tests/Decoder/NullDecoderTest.php +++ b/tests/Decoder/NullDecoderTest.php @@ -24,12 +24,12 @@ class NullDecoderTest extends TestCase */ private $decoder; - protected function setUp() + protected function setUp(): void { $this->decoder = new NullDecoder(); } - public function testDecode() + public function testDecode(): void { $testString = 'a string to be decompressed'; @@ -38,7 +38,7 @@ public function testDecode() $this->assertSame($testString, $result); } - public function testSupports() + public function testSupports(): void { $this->assertTrue($this->decoder->supports('null')); $this->assertTrue($this->decoder->supports(null)); diff --git a/tests/Decoder/SevenzDecoderTest.php b/tests/Decoder/SevenzDecoderTest.php index 9b668e9..b3bfe17 100644 --- a/tests/Decoder/SevenzDecoderTest.php +++ b/tests/Decoder/SevenzDecoderTest.php @@ -20,21 +20,21 @@ */ class SevenzDecoderTest extends TestCase { - public function testEmptyConstructor() + public function testEmptyConstructor(): void { $decoder = new SevenzDecoder(); $this->assertSame('7z', $decoder->getExecutable()); } - public function testExecutable() + public function testExecutable(): void { $decoder = new SevenzDecoder('foo'); $this->assertSame('foo', $decoder->getExecutable()); } - public function testSupports() + public function testSupports(): void { $decoder = new SevenzDecoder(); @@ -42,7 +42,7 @@ public function testSupports() $this->assertFalse($decoder->supports('foo')); } - public function testDecode() + public function testDecode(): void { $rc = null; $out = null; @@ -65,7 +65,7 @@ public function testDecode() /** * @depends testDecode */ - public function testFail() + public function testFail(): void { $this->expectException(DecodeFailedException::class); diff --git a/tests/Encoder/Bzip2EncoderTest.php b/tests/Encoder/Bzip2EncoderTest.php index c349fef..d41cce9 100644 --- a/tests/Encoder/Bzip2EncoderTest.php +++ b/tests/Encoder/Bzip2EncoderTest.php @@ -24,7 +24,7 @@ class Bzip2EncoderTest extends TestCase */ private $encoder; - protected function setUp() + protected function setUp(): void { $this->encoder = new Bzip2Encoder(); } diff --git a/tests/Encoder/DeflateEncoderTest.php b/tests/Encoder/DeflateEncoderTest.php index a3162b1..8657c04 100644 --- a/tests/Encoder/DeflateEncoderTest.php +++ b/tests/Encoder/DeflateEncoderTest.php @@ -24,12 +24,12 @@ class DeflateEncoderTest extends TestCase */ private $encoder; - protected function setUp() + protected function setUp(): void { $this->encoder = new DeflateEncoder(); } - public function testEncode() + public function testEncode(): void { $testString = 'a string to be compressed'; @@ -40,7 +40,7 @@ public function testEncode() $this->assertSame($testString, $uncompressedResult); } - public function testSupports() + public function testSupports(): void { $this->assertTrue($this->encoder->supports('deflate')); $this->assertFalse($this->encoder->supports('foo')); diff --git a/tests/Encoder/EncoderResolverTest.php b/tests/Encoder/EncoderResolverTest.php index 5f2c963..b80cfeb 100644 --- a/tests/Encoder/EncoderResolverTest.php +++ b/tests/Encoder/EncoderResolverTest.php @@ -15,6 +15,7 @@ use Brainbits\Transcoder\Encoder\EncoderResolver; use Brainbits\Transcoder\Tests\TranscoderTestHelper; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use RuntimeException; /** @@ -22,9 +23,10 @@ */ class EncoderResolverTest extends TestCase { + use ProphecyTrait; use TranscoderTestHelper; - public function testResolveThrowsRuntimeExceptionWithoutDecoders() + public function testResolveThrowsRuntimeExceptionWithoutDecoders(): void { $this->expectException(RuntimeException::class); @@ -33,7 +35,7 @@ public function testResolveThrowsRuntimeExceptionWithoutDecoders() $resolver->resolve('test'); } - public function testResolveRuntimeExceptionWithoutMatchingDecoder() + public function testResolveRuntimeExceptionWithoutMatchingDecoder(): void { $this->expectException(RuntimeException::class); @@ -47,7 +49,7 @@ public function testResolveRuntimeExceptionWithoutMatchingDecoder() $resolver->resolve('test'); } - public function testResolveReturnsCorrectDecoder() + public function testResolveReturnsCorrectDecoder(): void { $encoder = $this->prophesizeEncoder(); $encoder->supports('test') diff --git a/tests/Encoder/GzipEncoderTest.php b/tests/Encoder/GzipEncoderTest.php index cc08fbe..cb994ac 100644 --- a/tests/Encoder/GzipEncoderTest.php +++ b/tests/Encoder/GzipEncoderTest.php @@ -24,12 +24,12 @@ class GzipEncoderTest extends TestCase */ private $encoder; - protected function setUp() + protected function setUp(): void { $this->encoder = new GzipEncoder(); } - public function testEncode() + public function testEncode(): void { $testString = 'a string to be compressed'; @@ -40,7 +40,7 @@ public function testEncode() $this->assertSame($testString, $uncompressedResult); } - public function testSupports() + public function testSupports(): void { $this->assertTrue($this->encoder->supports('gzip')); $this->assertFalse($this->encoder->supports('foo')); diff --git a/tests/Encoder/NullEncoderTest.php b/tests/Encoder/NullEncoderTest.php index 5bcdac9..4dd7f3a 100644 --- a/tests/Encoder/NullEncoderTest.php +++ b/tests/Encoder/NullEncoderTest.php @@ -24,12 +24,12 @@ class NullEncoderTest extends TestCase */ private $encoder; - protected function setUp() + protected function setUp(): void { $this->encoder = new NullEncoder(); } - public function testEncode() + public function testEncode(): void { $testString = 'a string to be compressed'; @@ -38,7 +38,7 @@ public function testEncode() $this->assertSame($testString, $result); } - public function testSupports() + public function testSupports(): void { $this->assertTrue($this->encoder->supports('null')); $this->assertTrue($this->encoder->supports(null)); diff --git a/tests/Encoder/SevenzEncoderTest.php b/tests/Encoder/SevenzEncoderTest.php index 9543a0c..19f208c 100644 --- a/tests/Encoder/SevenzEncoderTest.php +++ b/tests/Encoder/SevenzEncoderTest.php @@ -19,21 +19,21 @@ */ class SevenzEncoderTest extends TestCase { - public function testEmptyConstructor() + public function testEmptyConstructor(): void { $encoder = new SevenzEncoder(); $this->assertSame('7z', $encoder->getExecutable()); } - public function testExecutable() + public function testExecutable(): void { $encoder = new SevenzEncoder('foo'); $this->assertSame('foo', $encoder->getExecutable()); } - public function testSupports() + public function testSupports(): void { $encoder = new SevenzEncoder(); @@ -41,7 +41,7 @@ public function testSupports() $this->assertFalse($encoder->supports('foo')); } - public function testEncode() + public function testEncode(): void { $rc = null; $out = null; diff --git a/tests/TranscoderFactoryTest.php b/tests/TranscoderFactoryTest.php index 3180380..7515f8f 100644 --- a/tests/TranscoderFactoryTest.php +++ b/tests/TranscoderFactoryTest.php @@ -18,6 +18,7 @@ use Brainbits\Transcoder\TranscoderFactory; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Psr\Log\LoggerInterface; @@ -26,6 +27,7 @@ */ class TranscoderFactoryTest extends TestCase { + use ProphecyTrait; use TranscoderTestHelper; /** @@ -58,7 +60,7 @@ class TranscoderFactoryTest extends TestCase */ private $transcoderFactory; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -77,7 +79,7 @@ protected function setUp() ); } - public function testEncoderFactoryIsCalledWithEncoderType() + public function testEncoderFactoryIsCalledWithEncoderType(): void { $expectedEncoder = 'encoder'; @@ -92,7 +94,7 @@ public function testEncoderFactoryIsCalledWithEncoderType() $this->transcoderFactory->createTranscoder(null, $expectedEncoder); } - public function testEncoderFactoryIsCalledWithDecoderType() + public function testEncoderFactoryIsCalledWithDecoderType(): void { $expectedDecoder = 'decoder'; @@ -107,7 +109,7 @@ public function testEncoderFactoryIsCalledWithDecoderType() $this->transcoderFactory->createTranscoder($expectedDecoder, null); } - public function testPassThroughTranscoderIsCreatedForSameDecoderEncoder() + public function testPassThroughTranscoderIsCreatedForSameDecoderEncoder(): void { $expectedEncoder = $expectedDecoder = 'same'; @@ -122,7 +124,7 @@ public function testPassThroughTranscoderIsCreatedForSameDecoderEncoder() $this->transcoderFactory->createTranscoder($expectedDecoder, $expectedEncoder); } - public function testTranscoderWasCreatedWithCreatedFactories() + public function testTranscoderWasCreatedWithCreatedFactories(): void { $this->encoderResolver->resolve('encode') ->shouldBeCalled() diff --git a/tests/TranscoderTest.php b/tests/TranscoderTest.php index 5924340..26b0916 100644 --- a/tests/TranscoderTest.php +++ b/tests/TranscoderTest.php @@ -15,6 +15,7 @@ use Brainbits\Transcoder\Encoder\EncoderInterface; use Brainbits\Transcoder\Transcoder; use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; /** @@ -22,6 +23,7 @@ */ class TranscoderTest extends TestCase { + use ProphecyTrait; use TranscoderTestHelper; /** @@ -39,7 +41,7 @@ class TranscoderTest extends TestCase */ private $transcoder; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -49,12 +51,12 @@ protected function setUp() $this->transcoder = new Transcoder($this->decoder->reveal(), $this->encoder->reveal()); } - public function testConstructor() + public function testConstructor(): void { $this->assertInstanceOf(Transcoder::class, $this->transcoder); } - public function testTranscode() + public function testTranscode(): void { $encodedValue = 'encoded'; $decodedValue = 'decoded'; From e508e8ee52851bf33da62f6aa384d9115919c7ac Mon Sep 17 00:00:00 2001 From: timonf <546813+timonf@users.noreply.github.com> Date: Mon, 18 Oct 2021 10:36:25 +0200 Subject: [PATCH 2/5] build: add GitHub actions --- .github/workflows/test.yml | 52 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 22 ---------------- composer.json | 6 ++++- phpcs.xml | 10 ++++++++ phpstan.neon | 9 +++++++ phpunit.xml.dist | 10 ++------ 6 files changed, 78 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml create mode 100644 phpcs.xml create mode 100644 phpstan.neon diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6801538 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,52 @@ +name: "Test" + +on: [push, pull_request] + +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" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8898cc0..0000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -language: php - -php: - - 7.4 - - 8.0 - - nightly - -matrix: - allow_failures: - - php: - - nightly - -before_install: - - sudo apt-get update -qq - - sudo apt-get install -y p7zip-full - -before_script: composer install - -script: vendor/bin/phpunit tests --coverage-clover=coverage.clover - -after_script: - - sh -c 'if [ $(phpenv version-name) = "7.1" ]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi;' diff --git a/composer.json b/composer.json index 0976094..46f987f 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,11 @@ }, "require-dev": { "phpunit/phpunit": "^9.5", - "phpspec/prophecy-phpunit": "^2.0" + "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/" } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..2ab273e --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,10 @@ + + + src/ + + + + + + + diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..0a114ff --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,9 @@ +parameters: + checkMissingIterableValueType: false + level: 8 + paths: + - src + bootstrapFiles: + - vendor/autoload.php +includes: + - vendor/brainbits/phpstan-rules/rules.neon diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 642a0bd..4dda885 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,14 +3,8 @@ colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" - convertWarningsToExceptions="true" - syntaxCheck="true"> + convertWarningsToExceptions="true"> - tests + tests - - - src/ - - From f8bbed9a624e40217663a11a73775f7b0ec01010 Mon Sep 17 00:00:00 2001 From: timonf <546813+timonf@users.noreply.github.com> Date: Mon, 18 Oct 2021 10:38:00 +0200 Subject: [PATCH 3/5] fix: fix phpstan and phpcs errors --- src/Decoder/Bzip2Decoder.php | 20 +++++++++++++------- src/Decoder/DecoderInterface.php | 2 +- src/Decoder/DecoderResolver.php | 16 ++++++++-------- src/Decoder/DecoderResolverInterface.php | 2 +- src/Decoder/DeflateDecoder.php | 10 ++++++---- src/Decoder/GzipDecoder.php | 10 ++++++---- src/Decoder/NullDecoder.php | 6 +++--- src/Decoder/SevenzDecoder.php | 10 +++++----- src/Encoder/Bzip2Encoder.php | 15 +++++++++++---- src/Encoder/DeflateEncoder.php | 10 ++++++---- src/Encoder/EncoderInterface.php | 2 +- src/Encoder/EncoderResolver.php | 16 +++++++++------- src/Encoder/EncoderResolverInterface.php | 2 +- src/Encoder/GzipEncoder.php | 10 ++++++---- src/Encoder/NullEncoder.php | 6 +++--- src/Encoder/SevenzEncoder.php | 10 +++++----- src/Exception/DecodeFailedException.php | 2 +- src/Exception/EncodeFailedException.php | 2 +- src/Exception/ExceptionInterface.php | 2 +- src/Exception/RuntimeException.php | 2 +- src/Transcoder.php | 6 +++--- src/TranscoderFactory.php | 17 +++++++++++------ src/TranscoderInterface.php | 2 +- 23 files changed, 104 insertions(+), 76 deletions(-) diff --git a/src/Decoder/Bzip2Decoder.php b/src/Decoder/Bzip2Decoder.php index e8c10bf..212cf40 100644 --- a/src/Decoder/Bzip2Decoder.php +++ b/src/Decoder/Bzip2Decoder.php @@ -1,6 +1,6 @@ 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; @@ -39,14 +46,13 @@ public function decode(string $data): string 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 || diff --git a/src/Decoder/DecoderInterface.php b/src/Decoder/DecoderInterface.php index ca6f185..ff80ab5 100644 --- a/src/Decoder/DecoderInterface.php +++ b/src/Decoder/DecoderInterface.php @@ -1,6 +1,6 @@ addDecoder($decoder); @@ -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 diff --git a/src/Decoder/DecoderResolverInterface.php b/src/Decoder/DecoderResolverInterface.php index a68c70c..2d642ec 100644 --- a/src/Decoder/DecoderResolverInterface.php +++ b/src/Decoder/DecoderResolverInterface.php @@ -1,6 +1,6 @@ run(); if (!$process->isSuccessful()) { - throw new DecodeFailedException('7z failure: '.$process->getOutput().$process->getErrorOutput()); + throw new DecodeFailedException('7z failure: ' . $process->getOutput() . $process->getErrorOutput()); } $data = $process->getOutput(); @@ -51,7 +51,7 @@ public function decode(string $data): string public function supports(?string $type): bool { - return self::TYPE === $type; + return $type === self::TYPE; } private function getProcess(string $data): Process diff --git a/src/Encoder/Bzip2Encoder.php b/src/Encoder/Bzip2Encoder.php index 7c5192f..aad69a7 100644 --- a/src/Encoder/Bzip2Encoder.php +++ b/src/Encoder/Bzip2Encoder.php @@ -1,6 +1,6 @@ addEncoder($encoder); @@ -42,7 +44,7 @@ public function resolve(?string $type): EncoderInterface } } - throw new \RuntimeException("No decoder supports the requested type $type"); + throw new RuntimeException(sprintf('No decoder supports the requested type %s', $type)); } private function addEncoder(EncoderInterface $encoder): void diff --git a/src/Encoder/EncoderResolverInterface.php b/src/Encoder/EncoderResolverInterface.php index b659e55..1bd88c5 100644 --- a/src/Encoder/EncoderResolverInterface.php +++ b/src/Encoder/EncoderResolverInterface.php @@ -1,6 +1,6 @@ run(); if (!$process->isSuccessful()) { - throw new EncodeFailedException('7z failure: '.$process->getOutput().$process->getErrorOutput()); + throw new EncodeFailedException('7z failure: ' . $process->getOutput() . $process->getErrorOutput()); } $data = $process->getOutput(); @@ -51,7 +51,7 @@ public function encode(string $data): string public function supports(?string $type): bool { - return self::TYPE === $type; + return $type === self::TYPE; } private function getProcess(string $data): Process diff --git a/src/Exception/DecodeFailedException.php b/src/Exception/DecodeFailedException.php index f42c22f..971803b 100644 --- a/src/Exception/DecodeFailedException.php +++ b/src/Exception/DecodeFailedException.php @@ -1,6 +1,6 @@ logger->debug("Creating transcoder with input type $inputType and output type $outputType"); + $this->logger->debug(sprintf( + 'Creating transcoder with input type %s and output type %s', + $inputType, + $outputType, + )); if ($inputType === $outputType) { $inputType = $outputType = null; @@ -50,5 +56,4 @@ public function createTranscoder(?string $inputType = null, ?string $outputType return new Transcoder($decoder, $encoder); } - } diff --git a/src/TranscoderInterface.php b/src/TranscoderInterface.php index a5f6488..e0af55d 100644 --- a/src/TranscoderInterface.php +++ b/src/TranscoderInterface.php @@ -1,6 +1,6 @@ Date: Mon, 18 Oct 2021 13:38:28 +0200 Subject: [PATCH 4/5] build: fix dependencies and add scheduled tests --- .github/workflows/test.yml | 6 +++++- composer.json | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6801538..e1ffe65 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,10 @@ name: "Test" -on: [push, pull_request] +on: + push: + pull_request: + schedule: + - cron: '0 03 * * 1' # At 03:00 on Monday. jobs: tests: diff --git a/composer.json b/composer.json index 46f987f..ed2d758 100644 --- a/composer.json +++ b/composer.json @@ -19,9 +19,9 @@ } ], "require": { - "php": ">=7.4", + "php": "^7.4|^8.0", "psr/log": "^1.0", - "symfony/process": ">=4.0" + "symfony/process": ">=4.4" }, "require-dev": { "phpunit/phpunit": "^9.5", From 332d6adcc0020bfa7781f19559a9cd7423721ca9 Mon Sep 17 00:00:00 2001 From: timonf <546813+timonf@users.noreply.github.com> Date: Tue, 19 Oct 2021 12:16:14 +0200 Subject: [PATCH 5/5] build: remove Scrutinizer optimize phpstan file update build badges --- .github/workflows/test.yml | 2 +- .scrutinizer.yml | 6 ------ README.md | 5 +---- composer.json | 2 +- phpstan.neon | 2 +- 5 files changed, 4 insertions(+), 13 deletions(-) delete mode 100644 .scrutinizer.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e1ffe65..3de4384 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ on: push: pull_request: schedule: - - cron: '0 03 * * 1' # At 03:00 on Monday. + - cron: '0 03 * * 1' # At 03:00 on Monday. jobs: tests: diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index da18520..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,6 +0,0 @@ -inherit: true -imports: - - php -tools: - external_code_coverage: - timeout: 600 # Timeout in seconds. diff --git a/README.md b/README.md index e2fcc26..d0bc9da 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,8 @@ Transcoder Library ================== -[![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. diff --git a/composer.json b/composer.json index ed2d758..9795fec 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "4.0-dev" } } } diff --git a/phpstan.neon b/phpstan.neon index 0a114ff..1105443 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,6 @@ parameters: checkMissingIterableValueType: false - level: 8 + level: max paths: - src bootstrapFiles: