Skip to content

Add Rector and apply basic rules #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -43,8 +44,10 @@
"test": [
"phpunit",
"phpcs",
"phpstan"
"phpstan",
"rector process --dry-run"
],
"cs-fix": "php-cs-fixer fix"
"cs-fix": "php-cs-fixer fix",
"rector": "rector process"
}
}
18 changes: 18 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\SetList;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPhpSets()
->withTypeCoverageLevel(1)
->withDeadCodeLevel(2)
->withCodeQualityLevel(10)
->withCodingStyleLevel(0)
;
6 changes: 3 additions & 3 deletions src/Loader/MoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Loader/PoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Loader/StrictPoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
16 changes: 8 additions & 8 deletions src/Scanner/FunctionsHandlersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Scanner/ParsedFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading