Skip to content

Commit 5ba5fa5

Browse files
committed
Add Rector and apply basic rules
1 parent 95820f0 commit 5ba5fa5

9 files changed

Lines changed: 40 additions & 19 deletions

File tree

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"squizlabs/php_codesniffer": "^3.0",
2727
"brick/varexporter": "^0.3.5",
2828
"friendsofphp/php-cs-fixer": "^3.2",
29-
"oscarotero/php-cs-fixer-config": "^2.0"
29+
"oscarotero/php-cs-fixer-config": "^2.0",
30+
"rector/rector": "^2.0"
3031
},
3132
"autoload": {
3233
"psr-4": {
@@ -41,8 +42,10 @@
4142
"scripts": {
4243
"test": [
4344
"phpunit",
44-
"phpcs"
45+
"phpcs",
46+
"rector process --dry-run"
4547
],
46-
"cs-fix": "php-cs-fixer fix"
48+
"cs-fix": "php-cs-fixer fix",
49+
"rector": "rector process"
4750
}
4851
}

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
@@ -384,7 +384,7 @@ private function readPluralTranslation(bool $throwIfNotFound = false): bool
384384
if (($translation = $this->translation->getTranslation()) !== null) {
385385
array_unshift($translations, $translation);
386386
}
387-
if (count($translations) !== (int) $index) {
387+
if (count($translations) !== $index) {
388388
throw new Exception("The msgstr has an invalid index{$this->getErrorPosition()}");
389389
}
390390
$data = $this->readQuotedString('msgstr');

src/Scanner/FunctionsHandlersTrait.php

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

2020
$translation = $this->addComments(
2121
$function,
@@ -30,7 +30,7 @@ protected function ngettext(ParsedFunction $function): ?Translation
3030
if (!$this->checkFunction($function, 2)) {
3131
return null;
3232
}
33-
list($original, $plural) = $function->getArguments();
33+
[$original, $plural] = $function->getArguments();
3434

3535
$translation = $this->addComments(
3636
$function,
@@ -45,7 +45,7 @@ protected function pgettext(ParsedFunction $function): ?Translation
4545
if (!$this->checkFunction($function, 2)) {
4646
return null;
4747
}
48-
list($context, $original) = $function->getArguments();
48+
[$context, $original] = $function->getArguments();
4949

5050
$translation = $this->addComments(
5151
$function,
@@ -60,7 +60,7 @@ protected function dgettext(ParsedFunction $function): ?Translation
6060
if (!$this->checkFunction($function, 2)) {
6161
return null;
6262
}
63-
list($domain, $original) = $function->getArguments();
63+
[$domain, $original] = $function->getArguments();
6464

6565
$translation = $this->addComments(
6666
$function,
@@ -75,7 +75,7 @@ protected function dpgettext(ParsedFunction $function): ?Translation
7575
if (!$this->checkFunction($function, 3)) {
7676
return null;
7777
}
78-
list($domain, $context, $original) = $function->getArguments();
78+
[$domain, $context, $original] = $function->getArguments();
7979

8080
$translation = $this->addComments(
8181
$function,
@@ -90,7 +90,7 @@ protected function npgettext(ParsedFunction $function): ?Translation
9090
if (!$this->checkFunction($function, 3)) {
9191
return null;
9292
}
93-
list($context, $original, $plural) = $function->getArguments();
93+
[$context, $original, $plural] = $function->getArguments();
9494

9595
$translation = $this->addComments(
9696
$function,
@@ -105,7 +105,7 @@ protected function dngettext(ParsedFunction $function): ?Translation
105105
if (!$this->checkFunction($function, 3)) {
106106
return null;
107107
}
108-
list($domain, $original, $plural) = $function->getArguments();
108+
[$domain, $original, $plural] = $function->getArguments();
109109

110110
$translation = $this->addComments(
111111
$function,
@@ -120,7 +120,7 @@ protected function dnpgettext(ParsedFunction $function): ?Translation
120120
if (!$this->checkFunction($function, 4)) {
121121
return null;
122122
}
123-
list($domain, $context, $original, $plural) = $function->getArguments();
123+
[$domain, $context, $original, $plural] = $function->getArguments();
124124

125125
$translation = $this->addComments(
126126
$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()

tests/MoGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testMoGenerator()
2626
$translation->translate('Orixinal');
2727
$translations->add($translation);
2828

29-
$translation = Translation::create('context-1', 'Other comment', 'Other comments');
29+
$translation = Translation::create('context-1', 'Other comment');
3030
$translation->translate('Outro comentario');
3131
$translation->translatePlural('Outros comentarios');
3232
$translations->add($translation);

tests/PoGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testPoLoader()
3333
$translation->getReferences()->add('/my/template.php', 45);
3434
$translations->add($translation);
3535

36-
$translation = Translation::create('context-1', 'Other comment', 'Other comments');
36+
$translation = Translation::create('context-1', 'Other comment');
3737
$translation->translate('Outro comentario');
3838
$translation->translatePlural('Outros comentarios');
3939
$translation->getExtractedComments()->add('Not sure about this');

0 commit comments

Comments
 (0)