From db8895c5c972158394625767db97350357f7a501 Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Sun, 29 Oct 2023 16:12:14 -0500 Subject: [PATCH 1/3] Run against phpstan level 9 --- .gitignore | 1 + Makefile | 5 ++++- composer.json | 12 +++++++----- phpstan.neon | 5 +++++ 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 phpstan.neon diff --git a/.gitignore b/.gitignore index a3ee05b..f86dccc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /vendor/ /clover.xml /composer.lock +*.cache diff --git a/Makefile b/Makefile index a2c93fb..e194795 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .PHONY: test -test: cs +test: cs phpstan ./vendor/bin/phpunit .PHONY: cs @@ -10,3 +10,6 @@ cs: cbf: ./vendor/bin/phpcbf +.PHONY: phpstan +phpstan: + ./vendor/bin/phpstan diff --git a/composer.json b/composer.json index a380d38..95cfa1a 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": ">=7.1" + "php": ">=7.4" }, "autoload": { "psr-4": { @@ -22,14 +22,16 @@ } }, "require-dev": { - "phpunit/phpunit": "~7.5|~9.3", + "corpus/coding-standard": "^0.6.0", "donatj/drop": "^1.0", - "squizlabs/php_codesniffer": "^3.5", - "corpus/coding-standard": "^0.6.0" + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "~7.5|~9.3", + "squizlabs/php_codesniffer": "^3.5" }, "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true - } + }, + "sort-packages": true } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..ec605ef --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 9 + paths: + - src + - tests From cd4db4775f36d7220fac70119e7248c1e00fd16f Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Sun, 29 Oct 2023 16:12:20 -0500 Subject: [PATCH 2/3] Couple phpstan fixes --- src/ApacheModRewriteGenerator.php | 7 ++++++- src/Engine.php | 10 +++++----- tests/tests/ApacheIntegrationTest.php | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ApacheModRewriteGenerator.php b/src/ApacheModRewriteGenerator.php index 1eeb2de..ede59c9 100644 --- a/src/ApacheModRewriteGenerator.php +++ b/src/ApacheModRewriteGenerator.php @@ -77,7 +77,12 @@ public function generateRewrite( string $from, string $to, int $type ) : string } private function escapeSubstitution( string $input ) : string { - return preg_replace('/[-\s%$\\\\]/', '\\\\$0', $input); + $result = preg_replace('/[-\s%$\\\\]/', '\\\\$0', $input); + if( $result === null ) { + throw new \RuntimeException('preg_replace failed - ' . preg_last_error()); + } + + return $result; } } diff --git a/src/Engine.php b/src/Engine.php index 862de2e..1124217 100644 --- a/src/Engine.php +++ b/src/Engine.php @@ -6,12 +6,9 @@ class Engine { - /** - * @var \donatj\RewriteGenerator\GeneratorInterface - */ - private $generator; + private GeneratorInterface $generator; - private $lastErrorCount = 0; + private int $lastErrorCount = 0; public function __construct( GeneratorInterface $generator ) { $this->generator = $generator; @@ -22,6 +19,9 @@ public function generate( string $input, int $type, bool $comments ) : string { $output = ''; $input = preg_replace('/\h+/', "\t", $input); // Spacing Cleanup + if( $input === null ) { + throw new \RuntimeException('preg_replace failed - ' . preg_last_error()); + } $lines = explode(PHP_EOL, $input); diff --git a/tests/tests/ApacheIntegrationTest.php b/tests/tests/ApacheIntegrationTest.php index b4d0a5b..e4e3eec 100644 --- a/tests/tests/ApacheIntegrationTest.php +++ b/tests/tests/ApacheIntegrationTest.php @@ -13,7 +13,7 @@ class ApacheIntegrationTest extends TestCase { /** * @dataProvider exampleProvider */ - public function test_examples( string $input, string $output301, string $outputRewrite ) { + public function test_examples( string $input, string $output301, string $outputRewrite ) : void { $engine = new Engine(new ApacheModRewriteGenerator); $given = $engine->generate($input, RewriteTypes::PERMANENT_REDIRECT, true); @@ -136,7 +136,7 @@ public function exampleProvider() : Generator { /** * @dataProvider failureProvider */ - public function test_failures( string $input, string $output, int $errorCount ) { + public function test_failures( string $input, string $output, int $errorCount ) : void { $engine = new Engine(new ApacheModRewriteGenerator); $given = $engine->generate($input, RewriteTypes::PERMANENT_REDIRECT, true); From 42e1459eebff4b37b8020e9b5af6a8018c98303a Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Sun, 29 Oct 2023 16:13:10 -0500 Subject: [PATCH 3/3] Update PHP versions --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3856785..fdcafee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php-versions: ['7.4', '8.0', '8.1', '8.2'] runs-on: ${{ matrix.operating-system }}