diff --git a/phpstan.neon b/phpstan.neon index fa39039..89ad65e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,3 +1,3 @@ parameters: - level: 6 + level: 7 checkMissingIterableValueType: false diff --git a/psalm-report.json b/psalm-report.json index 74204f4..d27f3af 100644 --- a/psalm-report.json +++ b/psalm-report.json @@ -23,30 +23,6 @@ "selected_text": "$locales", "error_level": 6, "shortcode": 128 - }, - { - "severity": "error", - "line_from": 237, - "line_to": 237, - "type": "InvalidReturnType", - "message": "The declared return type 'array' for Spryker\\Zed\\Locale\\Business\\Manager\\LocaleManager::getAvailableLocaleCollection is incorrect, got 'array'", - "file_name": "vendor/spryker/spryker/Bundles/Locale/src/Spryker/Zed/Locale/Business/Manager/LocaleManager.php", - "snippet": " * @return array<\\Generated\\Shared\\Transfer\\LocaleTransfer>", - "selected_text": "array<\\Generated\\Shared\\Transfer\\LocaleTransfer>", - "error_level": 6, - "shortcode": 11 - }, - { - "severity": "error", - "line_from": 247, - "line_to": 247, - "type": "InvalidReturnStatement", - "message": "The inferred type 'array' does not match the declared return type 'array' for Spryker\\Zed\\Locale\\Business\\Manager\\LocaleManager::getAvailableLocaleCollection", - "file_name": "vendor/spryker/spryker/Bundles/Locale/src/Spryker/Zed/Locale/Business/Manager/LocaleManager.php", - "snippet": " return array_merge(array_flip($availableLocales), $indexedLocaleTransfers);", - "selected_text": "array_merge(array_flip($availableLocales), $indexedLocaleTransfers)", - "error_level": 6, - "shortcode": 128 } ], "warning": [ @@ -184,8 +160,8 @@ }, { "severity": "info", - "line_from": 260, - "line_to": 260, + "line_from": 262, + "line_to": 262, "type": "PossiblyNullArrayOffset", "message": "Cannot access value on variable $indexedLocaleTransfers[null|string] using possibly null offset null|string", "file_name": "vendor/spryker/spryker/Bundles/Locale/src/Spryker/Zed/Locale/Business/Manager/LocaleManager.php", @@ -199,7 +175,7 @@ "line_from": 47, "line_to": 47, "type": "InvalidNullableReturnType", - "message": "The declared return type 'string' for /var/work/devvm/project/vendor/spryker/spryker/bundles/locale/src/spryker/zed/locale/communication/plugin/application/localeapplicationplugin.php:47:1540:-:closure is not nullable, but 'null|string' contains null", + "message": "The declared return type 'string' for /data/vendor/spryker/spryker/bundles/locale/src/spryker/zed/locale/communication/plugin/application/localeapplicationplugin.php:47:1540:-:closure is not nullable, but 'null|string' contains null", "file_name": "vendor/spryker/spryker/Bundles/Locale/src/Spryker/Zed/Locale/Communication/Plugin/Application/LocaleApplicationPlugin.php", "snippet": " $container->set(static::SERVICE_LOCALE, function (ContainerInterface $container): string {", "selected_text": "string", @@ -211,7 +187,7 @@ "line_from": 52, "line_to": 52, "type": "NullableReturnStatement", - "message": "The declared return type 'string' for /var/work/devvm/project/vendor/spryker/spryker/bundles/locale/src/spryker/zed/locale/communication/plugin/application/localeapplicationplugin.php:47:1540:-:closure is not nullable, but the function returns 'null|string'", + "message": "The declared return type 'string' for /data/vendor/spryker/spryker/bundles/locale/src/spryker/zed/locale/communication/plugin/application/localeapplicationplugin.php:47:1540:-:closure is not nullable, but the function returns 'null|string'", "file_name": "vendor/spryker/spryker/Bundles/Locale/src/Spryker/Zed/Locale/Communication/Plugin/Application/LocaleApplicationPlugin.php", "snippet": " return $localeTransfer->getLocaleName();", "selected_text": "$localeTransfer->getLocaleName()", diff --git a/src/Spryker/Zed/Locale/Business/Internal/Install/LocaleInstaller.php b/src/Spryker/Zed/Locale/Business/Internal/Install/LocaleInstaller.php index 7979331..4c748c7 100644 --- a/src/Spryker/Zed/Locale/Business/Internal/Install/LocaleInstaller.php +++ b/src/Spryker/Zed/Locale/Business/Internal/Install/LocaleInstaller.php @@ -58,10 +58,13 @@ protected function installLocales() */ protected function executeInstallLocalesTransaction(): void { + /** @var resource $localeFile */ $localeFile = fopen($this->localeFile, 'r'); while (!feof($localeFile)) { - $locale = trim(fgets($localeFile)); + /** @var string $locale */ + $locale = fgets($localeFile); + $locale = trim($locale); $query = $this->localeQueryContainer->queryLocaleByName($locale); diff --git a/src/Spryker/Zed/Locale/Business/Manager/LocaleManager.php b/src/Spryker/Zed/Locale/Business/Manager/LocaleManager.php index b3c73d0..8fffd04 100644 --- a/src/Spryker/Zed/Locale/Business/Manager/LocaleManager.php +++ b/src/Spryker/Zed/Locale/Business/Manager/LocaleManager.php @@ -243,8 +243,10 @@ protected function getAvailableLocaleCollection(Store $store): array $localeTransfers = $this->localeRepository->getLocaleTransfersByLocaleNames($availableLocales); $indexedLocaleTransfers = $this->indexLocaleTransfersByLocalename($localeTransfers); + /** @var array<\Generated\Shared\Transfer\LocaleTransfer> $availableLocales */ + $availableLocales = array_intersect_key(array_flip($availableLocales), $indexedLocaleTransfers); - return array_merge(array_flip($availableLocales), $indexedLocaleTransfers); + return array_merge($availableLocales, $indexedLocaleTransfers); } /** diff --git a/src/Spryker/Zed/Locale/LocaleConfig.php b/src/Spryker/Zed/Locale/LocaleConfig.php index fe0f96e..bc49981 100644 --- a/src/Spryker/Zed/Locale/LocaleConfig.php +++ b/src/Spryker/Zed/Locale/LocaleConfig.php @@ -18,6 +18,7 @@ class LocaleConfig extends AbstractBundleConfig */ public function getLocaleFile() { + /** @phpstan-var string */ return realpath(__DIR__ . '/Business/Internal/Install/locales.txt'); } } diff --git a/tests/SprykerTest/Zed/Locale/Business/LocaleFacadeTest.php b/tests/SprykerTest/Zed/Locale/Business/LocaleFacadeTest.php index 7e45542..9c7b010 100644 --- a/tests/SprykerTest/Zed/Locale/Business/LocaleFacadeTest.php +++ b/tests/SprykerTest/Zed/Locale/Business/LocaleFacadeTest.php @@ -46,6 +46,11 @@ class LocaleFacadeTest extends Unit */ protected $localeNames = []; + /** + * @var \SprykerTest\Zed\Locale\LocaleBusinessTester + */ + protected $tester; + /** * @return void */ @@ -105,4 +110,17 @@ public function testCurrentLocaleIsChangeable(): void //Assert $this->assertSame($currentLocale->getLocaleName(), $newCurrentLocale->getLocaleName()); } + + /** + * @return void + */ + public function testGetLocaleCollectionGetsLocalesFromStoreInstance(): void + { + // Act + $localeTransfers = $this->localeFacade->getLocaleCollection(); + + // Assert + $this->assertSame('en_US', array_keys($localeTransfers)[0]); + $this->assertSame('de_DE', array_keys($localeTransfers)[1]); + } }