diff --git a/composer.json b/composer.json index 882be1d0..f2b4b3db 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "symfony/asset": "^4.4|^5.0", "symfony/config": "^4.4|^5.0", "symfony/console": "^4.4|^5.0", - "symfony/translation-contracts": "^1.0", + "symfony/translation-contracts": "^1.1|^2.0", "symfony/dependency-injection": "^4.4|^5.0", "symfony/filesystem": "^4.4|^5.0", "symfony/finder": "^4.4|^5.0", @@ -40,14 +40,14 @@ "zendframework/zend-hydrator": "^2.2" }, "require-dev": { - "matthiasnoback/symfony-config-test": "^4.0", - "matthiasnoback/symfony-dependency-injection-test": "^3.0", + "matthiasnoback/symfony-config-test": "^4.1", + "matthiasnoback/symfony-dependency-injection-test": "^4.1", "mikey179/vfsstream": "^1.6", - "phpspec/phpspec": "^5.0", - "phpstan/phpstan": "^0.11", - "phpstan/phpstan-phpunit": "^0.11", - "phpstan/phpstan-webmozart-assert": "^0.11", - "phpunit/phpunit": "^7.0", + "phpspec/phpspec": "^6.1", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpstan/phpstan-webmozart-assert": "^0.12", + "phpunit/phpunit": "^8.5", "sylius-labs/coding-standard": "^3.0", "symfony/browser-kit": "^4.4|^5.0", "symfony/security-csrf": "^4.4|^5.0", @@ -55,9 +55,6 @@ "twig/twig": "^2.0", "vimeo/psalm": "^3.5" }, - "conflict": { - "twig/twig": "^1.0" - }, "autoload": { "psr-4": { "Sylius\\Bundle\\ThemeBundle\\": "src/" diff --git a/phpstan.neon b/phpstan.neon index eba38f28..2915116b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,24 +5,19 @@ includes: - vendor/phpstan/phpstan-phpunit/rules.neon parameters: + checkMissingIterableValueType: false reportUnmatchedIgnoredErrors: false - - specDir: 'spec/' + treatPhpDocTypesAsCertain: false excludes_analyse: - - %currentWorkingDirectory%/tests/Application/var/* + # Test dependencies + - %currentWorkingDirectory%/spec/ + - %currentWorkingDirectory%/tests/Application/var/ ignoreErrors: # PHPStan integration - '/Call to an undefined method Prophecy\\Prophecy\\MethodProphecy::getRealPath\(\)/' - # Symfony 3.4 support - - '/Method Symfony\\Component\\HttpKernel\\KernelInterface::getBundle\(\) invoked with 2 parameters, 1 required/' - - '/Method Symfony\\Component\\HttpKernel\\KernelInterface::getBundle\(\) invoked with 2 parameters, 0-1 required/' - - '/Call to function method_exists\(\) with .Symfony\\\\Component…. and .getRootNode. will always evaluate to false/' - - '/Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::getRootNode\(\)/' - - '/Class Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder does not have a constructor and must be instantiated without any parameters/' - # Symfony caveats - '/Parameter \#1 \$name of method Symfony\\Component\\Config\\FileLocatorInterface::locate\(\) expects string, Symfony\\Component\\Templating\\TemplateReferenceInterface given/' - '/Parameter \#1 \$translator of class Symfony\\Component\\Translation\\Formatter\\MessageFormatter constructor expects Symfony\\Contracts\\Translation\\TranslatorInterface|null, Symfony\\Component\\Translation\\MessageSelector given/' @@ -30,3 +25,8 @@ parameters: # Symfony passes TemplateReference object instead of a string - "/Casting to string something that\\'s already string./" - '/Parameter \#1 \$name of method Twig\\Loader\\LoaderInterface::[A-Za-z]+\(\) expects string, string\|Symfony\\Component\\Templating\\TemplateReference given\./' + + - '/Method Sylius\\Bundle\\ThemeBundle\\Filesystem\\FilesystemInterface::[A-Za-z]+\(\) has no return typehint specified./' + - '/Method Sylius\\Bundle\\ThemeBundle\\Translation\\ThemeAwareTranslator::__call\(\) has no return typehint specified./' + - '/Method Sylius\\Bundle\\ThemeBundle\\Translation\\ThemeAwareTranslator::trans\(\) has parameter \$[A-Za-z]+ with no typehint specified./' + - '/Method Sylius\\Bundle\\ThemeBundle\\Templating\\Locator\\TemplateFileLocator::unserialize\(\) has parameter \$serialized with no typehint specified./' diff --git a/psalm.xml b/psalm.xml index 263fea38..bad50e70 100644 --- a/psalm.xml +++ b/psalm.xml @@ -45,6 +45,7 @@ + diff --git a/src/Asset/Installer/AssetsInstaller.php b/src/Asset/Installer/AssetsInstaller.php index 4a4f8341..dcd0ed02 100644 --- a/src/Asset/Installer/AssetsInstaller.php +++ b/src/Asset/Installer/AssetsInstaller.php @@ -20,7 +20,6 @@ use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; -use Symfony\Component\Finder\SplFileInfo; use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\KernelInterface; @@ -110,7 +109,6 @@ private function installThemedBundleAssets(ThemeInterface $theme, string $origin $finder = new Finder(); $finder->sortByName()->ignoreDotFiles(false)->in($originDir); - /** @var SplFileInfo[] $finder */ foreach ($finder as $originFile) { $targetFile = $targetDir . '/' . $originFile->getRelativePathname(); $targetFile = $this->pathResolver->resolve($targetFile, $theme); diff --git a/src/Asset/Package/PathPackage.php b/src/Asset/Package/PathPackage.php index 71149289..d2192fd7 100644 --- a/src/Asset/Package/PathPackage.php +++ b/src/Asset/Package/PathPackage.php @@ -43,10 +43,7 @@ public function __construct( $this->pathResolver = $pathResolver; } - /** - * {@inheritdoc} - */ - public function getUrl($path): string + public function getUrl(string $path): string { if ($this->isAbsoluteUrl($path)) { return $path; diff --git a/src/Asset/Package/UrlPackage.php b/src/Asset/Package/UrlPackage.php index 4c1cdff0..0981b4f6 100644 --- a/src/Asset/Package/UrlPackage.php +++ b/src/Asset/Package/UrlPackage.php @@ -67,10 +67,7 @@ public function __construct( $this->pathResolver = $pathResolver; } - /** - * {@inheritdoc} - */ - public function getUrl($path): string + public function getUrl(string $path): string { if ($this->isAbsoluteUrl($path)) { return $path; diff --git a/src/Configuration/ThemeConfiguration.php b/src/Configuration/ThemeConfiguration.php index 70114bb3..d6d14bb3 100644 --- a/src/Configuration/ThemeConfiguration.php +++ b/src/Configuration/ThemeConfiguration.php @@ -24,28 +24,19 @@ final class ThemeConfiguration implements ConfigurationInterface */ public function getConfigTreeBuilder(): TreeBuilder { - if (method_exists(TreeBuilder::class, 'getRootNode')) { - $treeBuilder = new TreeBuilder('sylius_theme'); - - /** @var ArrayNodeDefinition $rootNodeDefinition */ - $rootNodeDefinition = $treeBuilder->getRootNode(); - } else { - // BC layer for symfony/config 4.1 and older - $treeBuilder = new TreeBuilder(); - - /** @var ArrayNodeDefinition $rootNodeDefinition */ - $rootNodeDefinition = $treeBuilder->root('sylius_theme'); - } - - $rootNodeDefinition->ignoreExtraKeys(); - - $this->addRequiredNameField($rootNodeDefinition); - $this->addOptionalTitleField($rootNodeDefinition); - $this->addOptionalDescriptionField($rootNodeDefinition); - $this->addOptionalPathField($rootNodeDefinition); - $this->addOptionalParentsList($rootNodeDefinition); - $this->addOptionalScreenshotsList($rootNodeDefinition); - $this->addOptionalAuthorsList($rootNodeDefinition); + $treeBuilder = new TreeBuilder('sylius_theme'); + /** @var ArrayNodeDefinition $rootNode */ + $rootNode = $treeBuilder->getRootNode(); + + $rootNode->ignoreExtraKeys(); + + $this->addRequiredNameField($rootNode); + $this->addOptionalTitleField($rootNode); + $this->addOptionalDescriptionField($rootNode); + $this->addOptionalPathField($rootNode); + $this->addOptionalParentsList($rootNode); + $this->addOptionalScreenshotsList($rootNode); + $this->addOptionalAuthorsList($rootNode); return $treeBuilder; } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 2616aaf9..6aa56bb1 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -36,25 +36,16 @@ public function __construct(array $configurationSourceFactories = []) */ public function getConfigTreeBuilder(): TreeBuilder { - if (method_exists(TreeBuilder::class, 'getRootNode')) { - $treeBuilder = new TreeBuilder('sylius_theme'); + $treeBuilder = new TreeBuilder('sylius_theme'); + /** @var ArrayNodeDefinition $rootNode */ + $rootNode = $treeBuilder->getRootNode(); - /** @var ArrayNodeDefinition $rootNodeDefinition */ - $rootNodeDefinition = $treeBuilder->getRootNode(); - } else { - // BC layer for symfony/config 4.1 and older - $treeBuilder = new TreeBuilder(); + $this->addSourcesConfiguration($rootNode); - /** @var ArrayNodeDefinition $rootNodeDefinition */ - $rootNodeDefinition = $treeBuilder->root('sylius_theme'); - } - - $this->addSourcesConfiguration($rootNodeDefinition); - - $rootNodeDefinition->children()->arrayNode('assets')->canBeDisabled(); - $rootNodeDefinition->children()->arrayNode('templating')->canBeDisabled(); - $rootNodeDefinition->children()->arrayNode('translations')->canBeDisabled(); - $rootNodeDefinition->children()->scalarNode('context')->defaultValue('sylius.theme.context.settable')->cannotBeEmpty(); + $rootNode->children()->arrayNode('assets')->canBeDisabled(); + $rootNode->children()->arrayNode('templating')->canBeDisabled(); + $rootNode->children()->arrayNode('translations')->canBeDisabled(); + $rootNode->children()->scalarNode('context')->defaultValue('sylius.theme.context.settable')->cannotBeEmpty(); return $treeBuilder; } diff --git a/src/Filesystem/FilesystemInterface.php b/src/Filesystem/FilesystemInterface.php index a73df8ff..2a7d953f 100644 --- a/src/Filesystem/FilesystemInterface.php +++ b/src/Filesystem/FilesystemInterface.php @@ -32,7 +32,7 @@ interface FilesystemInterface * @throws FileNotFoundException When originFile doesn't exist * @throws IOException When copy fails */ - public function copy($originFile, $targetFile, $override = false); + public function copy(string $originFile, string $targetFile, bool $override = false); /** * Creates a directory recursively. @@ -42,7 +42,7 @@ public function copy($originFile, $targetFile, $override = false); * * @throws IOException On any directory creation failure */ - public function mkdir($dirs, $mode = 0777); + public function mkdir($dirs, int $mode = 0777); /** * Checks the existence of files or directories. @@ -62,7 +62,7 @@ public function exists($files); * * @throws IOException When touch fails */ - public function touch($files, $time = null, $atime = null); + public function touch($files, int $time = null, int $atime = null); /** * Removes files or directories. @@ -83,7 +83,7 @@ public function remove($files); * * @throws IOException When the change fail */ - public function chmod($files, $mode, $umask = 0000, $recursive = false); + public function chmod($files, int $mode, int $umask = 0000, bool $recursive = false); /** * Change the owner of an array of files or directories. @@ -94,7 +94,7 @@ public function chmod($files, $mode, $umask = 0000, $recursive = false); * * @throws IOException When the change fail */ - public function chown($files, $user, $recursive = false); + public function chown($files, string $user, bool $recursive = false); /** * Change the group of an array of files or directories. @@ -105,7 +105,7 @@ public function chown($files, $user, $recursive = false); * * @throws IOException When the change fail */ - public function chgrp($files, $group, $recursive = false); + public function chgrp($files, string $group, bool $recursive = false); /** * Renames a file or a directory. @@ -117,7 +117,7 @@ public function chgrp($files, $group, $recursive = false); * @throws IOException When target file or directory already exists * @throws IOException When origin cannot be renamed */ - public function rename($origin, $target, $overwrite = false); + public function rename(string $origin, string $target, bool $overwrite = false); /** * Creates a symbolic link or copy a directory. @@ -128,7 +128,7 @@ public function rename($origin, $target, $overwrite = false); * * @throws IOException When symlink fails */ - public function symlink($originDir, $targetDir, $copyOnWindows = false); + public function symlink(string $originDir, string $targetDir, bool $copyOnWindows = false); /** * Mirrors a directory to another. @@ -144,7 +144,7 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false); * * @throws IOException When file type is unknown */ - public function mirror($originDir, $targetDir, \Traversable $iterator = null, $options = []); + public function mirror(string $originDir, string $targetDir, \Traversable $iterator = null, array $options = []); /** * Given an existing path, convert it to a path relative to a given starting path. @@ -154,7 +154,7 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o * * @return string Path of target relative to starting path */ - public function makePathRelative($endPath, $startPath); + public function makePathRelative(string $endPath, string $startPath); /** * Returns whether the file path is an absolute path. @@ -163,7 +163,7 @@ public function makePathRelative($endPath, $startPath); * * @return bool */ - public function isAbsolutePath($file); + public function isAbsolutePath(string $file); public function getFileContents(string $file): string; } diff --git a/src/Loader/ThemeLoader.php b/src/Loader/ThemeLoader.php index a6e08f86..1098c695 100644 --- a/src/Loader/ThemeLoader.php +++ b/src/Loader/ThemeLoader.php @@ -81,7 +81,6 @@ private function initializeThemes(array $configurations): array { $themes = []; foreach ($configurations as $configuration) { - /** @var ThemeInterface $theme */ $themes[$configuration['name']] = $this->themeFactory->create($configuration['name'], $configuration['path']); } diff --git a/src/Locator/BundleResourceLocator.php b/src/Locator/BundleResourceLocator.php index b02922ac..91cea679 100644 --- a/src/Locator/BundleResourceLocator.php +++ b/src/Locator/BundleResourceLocator.php @@ -66,7 +66,7 @@ private function locateResourceBasedOnBundleNotation(string $resourcePath, Theme // Symfony 4.0+ always returns a single bundle /** @var BundleInterface|BundleInterface[] $bundles */ - $bundles = $this->kernel->getBundle($bundleName, false); + $bundles = $this->kernel->getBundle($bundleName); // So we need to hack it to support both Symfony 3.4 and Symfony 4.0+ if (!is_array($bundles)) { diff --git a/src/Twig/ThemeFilesystemLoader.php b/src/Twig/ThemeFilesystemLoader.php index 54614373..0a65432e 100644 --- a/src/Twig/ThemeFilesystemLoader.php +++ b/src/Twig/ThemeFilesystemLoader.php @@ -74,6 +74,7 @@ public function getCacheKey($name): string /** * @param string|TemplateReference $name + * @param int $time */ public function isFresh($name, $time): bool { diff --git a/tests/Application/Kernel.php b/tests/Application/Kernel.php index f22160aa..54aef8cc 100644 --- a/tests/Application/Kernel.php +++ b/tests/Application/Kernel.php @@ -18,9 +18,6 @@ final class Kernel extends HttpKernel { - /** - * {@inheritdoc} - */ public function registerBundles() { return [ @@ -31,10 +28,7 @@ public function registerBundles() ]; } - /** - * {@inheritdoc} - */ - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load(__DIR__ . '/config/config.yml'); } diff --git a/tests/Application/TestBundle/DependencyInjection/TestExtension.php b/tests/Application/TestBundle/DependencyInjection/TestExtension.php index 489b91c3..b0bced55 100644 --- a/tests/Application/TestBundle/DependencyInjection/TestExtension.php +++ b/tests/Application/TestBundle/DependencyInjection/TestExtension.php @@ -20,10 +20,7 @@ final class TestExtension extends Extension { - /** - * {@inheritdoc} - */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.xml'); diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index 76e276dc..8ac71fc4 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -66,7 +66,7 @@ public function its_context_can_be_overridden(): void /** * @test */ - public function assets_support_is_enabled_by_default() + public function assets_support_is_enabled_by_default(): void { $this->assertProcessedConfigurationEquals([[]], ['assets' => ['enabled' => true]], 'assets'); } @@ -74,7 +74,7 @@ public function assets_support_is_enabled_by_default() /** * @test */ - public function assets_support_may_be_toggled() + public function assets_support_may_be_toggled(): void { $this->assertProcessedConfigurationEquals([['assets' => ['enabled' => true]]], ['assets' => ['enabled' => true]], 'assets'); $this->assertProcessedConfigurationEquals([['assets' => []]], ['assets' => ['enabled' => true]], 'assets'); @@ -87,7 +87,7 @@ public function assets_support_may_be_toggled() /** * @test */ - public function templating_support_is_enabled_by_default() + public function templating_support_is_enabled_by_default(): void { $this->assertProcessedConfigurationEquals([[]], ['templating' => ['enabled' => true]], 'templating'); } @@ -95,7 +95,7 @@ public function templating_support_is_enabled_by_default() /** * @test */ - public function templating_support_may_be_toggled() + public function templating_support_may_be_toggled(): void { $this->assertProcessedConfigurationEquals([['templating' => ['enabled' => true]]], ['templating' => ['enabled' => true]], 'templating'); $this->assertProcessedConfigurationEquals([['templating' => []]], ['templating' => ['enabled' => true]], 'templating'); @@ -108,7 +108,7 @@ public function templating_support_may_be_toggled() /** * @test */ - public function translations_support_is_enabled_by_default() + public function translations_support_is_enabled_by_default(): void { $this->assertProcessedConfigurationEquals([[]], ['translations' => ['enabled' => true]], 'translations'); } @@ -116,7 +116,7 @@ public function translations_support_is_enabled_by_default() /** * @test */ - public function translations_support_may_be_toggled() + public function translations_support_may_be_toggled(): void { $this->assertProcessedConfigurationEquals([['translations' => ['enabled' => true]]], ['translations' => ['enabled' => true]], 'translations'); $this->assertProcessedConfigurationEquals([['translations' => []]], ['translations' => ['enabled' => true]], 'translations'); @@ -126,9 +126,6 @@ public function translations_support_may_be_toggled() $this->assertProcessedConfigurationEquals([['translations' => false]], ['translations' => ['enabled' => false]], 'translations'); } - /** - * {@inheritdoc} - */ protected function getConfiguration(): ConfigurationInterface { return new Configuration(); diff --git a/tests/Functional/AssetTest.php b/tests/Functional/AssetTest.php index ddc814c7..a45f79e7 100644 --- a/tests/Functional/AssetTest.php +++ b/tests/Functional/AssetTest.php @@ -107,7 +107,7 @@ private function createWebDirectory(): string return $webDirectory; } - private function assertFileContent($lines, $webDirectory): void + private function assertFileContent(array $lines, string $webDirectory): void { foreach ($lines as $line) { if (empty($line)) { diff --git a/tests/Translation/DependencyInjection/Compiler/TranslatorFallbackLocalesPassTest.php b/tests/Translation/DependencyInjection/Compiler/TranslatorFallbackLocalesPassTest.php index 0e1defab..42a3efd6 100644 --- a/tests/Translation/DependencyInjection/Compiler/TranslatorFallbackLocalesPassTest.php +++ b/tests/Translation/DependencyInjection/Compiler/TranslatorFallbackLocalesPassTest.php @@ -103,10 +103,7 @@ public function it_does_not_force_symfony_translator_to_have_any_method_calls(): $this->assertContainerBuilderHasService('sylius.theme.translation.translator'); } - /** - * {@inheritdoc} - */ - protected function registerCompilerPass(ContainerBuilder $container) + protected function registerCompilerPass(ContainerBuilder $container): void { $container->addCompilerPass(new TranslatorFallbackLocalesPass()); } diff --git a/tests/Translation/DependencyInjection/Compiler/TranslatorLoaderProviderPassTest.php b/tests/Translation/DependencyInjection/Compiler/TranslatorLoaderProviderPassTest.php index 7f5ae43e..7e3c4cb7 100644 --- a/tests/Translation/DependencyInjection/Compiler/TranslatorLoaderProviderPassTest.php +++ b/tests/Translation/DependencyInjection/Compiler/TranslatorLoaderProviderPassTest.php @@ -98,10 +98,7 @@ public function it_does_not_force_the_existence_of_translation_loaders(): void ); } - /** - * {@inheritdoc} - */ - protected function registerCompilerPass(ContainerBuilder $container) + protected function registerCompilerPass(ContainerBuilder $container): void { $container->addCompilerPass(new TranslatorLoaderProviderPass()); } diff --git a/tests/Translation/DependencyInjection/Compiler/TranslatorResourceProviderPassTest.php b/tests/Translation/DependencyInjection/Compiler/TranslatorResourceProviderPassTest.php index f8f36dbf..591570dd 100644 --- a/tests/Translation/DependencyInjection/Compiler/TranslatorResourceProviderPassTest.php +++ b/tests/Translation/DependencyInjection/Compiler/TranslatorResourceProviderPassTest.php @@ -144,10 +144,7 @@ public function it_does_not_crash_if_definition_does_not_have_resource_files_at_ ); } - /** - * {@inheritdoc} - */ - protected function registerCompilerPass(ContainerBuilder $container) + protected function registerCompilerPass(ContainerBuilder $container): void { $container->addCompilerPass(new TranslatorResourceProviderPass()); } diff --git a/tests/Translation/TranslatorTest.php b/tests/Translation/TranslatorTest.php index fe910305..a9a6bda6 100644 --- a/tests/Translation/TranslatorTest.php +++ b/tests/Translation/TranslatorTest.php @@ -51,7 +51,7 @@ public function it_instantiates_with_valid_options(array $options): void * @dataProvider getInvalidLocalesTests * @expectedException \InvalidArgumentException */ - public function it_throws_exception_on_instantiating_with_invalid_locale($locale): void + public function it_throws_exception_on_instantiating_with_invalid_locale(string $locale): void { $this->createTranslator($locale); } @@ -60,7 +60,7 @@ public function it_throws_exception_on_instantiating_with_invalid_locale($locale * @test * @dataProvider getAllValidLocalesTests */ - public function it_instantiates_with_valid_locale($locale): void + public function it_instantiates_with_valid_locale(string $locale): void { $translator = $this->createTranslator($locale); @@ -72,7 +72,7 @@ public function it_instantiates_with_valid_locale($locale): void * @dataProvider getInvalidLocalesTests * @expectedException \InvalidArgumentException */ - public function its_throws_exception_on_setting_invalid_fallback_locales($locale): void + public function its_throws_exception_on_setting_invalid_fallback_locales(string $locale): void { $translator = $this->createTranslator('fr'); $translator->setFallbackLocales(['fr', $locale]); @@ -82,7 +82,7 @@ public function its_throws_exception_on_setting_invalid_fallback_locales($locale * @test * @dataProvider getAllValidLocalesTests */ - public function its_fallback_locales_can_be_set_only_if_valid($locale): void + public function its_fallback_locales_can_be_set_only_if_valid(string $locale): void { $translator = $this->createTranslator('fr'); $translator->setFallbackLocales(['fr', $locale]); @@ -94,7 +94,7 @@ public function its_fallback_locales_can_be_set_only_if_valid($locale): void * @test * @dataProvider getAllValidLocalesTests */ - public function it_adds_resources_with_valid_locales($locale): void + public function it_adds_resources_with_valid_locales(string $locale): void { $translator = $this->createTranslator('fr'); $translator->addLoader('array', new ArrayLoader()); @@ -107,7 +107,7 @@ public function it_adds_resources_with_valid_locales($locale): void * @test * @dataProvider getAllValidLocalesTests */ - public function it_translates_valid_locales($locale): void + public function it_translates_valid_locales(string $locale): void { $translator = $this->createTranslator($locale); $translator->addLoader('array', new ArrayLoader()); @@ -153,7 +153,7 @@ public function it_can_have_multiple_fallback_locales(): void * @test * @dataProvider getThemelessLocalesTests */ - public function it_gets_catalogue_with_fallback_catalogues_of_a_simple_locale($locale): void + public function it_gets_catalogue_with_fallback_catalogues_of_a_simple_locale(string $locale): void { $translator = $this->createTranslator($locale); $catalogue = new MessageCatalogue($locale); @@ -165,7 +165,7 @@ public function it_gets_catalogue_with_fallback_catalogues_of_a_simple_locale($l * @test * @dataProvider getThemedLocalesTests */ - public function it_gets_catalogue_with_fallback_catalogues_of_a_themed_locale($locale): void + public function it_gets_catalogue_with_fallback_catalogues_of_a_themed_locale(string $locale): void { $translator = $this->createTranslator($locale); @@ -269,10 +269,7 @@ public function it_creates_a_nested_catalogue_with_fallback_translations(): void $this->assertEquals($catalogue, $translator->getCatalogue()); } - /** - * @return array - */ - public function getInvalidLocalesTests() + public function getInvalidLocalesTests(): array { return [ ['fr FR'], @@ -289,10 +286,7 @@ public function getInvalidLocalesTests() ]; } - /** - * @return array - */ - public function getAllValidLocalesTests() + public function getAllValidLocalesTests(): array { return array_merge( $this->getThemedLocalesTests(), @@ -300,10 +294,7 @@ public function getAllValidLocalesTests() ); } - /** - * @return array - */ - public function getThemedLocalesTests() + public function getThemedLocalesTests(): array { return [ ['fr@heron'], @@ -316,10 +307,7 @@ public function getThemedLocalesTests() ]; } - /** - * @return array - */ - public function getThemelessLocalesTests() + public function getThemelessLocalesTests(): array { return [ [''], @@ -333,10 +321,7 @@ public function getThemelessLocalesTests() ]; } - /** - * @return array - */ - public function getValidOptionsTests() + public function getValidOptionsTests(): array { return [ [['cache_dir' => null, 'debug' => false]], @@ -347,10 +332,7 @@ public function getValidOptionsTests() ]; } - /** - * @return array - */ - public function getInvalidOptionsTests() + public function getInvalidOptionsTests(): array { return [ [['heron' => '']], @@ -360,10 +342,9 @@ public function getInvalidOptionsTests() } /** - * @param string $locale * @param string[] $options */ - private function createTranslator($locale = 'en', $options = []): Translator + private function createTranslator(string $locale = 'en', array $options = []): Translator { $loaderProvider = new TranslatorLoaderProvider(); $resourceProvider = new TranslatorResourceProvider();