diff --git a/rector.php b/rector.php index 1ac454a..f9db34a 100644 --- a/rector.php +++ b/rector.php @@ -11,7 +11,7 @@ __DIR__ . '/tests', ]) ->withPhpSets() - ->withTypeCoverageLevel(1) + ->withPreparedSets(typeDeclarations: true) ->withDeadCodeLevel(2) ->withCodeQualityLevel(10) ->withCodingStyleLevel(0) diff --git a/src/Scanner/CodeScanner.php b/src/Scanner/CodeScanner.php index d01caf3..532096d 100644 --- a/src/Scanner/CodeScanner.php +++ b/src/Scanner/CodeScanner.php @@ -95,7 +95,7 @@ protected function getFunctionHandler(ParsedFunction $function): ?callable protected function addComments(ParsedFunction $function, ?Translation $translation): ?Translation { - if (empty($this->commentsPrefixes) || empty($translation)) { + if (empty($this->commentsPrefixes) || $translation === null) { return $translation; } @@ -110,7 +110,7 @@ protected function addComments(ParsedFunction $function, ?Translation $translati protected function addFlags(ParsedFunction $function, ?Translation $translation): ?Translation { - if (empty($translation)) { + if ($translation === null) { return $translation; } diff --git a/tests/BasePoLoaderTestCase.php b/tests/BasePoLoaderTestCase.php index 4029d72..da672a6 100644 --- a/tests/BasePoLoaderTestCase.php +++ b/tests/BasePoLoaderTestCase.php @@ -11,7 +11,7 @@ abstract class BasePoLoaderTestCase extends TestCase { abstract protected function createPoLoader(): Loader; - public function testPoLoader() + public function testPoLoader(): void { $loader = $this->createPoLoader(); $translations = $loader->loadFile(__DIR__.'/assets/translations.po'); @@ -73,7 +73,7 @@ public function testPoLoader() $this->assertSame('bs', $translations->getLanguage()); } - private function translation1(Translation $translation) + private function translation1(Translation $translation): void { $this->assertSame( 'Ensure this value has at least %(limit_value)d character (it has %sd).', @@ -87,7 +87,7 @@ private function translation1(Translation $translation) $this->assertSame(['', ''], $translation->getPluralTranslations()); } - private function translation2(Translation $translation) + private function translation2(Translation $translation): void { $this->assertSame( 'Ensure this value has at most %(limit_value)d character (it has %sd).', @@ -101,7 +101,7 @@ private function translation2(Translation $translation) $this->assertSame(['', ''], $translation->getPluralTranslations()); } - private function translation3(Translation $translation) + private function translation3(Translation $translation): void { $this->assertSame('%ss must be unique for %ss %ss.', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -109,7 +109,7 @@ private function translation3(Translation $translation) $this->assertCount(0, $translation->getPluralTranslations()); } - private function translation4(Translation $translation) + private function translation4(Translation $translation): void { $this->assertSame('and', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -118,7 +118,7 @@ private function translation4(Translation $translation) $this->assertSame(['c-format'], $translation->getFlags()->toArray()); } - private function translation5(Translation $translation) + private function translation5(Translation $translation): void { $this->assertSame('Value %sr is not a valid choice.', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -127,7 +127,7 @@ private function translation5(Translation $translation) $this->assertSame(['This is a extracted comment'], $translation->getExtractedComments()->toArray()); } - private function translation6(Translation $translation) + private function translation6(Translation $translation): void { $this->assertSame('This field cannot be null.', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -137,7 +137,7 @@ private function translation6(Translation $translation) $this->assertSame(['C:/Users/Me/Documents/foo2.php' => [1]], $translation->getReferences()->toArray()); } - private function translation7(Translation $translation) + private function translation7(Translation $translation): void { $this->assertSame('This field cannot be blank.', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -147,7 +147,7 @@ private function translation7(Translation $translation) $this->assertSame(['C:/Users/Me/Documents/foo1.php' => []], $translation->getReferences()->toArray()); } - private function translation8(Translation $translation) + private function translation8(Translation $translation): void { $this->assertSame('Field of type: %ss', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -163,7 +163,7 @@ private function translation8(Translation $translation) ); } - private function translation9(Translation $translation) + private function translation9(Translation $translation): void { $this->assertSame('Integer', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -174,7 +174,7 @@ private function translation9(Translation $translation) $this->assertSame(['a simple line comment is above'], $translation->getComments()->toArray()); } - private function translation10(Translation $translation) + private function translation10(Translation $translation): void { $this->assertSame('{test1}', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -191,7 +191,7 @@ private function translation10(Translation $translation) ); } - private function translation11(Translation $translation) + private function translation11(Translation $translation): void { $this->assertSame('{test2}', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -205,7 +205,7 @@ private function translation11(Translation $translation) ); } - private function translation12(Translation $translation) + private function translation12(Translation $translation): void { $this->assertSame('Multibyte test', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -215,7 +215,7 @@ private function translation12(Translation $translation) $this->assertCount(0, $translation->getReferences()); } - private function translation13(Translation $translation) + private function translation13(Translation $translation): void { $this->assertSame('Tabulation test', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -225,7 +225,7 @@ private function translation13(Translation $translation) $this->assertCount(0, $translation->getReferences()); } - private function translation14(Translation $translation) + private function translation14(Translation $translation): void { $this->assertSame('%s has been added to your cart.', $translation->getOriginal()); $this->assertSame('%s have been added to your cart.', $translation->getPlural()); @@ -257,10 +257,8 @@ public function stringDecodeProvider() /** * @dataProvider stringDecodeProvider - * @param mixed $source - * @param mixed $decoded */ - public function testStringDecode($source, $decoded) + public function testStringDecode(string $source, string $decoded): void { $po = <<assertSame($decoded, $translations->find(null, 'source')->getTranslation()); } - public function testMultilineDisabledTranslations() + public function testMultilineDisabledTranslations(): void { $po = <<<'EOT' #~ msgid "Last agent hours-description" diff --git a/tests/CommentsTest.php b/tests/CommentsTest.php index 64420f5..c272a00 100644 --- a/tests/CommentsTest.php +++ b/tests/CommentsTest.php @@ -8,7 +8,7 @@ class CommentsTest extends TestCase { - public function testComments() + public function testComments(): void { $comments = new Comments(); @@ -36,7 +36,7 @@ public function testComments() $this->assertCount(1, $comments); } - public function testMergeComments() + public function testMergeComments(): void { $comments1 = new Comments('one', 'two', 'three'); $comments2 = new Comments('three', 'four', 'five'); @@ -50,7 +50,7 @@ public function testMergeComments() $this->assertNotSame($merged, $comments2); } - public function testCreateFromState() + public function testCreateFromState(): void { $state = ['comments' => ['First comment', 'Second comment']]; $comments = Comments::__set_state($state); diff --git a/tests/FlagsTest.php b/tests/FlagsTest.php index d0f7692..e6eeb96 100644 --- a/tests/FlagsTest.php +++ b/tests/FlagsTest.php @@ -8,7 +8,7 @@ class FlagsTest extends TestCase { - public function testFlags() + public function testFlags(): void { $flags = new Flags(); @@ -41,7 +41,7 @@ public function testFlags() $this->assertCount(2, $flags); } - public function testMergeFlags() + public function testMergeFlags(): void { $flags1 = new Flags('one', 'two', 'three'); $flags2 = new Flags('three', 'four', 'five'); @@ -61,7 +61,7 @@ public function testMergeFlags() $this->assertNotSame($merged, $flags2); } - public function testCreateFromState() + public function testCreateFromState(): void { $state = ['flags' => ['one', 'two']]; $flags = Flags::__set_state($state); diff --git a/tests/HeadersTest.php b/tests/HeadersTest.php index df838c3..39d9d21 100644 --- a/tests/HeadersTest.php +++ b/tests/HeadersTest.php @@ -9,7 +9,7 @@ class HeadersTest extends TestCase { - public function testHeaders() + public function testHeaders(): void { $headers = new Headers(); @@ -41,7 +41,7 @@ public function testHeaders() $this->assertCount(0, $headers); } - public function testDomain() + public function testDomain(): void { $headers = new Headers(); $headers->setDomain('foo'); @@ -52,7 +52,7 @@ public function testDomain() $this->assertSame('foo', $headers->getDomain()); } - public function testLanguage() + public function testLanguage(): void { $headers = new Headers(); $headers->setLanguage('gl_ES'); @@ -63,7 +63,7 @@ public function testLanguage() $this->assertSame('gl_ES', $headers->getLanguage()); } - public function testInvalidLanguage() + public function testInvalidLanguage(): void { $this->expectException(InvalidArgumentException::class); @@ -71,7 +71,7 @@ public function testInvalidLanguage() $headers->setPluralForm(1, 'foo'); } - public function testPluralForm() + public function testPluralForm(): void { $headers = new Headers(); $headers->setPluralForm(2, '(n=1)'); @@ -82,7 +82,7 @@ public function testPluralForm() $this->assertSame([2, '(n=1)'], $headers->getPluralForm()); } - public function testMergeHeaders() + public function testMergeHeaders(): void { $headers1 = new Headers(['X-Domain' => 'foo', 'Language' => 'gl_ES']); $headers2 = new Headers(['Translator' => 'Oscar Otero', 'Language' => 'ru']); @@ -97,7 +97,7 @@ public function testMergeHeaders() $this->assertNotSame($merged, $headers2); } - public function testCreateFromState() + public function testCreateFromState(): void { $state = ['headers' => ['X-Domain' => 'foo']]; $headers = Headers::__set_state($state); diff --git a/tests/MergeTest.php b/tests/MergeTest.php index bd064f9..4248e7b 100644 --- a/tests/MergeTest.php +++ b/tests/MergeTest.php @@ -93,7 +93,7 @@ private static function createPO(): Translations return $translations; } - public function testNoStrategy() + public function testNoStrategy(): void { $pot = self::createPOT(); $po = self::createPO(); @@ -106,7 +106,7 @@ public function testNoStrategy() /** * We want to use the scanner to fetch new entries and complete them with PO files. */ - public function testScanAndLoadStrategy() + public function testScanAndLoadStrategy(): void { $pot = self::createPOT(); $po = self::createPO(); @@ -126,7 +126,7 @@ public function testScanAndLoadStrategy() $this->assertSnapshot(__FUNCTION__, $merged); } - private function assertSnapshot(string $name, Translations $translations, bool $forceCreate = false) + private function assertSnapshot(string $name, Translations $translations, bool $forceCreate = false): void { $file = __DIR__."/snapshots/{$name}.php"; $array = $translations->toArray(); diff --git a/tests/MoGeneratorTest.php b/tests/MoGeneratorTest.php index 4a0bd27..3687180 100644 --- a/tests/MoGeneratorTest.php +++ b/tests/MoGeneratorTest.php @@ -11,7 +11,7 @@ class MoGeneratorTest extends TestCase { - public function testMoGenerator() + public function testMoGenerator(): void { $generator = (new MoGenerator())->includeHeaders(); $loader = new MoLoader(); diff --git a/tests/MoLoaderTest.php b/tests/MoLoaderTest.php index 30a21a3..900d431 100644 --- a/tests/MoLoaderTest.php +++ b/tests/MoLoaderTest.php @@ -9,7 +9,7 @@ class MoLoaderTest extends TestCase { - public function testMoLoader() + public function testMoLoader(): void { $loader = new MoLoader(); $translations = $loader->loadFile(__DIR__.'/assets/translations.mo'); @@ -54,7 +54,7 @@ public function testMoLoader() $this->assertSame('bs', $translations->getLanguage()); } - private function translation0(Translation $translation) + private function translation0(Translation $translation): void { $this->assertSame('%s has been added to your cart.', $translation->getOriginal()); $this->assertSame('%s have been added to your cart.', $translation->getPlural()); @@ -62,7 +62,7 @@ private function translation0(Translation $translation) $this->assertCount(1, $translation->getPluralTranslations()); } - private function translation1(Translation $translation) + private function translation1(Translation $translation): void { $this->assertSame('%ss must be unique for %ss %ss.', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -70,7 +70,7 @@ private function translation1(Translation $translation) $this->assertCount(0, $translation->getPluralTranslations()); } - private function translation2(Translation $translation) + private function translation2(Translation $translation): void { $this->assertSame('Field of type: %ss', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -78,7 +78,7 @@ private function translation2(Translation $translation) $this->assertCount(0, $translation->getPluralTranslations()); } - private function translation3(Translation $translation) + private function translation3(Translation $translation): void { $this->assertSame('Integer', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -86,7 +86,7 @@ private function translation3(Translation $translation) $this->assertCount(0, $translation->getPluralTranslations()); } - private function translation4(Translation $translation) + private function translation4(Translation $translation): void { $this->assertSame('Multibyte test', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -94,7 +94,7 @@ private function translation4(Translation $translation) $this->assertCount(0, $translation->getPluralTranslations()); } - private function translation5(Translation $translation) + private function translation5(Translation $translation): void { $this->assertSame('Tabulation test', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -102,7 +102,7 @@ private function translation5(Translation $translation) $this->assertCount(0, $translation->getPluralTranslations()); } - private function translation6(Translation $translation) + private function translation6(Translation $translation): void { $this->assertSame('This field cannot be blank.', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -110,7 +110,7 @@ private function translation6(Translation $translation) $this->assertCount(0, $translation->getPluralTranslations()); } - private function translation7(Translation $translation) + private function translation7(Translation $translation): void { $this->assertSame('This field cannot be null.', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -118,7 +118,7 @@ private function translation7(Translation $translation) $this->assertCount(0, $translation->getPluralTranslations()); } - private function translation8(Translation $translation) + private function translation8(Translation $translation): void { $this->assertSame('and', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -126,7 +126,7 @@ private function translation8(Translation $translation) $this->assertCount(0, $translation->getPluralTranslations()); } - private function translation9(Translation $translation) + private function translation9(Translation $translation): void { $this->assertSame('{test1}', $translation->getOriginal()); $this->assertNull($translation->getPlural()); @@ -134,7 +134,7 @@ private function translation9(Translation $translation) $this->assertCount(0, $translation->getPluralTranslations()); } - private function translation10(Translation $translation) + private function translation10(Translation $translation): void { $this->assertSame('{test2}', $translation->getOriginal()); $this->assertNull($translation->getPlural()); diff --git a/tests/ParsedFunctionsAndCommentsTest.php b/tests/ParsedFunctionsAndCommentsTest.php index 9bad631..452b70e 100644 --- a/tests/ParsedFunctionsAndCommentsTest.php +++ b/tests/ParsedFunctionsAndCommentsTest.php @@ -8,7 +8,7 @@ class ParsedFunctionsAndCommentsTest extends TestCase { - public function testParsedFunction() + public function testParsedFunction(): void { $function = new ParsedFunction('__', 'template.php', 45); diff --git a/tests/PoGeneratorTest.php b/tests/PoGeneratorTest.php index 11da0a9..b6ee22e 100644 --- a/tests/PoGeneratorTest.php +++ b/tests/PoGeneratorTest.php @@ -10,7 +10,7 @@ class PoGeneratorTest extends TestCase { - public function testPoLoader() + public function testPoLoader(): void { $generator = new PoGenerator(); $translations = Translations::create('my-domain'); @@ -96,7 +96,7 @@ public function testPoLoader() $this->assertSame($expected, $result); } - public function stringEncodeProvider() + public function stringEncodeProvider(): array { return [ ['"test"', 'test'], @@ -109,10 +109,8 @@ public function stringEncodeProvider() /** * @dataProvider stringEncodeProvider - * @param mixed $encoded - * @param mixed $decoded */ - public function testStringEncode($encoded, $decoded) + public function testStringEncode(string $encoded, string $decoded): void { $this->assertSame($encoded, PoGenerator::encode($decoded)); } diff --git a/tests/PoLoaderTest.php b/tests/PoLoaderTest.php index 3708690..399f893 100644 --- a/tests/PoLoaderTest.php +++ b/tests/PoLoaderTest.php @@ -18,7 +18,7 @@ protected function createPoLoader(): Loader * @param mixed $source * @param mixed $decoded */ - public function testStringDecode($source, $decoded) + public function testStringDecode($source, $decoded): void { $this->assertSame($decoded, PoLoader::decode($source)); } diff --git a/tests/ReferencesTest.php b/tests/ReferencesTest.php index 885e209..c704a71 100644 --- a/tests/ReferencesTest.php +++ b/tests/ReferencesTest.php @@ -8,7 +8,7 @@ class ReferencesTest extends TestCase { - public function testReferences() + public function testReferences(): void { $references = new References(); @@ -36,7 +36,7 @@ public function testReferences() } } - public function testMergeReferences() + public function testMergeReferences(): void { $references1 = new References(); $references2 = new References(); @@ -72,7 +72,7 @@ public function testMergeReferences() $this->assertNotSame($merged, $references2); } - public function testCreateFromState() + public function testCreateFromState(): void { $state = [ 'references' => [ diff --git a/tests/TranslationTest.php b/tests/TranslationTest.php index 9ad6eac..4a7cfaa 100644 --- a/tests/TranslationTest.php +++ b/tests/TranslationTest.php @@ -11,7 +11,7 @@ class TranslationTest extends TestCase { - public function testTranslation() + public function testTranslation(): void { $translation = Translation::create('foo', 'bar'); @@ -56,7 +56,7 @@ public function testTranslation() $this->assertNotSame($translation->getReferences(), $clone->getReferences()); } - public function testMergeTranslation() + public function testMergeTranslation(): void { $translation1 = Translation::create('context', 'Original'); $translation1->translate('Orixinal');