Skip to content

Commit

Permalink
Merge pull request #25 from donatj/chore/phpstan
Browse files Browse the repository at this point in the history
Run against PHPStan as CI
  • Loading branch information
donatj authored Oct 29, 2023
2 parents c1ace41 + 42e1459 commit dfc9fd0
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/vendor/
/clover.xml
/composer.lock
*.cache
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: test
test: cs
test: cs phpstan
./vendor/bin/phpunit

.PHONY: cs
Expand All @@ -10,3 +10,6 @@ cs:
cbf:
./vendor/bin/phpcbf

.PHONY: phpstan
phpstan:
./vendor/bin/phpstan
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@
}
],
"require": {
"php": ">=7.1"
"php": ">=7.4"
},
"autoload": {
"psr-4": {
"donatj\\RewriteGenerator\\": "src/"
}
},
"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
}
}
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 9
paths:
- src
- tests
7 changes: 6 additions & 1 deletion src/ApacheModRewriteGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
10 changes: 5 additions & 5 deletions src/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tests/tests/ApacheIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit dfc9fd0

Please sign in to comment.