diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 56841fd7..ecca61fc 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -45,3 +45,35 @@ jobs: - name: Tests run: composer test + + rector: + name: Rector + runs-on: ubuntu-latest + + strategy: + matrix: + php: + - 8.4 + fail-fast: false + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + + - name: Cache PHP dependencies + uses: actions/cache@v4 + with: + path: vendor + key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Tests + run: vendor/bin/rector process --dry-run diff --git a/composer.json b/composer.json index 81f1e205..92e59f66 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "brick/varexporter": "^0.3.5", "friendsofphp/php-cs-fixer": "^3.2", "oscarotero/php-cs-fixer-config": "^2.0", - "phpstan/phpstan": "^1|^2" + "phpstan/phpstan": "^1|^2", + "rector/rector": "^1|^2" }, "autoload": { "psr-4": { @@ -45,6 +46,7 @@ "phpcs", "phpstan" ], - "cs-fix": "php-cs-fixer fix" + "cs-fix": "php-cs-fixer fix", + "rector": "rector process" } } diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..1ac454ad --- /dev/null +++ b/rector.php @@ -0,0 +1,18 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withPhpSets() + ->withTypeCoverageLevel(1) + ->withDeadCodeLevel(2) + ->withCodeQualityLevel(10) + ->withCodingStyleLevel(0) +; diff --git a/src/Loader/MoLoader.php b/src/Loader/MoLoader.php index 1e2fb68b..5fc9419e 100644 --- a/src/Loader/MoLoader.php +++ b/src/Loader/MoLoader.php @@ -63,7 +63,7 @@ public function loadString(string $string, ?Translations $translations = null): } $headerChunks = preg_split('/:\s*/', $headerLine, 2); - $translations->getHeaders()->set($headerChunks[0], isset($headerChunks[1]) ? $headerChunks[1] : ''); + $translations->getHeaders()->set($headerChunks[0], $headerChunks[1] ?? ''); } continue; @@ -73,13 +73,13 @@ public function loadString(string $string, ?Translations $translations = null): $chunks = explode("\x04", $original, 2); if (isset($chunks[1])) { - list($context, $original) = $chunks; + [$context, $original] = $chunks; } $chunks = explode("\x00", $original, 2); if (isset($chunks[1])) { - list($original, $plural) = $chunks; + [$original, $plural] = $chunks; } $translation = $this->createTranslation($context, $original, $plural); diff --git a/src/Loader/PoLoader.php b/src/Loader/PoLoader.php index 6816b5b3..ca7c281e 100644 --- a/src/Loader/PoLoader.php +++ b/src/Loader/PoLoader.php @@ -174,7 +174,7 @@ private static function parseHeaders(?string $string): array // Useful for distinguishing between header definitions and possible continuations of a header entry. if (preg_match('/^[\w-]+:/', $line)) { $pieces = array_map('trim', explode(':', $line, 2)); - list($name, $value) = $pieces; + [$name, $value] = $pieces; $headers[$name] = $value; continue; diff --git a/src/Loader/StrictPoLoader.php b/src/Loader/StrictPoLoader.php index 6ed0d9e9..fe66c86d 100644 --- a/src/Loader/StrictPoLoader.php +++ b/src/Loader/StrictPoLoader.php @@ -398,7 +398,7 @@ private function readPluralTranslation(bool $throwIfNotFound = false): bool if (($translation = $this->translation->getTranslation()) !== null) { array_unshift($translations, $translation); } - if (count($translations) !== (int) $index) { + if (count($translations) !== $index) { throw new Exception("The msgstr has an invalid index{$this->getErrorPosition()}"); } $data = $this->readQuotedString('msgstr'); diff --git a/src/Scanner/FunctionsHandlersTrait.php b/src/Scanner/FunctionsHandlersTrait.php index 75e4c13a..0ace4c40 100644 --- a/src/Scanner/FunctionsHandlersTrait.php +++ b/src/Scanner/FunctionsHandlersTrait.php @@ -17,7 +17,7 @@ protected function gettext(ParsedFunction $function): ?Translation if (!$this->checkFunction($function, 1)) { return null; } - list($original) = $function->getArguments(); + [$original] = $function->getArguments(); $translation = $this->addComments( $function, @@ -32,7 +32,7 @@ protected function ngettext(ParsedFunction $function): ?Translation if (!$this->checkFunction($function, 2)) { return null; } - list($original, $plural) = $function->getArguments(); + [$original, $plural] = $function->getArguments(); $translation = $this->addComments( $function, @@ -47,7 +47,7 @@ protected function pgettext(ParsedFunction $function): ?Translation if (!$this->checkFunction($function, 2)) { return null; } - list($context, $original) = $function->getArguments(); + [$context, $original] = $function->getArguments(); $translation = $this->addComments( $function, @@ -62,7 +62,7 @@ protected function dgettext(ParsedFunction $function): ?Translation if (!$this->checkFunction($function, 2)) { return null; } - list($domain, $original) = $function->getArguments(); + [$domain, $original] = $function->getArguments(); $translation = $this->addComments( $function, @@ -77,7 +77,7 @@ protected function dpgettext(ParsedFunction $function): ?Translation if (!$this->checkFunction($function, 3)) { return null; } - list($domain, $context, $original) = $function->getArguments(); + [$domain, $context, $original] = $function->getArguments(); $translation = $this->addComments( $function, @@ -92,7 +92,7 @@ protected function npgettext(ParsedFunction $function): ?Translation if (!$this->checkFunction($function, 3)) { return null; } - list($context, $original, $plural) = $function->getArguments(); + [$context, $original, $plural] = $function->getArguments(); $translation = $this->addComments( $function, @@ -107,7 +107,7 @@ protected function dngettext(ParsedFunction $function): ?Translation if (!$this->checkFunction($function, 3)) { return null; } - list($domain, $original, $plural) = $function->getArguments(); + [$domain, $original, $plural] = $function->getArguments(); $translation = $this->addComments( $function, @@ -122,7 +122,7 @@ protected function dnpgettext(ParsedFunction $function): ?Translation if (!$this->checkFunction($function, 4)) { return null; } - list($domain, $context, $original, $plural) = $function->getArguments(); + [$domain, $context, $original, $plural] = $function->getArguments(); $translation = $this->addComments( $function, diff --git a/src/Scanner/ParsedFunction.php b/src/Scanner/ParsedFunction.php index 4f4477d0..2a98c37a 100644 --- a/src/Scanner/ParsedFunction.php +++ b/src/Scanner/ParsedFunction.php @@ -21,7 +21,7 @@ public function __construct(string $name, string $filename, int $line, ?int $las $this->name = $name; $this->filename = $filename; $this->line = $line; - $this->lastLine = isset($lastLine) ? $lastLine : $line; + $this->lastLine = $lastLine ?? $line; } public function __debugInfo(): array