Skip to content

Commit 4353331

Browse files
authored
Merge pull request #305 from devnix/add-rector
Add Rector and apply basic rules
2 parents 1f56798 + 78d64ef commit 4353331

File tree

8 files changed

+68
-16
lines changed

8 files changed

+68
-16
lines changed

.github/workflows/test.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,35 @@ jobs:
4545

4646
- name: Tests
4747
run: composer test
48+
49+
rector:
50+
name: Rector
51+
runs-on: ubuntu-latest
52+
53+
strategy:
54+
matrix:
55+
php:
56+
- 8.4
57+
fail-fast: false
58+
59+
steps:
60+
- name: Checkout
61+
uses: actions/checkout@v4
62+
63+
- name: Install PHP
64+
uses: shivammathur/setup-php@v2
65+
with:
66+
php-version: ${{ matrix.php }}
67+
68+
- name: Cache PHP dependencies
69+
uses: actions/cache@v4
70+
with:
71+
path: vendor
72+
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
73+
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer-
74+
75+
- name: Install dependencies
76+
run: composer install --prefer-dist --no-progress --no-suggest
77+
78+
- name: Tests
79+
run: vendor/bin/rector process --dry-run

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"brick/varexporter": "^0.3.5",
2828
"friendsofphp/php-cs-fixer": "^3.2",
2929
"oscarotero/php-cs-fixer-config": "^2.0",
30-
"phpstan/phpstan": "^1|^2"
30+
"phpstan/phpstan": "^1|^2",
31+
"rector/rector": "^1|^2"
3132
},
3233
"autoload": {
3334
"psr-4": {
@@ -45,6 +46,7 @@
4546
"phpcs",
4647
"phpstan"
4748
],
48-
"cs-fix": "php-cs-fixer fix"
49+
"cs-fix": "php-cs-fixer fix",
50+
"rector": "rector process"
4951
}
5052
}

rector.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Set\ValueObject\SetList;
7+
8+
return RectorConfig::configure()
9+
->withPaths([
10+
__DIR__ . '/src',
11+
__DIR__ . '/tests',
12+
])
13+
->withPhpSets()
14+
->withTypeCoverageLevel(1)
15+
->withDeadCodeLevel(2)
16+
->withCodeQualityLevel(10)
17+
->withCodingStyleLevel(0)
18+
;

src/Loader/MoLoader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function loadString(string $string, ?Translations $translations = null):
6363
}
6464

6565
$headerChunks = preg_split('/:\s*/', $headerLine, 2);
66-
$translations->getHeaders()->set($headerChunks[0], isset($headerChunks[1]) ? $headerChunks[1] : '');
66+
$translations->getHeaders()->set($headerChunks[0], $headerChunks[1] ?? '');
6767
}
6868

6969
continue;
@@ -73,13 +73,13 @@ public function loadString(string $string, ?Translations $translations = null):
7373
$chunks = explode("\x04", $original, 2);
7474

7575
if (isset($chunks[1])) {
76-
list($context, $original) = $chunks;
76+
[$context, $original] = $chunks;
7777
}
7878

7979
$chunks = explode("\x00", $original, 2);
8080

8181
if (isset($chunks[1])) {
82-
list($original, $plural) = $chunks;
82+
[$original, $plural] = $chunks;
8383
}
8484

8585
$translation = $this->createTranslation($context, $original, $plural);

src/Loader/PoLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private static function parseHeaders(?string $string): array
174174
// Useful for distinguishing between header definitions and possible continuations of a header entry.
175175
if (preg_match('/^[\w-]+:/', $line)) {
176176
$pieces = array_map('trim', explode(':', $line, 2));
177-
list($name, $value) = $pieces;
177+
[$name, $value] = $pieces;
178178

179179
$headers[$name] = $value;
180180
continue;

src/Loader/StrictPoLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ private function readPluralTranslation(bool $throwIfNotFound = false): bool
398398
if (($translation = $this->translation->getTranslation()) !== null) {
399399
array_unshift($translations, $translation);
400400
}
401-
if (count($translations) !== (int) $index) {
401+
if (count($translations) !== $index) {
402402
throw new Exception("The msgstr has an invalid index{$this->getErrorPosition()}");
403403
}
404404
$data = $this->readQuotedString('msgstr');

src/Scanner/FunctionsHandlersTrait.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected function gettext(ParsedFunction $function): ?Translation
1717
if (!$this->checkFunction($function, 1)) {
1818
return null;
1919
}
20-
list($original) = $function->getArguments();
20+
[$original] = $function->getArguments();
2121

2222
$translation = $this->addComments(
2323
$function,
@@ -32,7 +32,7 @@ protected function ngettext(ParsedFunction $function): ?Translation
3232
if (!$this->checkFunction($function, 2)) {
3333
return null;
3434
}
35-
list($original, $plural) = $function->getArguments();
35+
[$original, $plural] = $function->getArguments();
3636

3737
$translation = $this->addComments(
3838
$function,
@@ -47,7 +47,7 @@ protected function pgettext(ParsedFunction $function): ?Translation
4747
if (!$this->checkFunction($function, 2)) {
4848
return null;
4949
}
50-
list($context, $original) = $function->getArguments();
50+
[$context, $original] = $function->getArguments();
5151

5252
$translation = $this->addComments(
5353
$function,
@@ -62,7 +62,7 @@ protected function dgettext(ParsedFunction $function): ?Translation
6262
if (!$this->checkFunction($function, 2)) {
6363
return null;
6464
}
65-
list($domain, $original) = $function->getArguments();
65+
[$domain, $original] = $function->getArguments();
6666

6767
$translation = $this->addComments(
6868
$function,
@@ -77,7 +77,7 @@ protected function dpgettext(ParsedFunction $function): ?Translation
7777
if (!$this->checkFunction($function, 3)) {
7878
return null;
7979
}
80-
list($domain, $context, $original) = $function->getArguments();
80+
[$domain, $context, $original] = $function->getArguments();
8181

8282
$translation = $this->addComments(
8383
$function,
@@ -92,7 +92,7 @@ protected function npgettext(ParsedFunction $function): ?Translation
9292
if (!$this->checkFunction($function, 3)) {
9393
return null;
9494
}
95-
list($context, $original, $plural) = $function->getArguments();
95+
[$context, $original, $plural] = $function->getArguments();
9696

9797
$translation = $this->addComments(
9898
$function,
@@ -107,7 +107,7 @@ protected function dngettext(ParsedFunction $function): ?Translation
107107
if (!$this->checkFunction($function, 3)) {
108108
return null;
109109
}
110-
list($domain, $original, $plural) = $function->getArguments();
110+
[$domain, $original, $plural] = $function->getArguments();
111111

112112
$translation = $this->addComments(
113113
$function,
@@ -122,7 +122,7 @@ protected function dnpgettext(ParsedFunction $function): ?Translation
122122
if (!$this->checkFunction($function, 4)) {
123123
return null;
124124
}
125-
list($domain, $context, $original, $plural) = $function->getArguments();
125+
[$domain, $context, $original, $plural] = $function->getArguments();
126126

127127
$translation = $this->addComments(
128128
$function,

src/Scanner/ParsedFunction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(string $name, string $filename, int $line, ?int $las
2121
$this->name = $name;
2222
$this->filename = $filename;
2323
$this->line = $line;
24-
$this->lastLine = isset($lastLine) ? $lastLine : $line;
24+
$this->lastLine = $lastLine ?? $line;
2525
}
2626

2727
public function __debugInfo(): array

0 commit comments

Comments
 (0)