diff --git a/Build/Scripts/phpstan.sh b/Build/Scripts/phpstan.sh new file mode 100755 index 0000000..7a95b00 --- /dev/null +++ b/Build/Scripts/phpstan.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +THIS_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" +cd "$THIS_SCRIPT_DIR" || exit 1 +cd ../../ || exit 1 +CORE_ROOT="${PWD}" + +Build/Scripts/runTests.sh -s composerInstall + +Build/Scripts/runTests.sh -s phpstan + +Build/Scripts/runTests.sh -s clean +Build/Scripts/additionalTests.sh -s clean diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon new file mode 100644 index 0000000..1339890 --- /dev/null +++ b/Build/phpstan/phpstan-baseline.neon @@ -0,0 +1,2 @@ +parameters: + ignoreErrors: \ No newline at end of file diff --git a/Build/phpstan/phpstan-constants.php b/Build/phpstan/phpstan-constants.php new file mode 100644 index 0000000..0bb0280 --- /dev/null +++ b/Build/phpstan/phpstan-constants.php @@ -0,0 +1,4 @@ +renderResponse('File/ConvertFile'); } + /** + * @return array>> + * @throws PropagateResponseException + */ protected function prepareExtensions(ServerRequestInterface $request, bool $selected = true): array { $extensions = $this->extensionService->getLocalExtensions(); @@ -133,6 +137,10 @@ protected function prepareExtensions(ServerRequestInterface $request, bool $sele return [$extensions, $selectedExtension, $selectedExtensionKey]; } + /** + * @return array>> + * @throws PropagateResponseException + */ protected function prepareFiles(ServerRequestInterface $request, string $extension, bool $selected = true): array { $files = $this->extensionService->getFilesOfExtension($extension); @@ -152,6 +160,7 @@ protected function prepareFiles(ServerRequestInterface $request, string $extensi } /** + * @param array $extensions * @throws PropagateResponseException */ protected function getSelectedExtension(ServerRequestInterface $request, array $extensions): string @@ -164,6 +173,7 @@ protected function getSelectedExtension(ServerRequestInterface $request, array $ } /** + * @param array $files * @throws PropagateResponseException */ protected function getSelectedFile(ServerRequestInterface $request, array $files): string @@ -175,6 +185,9 @@ protected function getSelectedFile(ServerRequestInterface $request, array $files return $selectedFile; } + /** + * @param array $values + */ protected function isArgumentSetAndAvailable(ServerRequestInterface $request, array $values, string $key): ?string { $formFieldValue = (string)($request->getParsedBody()[$key] ?? $request->getQueryParams()[$key] ?? ''); diff --git a/Classes/File/Converter.php b/Classes/File/Converter.php index 5b41883..46f69b5 100644 --- a/Classes/File/Converter.php +++ b/Classes/File/Converter.php @@ -105,8 +105,7 @@ protected function checkLanguageFilename(string $xmlFile): string /** * @param string $languageFile Absolute reference to the base locallang file - * - * @return array + * @return string[] */ protected function getAvailableTranslations(string $languageFile): array { @@ -198,10 +197,9 @@ protected function getOriginalFileName(string $filename, string $langKey): strin /** * Reads/Requires locallang files and returns raw $LOCAL_LANG array - * * @param string $languageFile Absolute reference to the ll-XML locallang file. - * - * @return array LOCAL_LANG array from ll-XML file (with all possible sub-files for languages included) + * @return array> LOCAL_LANG array from ll-XML file + * (with all possible sub-files for languages included) */ protected function getCombinedTranslationFileContent(string $languageFile): array { @@ -211,7 +209,7 @@ protected function getCombinedTranslationFileContent(string $languageFile): arra $includedLanguages = array_keys($ll['data']); foreach ($includedLanguages as $langKey) { - /** @var $parser LocallangXmlParser */ + /** @var LocallangXmlParser $parser */ $parser = GeneralUtility::makeInstance(LocallangXmlParser::class); $localLangContent = $parser->getParsedData($languageFile, $langKey); unset($parser); @@ -219,7 +217,7 @@ protected function getCombinedTranslationFileContent(string $languageFile): arra } } else { require($languageFile); - $includedLanguages = isset($LOCAL_LANG) ? array_keys($LOCAL_LANG) : []; + $includedLanguages = array_keys($LOCAL_LANG); } if (empty($includedLanguages)) { @@ -238,7 +236,7 @@ protected function getCombinedTranslationFileContent(string $languageFile): arra * @param string $namespacePrefix The tag-prefix resolve, e.g. a namespace like "T3:" * @param bool $reportDocTag If set, the document tag will be set in the key "_DOCUMENT_TAG" of the output array * - * @return array|string If the parsing had errors, a string with the error message is returned. + * @return array|string If the parsing had errors, a string with the error message is returned. * Otherwise, an array with the content. * * @see GeneralUtility::array2xml(),GeneralUtility::xml2arrayProcess() diff --git a/Classes/File/TransUnit.php b/Classes/File/TransUnit.php index f0b2e73..25b3ebc 100644 --- a/Classes/File/TransUnit.php +++ b/Classes/File/TransUnit.php @@ -21,6 +21,12 @@ protected string $target; + /** + * @param string|array $data + * @param string $key + * @param string $langKey + * @param array> $LOCAL_LANG + */ public function __construct( string|array $data, protected string $key, diff --git a/Classes/Localization/Parser/LocallangXmlParser.php b/Classes/Localization/Parser/LocallangXmlParser.php index 1c88389..c99b593 100644 --- a/Classes/Localization/Parser/LocallangXmlParser.php +++ b/Classes/Localization/Parser/LocallangXmlParser.php @@ -29,6 +29,7 @@ class LocallangXmlParser extends AbstractXmlParser { /** * Associative array of "filename => parsed data" pairs. + * @var array> $parsedTargetFiles */ protected array $parsedTargetFiles = []; @@ -38,7 +39,7 @@ class LocallangXmlParser extends AbstractXmlParser * @param string $sourcePath Source file path * @param string $languageKey Language key * - * @return array + * @return array> * * @throws FileNotFoundException * @throws InvalidXmlFileException @@ -71,6 +72,7 @@ public function getParsedData($sourcePath, $languageKey): array /** * Parse the given language key tag + * @return array> */ protected function getParsedDataForElement(\SimpleXMLElement $bodyOfFileTag, string $element): array { @@ -97,6 +99,7 @@ protected function getParsedDataForElement(\SimpleXMLElement $bodyOfFileTag, str /** * Returns array representation of XLIFF data, starting from a root node. + * @return array> */ protected function doParsingFromRoot(\SimpleXMLElement $root): array { @@ -105,6 +108,7 @@ protected function doParsingFromRoot(\SimpleXMLElement $root): array /** * Returns array representation of XLIFF data, starting from a root node. + * @return array> */ protected function doParsingTargetFromRoot(\SimpleXMLElement $root): array { @@ -113,6 +117,7 @@ protected function doParsingTargetFromRoot(\SimpleXMLElement $root): array /** * Returns array representation of XLIFF data, starting from a root node. + * @return array> */ protected function doParsingFromRootForElement(\SimpleXMLElement $root, string $element): array { @@ -153,6 +158,7 @@ protected function doParsingFromRootForElement(\SimpleXMLElement $root, string $ * Returns parsed representation of XML file. * * Parses XML if it wasn't done before. Caches parsed data. + * @return array> */ protected function getParsedTargetData(string $path): array { @@ -164,6 +170,7 @@ protected function getParsedTargetData(string $path): array /** * Reads and parses XML file and returns internal representation of data. + * @return array> */ protected function parseXmlTargetFile(string $targetPath): array { diff --git a/Classes/Service/ExtensionService.php b/Classes/Service/ExtensionService.php index e07c51e..b419b43 100644 --- a/Classes/Service/ExtensionService.php +++ b/Classes/Service/ExtensionService.php @@ -27,6 +27,9 @@ public function __construct( protected Converter $converter, ) {} + /** + * @return array> + */ public function getLocalExtensions(): array { $availableExtensions = $this->listUtility->getAvailableExtensions(); @@ -52,6 +55,7 @@ function (array $extension) { /** * Gather files for given extension key that need to be converted + * @return array> */ public function getFilesOfExtension(string $extensionKey): array { @@ -82,6 +86,10 @@ protected function isLanguageFile(string $filePath): bool return str_contains($filePath, 'Resources/Private/Language/'); } + /** + * @param array> $files + * @return array + */ public function convertLanguageFile(string $selectedExtension, string $selectedFile, array $files): array { $wasConvertedPreviously = false; diff --git a/composer.json b/composer.json index 13a2137..2905930 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,11 @@ "psr/http-message": "^1.1 || ^2.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.57.1", + "friendsofphp/php-cs-fixer": "^3.64.0", + "friendsoftypo3/phpstan-typo3": "^0.9.0", + "phpstan/phpdoc-parser": "^1.30.0", + "phpstan/phpstan": "^1.12.5", + "phpunit/phpunit": "^11.0.3", "typo3/testing-framework": "dev-main" }, "minimum-stability": "dev",