Skip to content

Commit fee79e0

Browse files
committed
[CHORE] Change phpstan level to 6 and cleanup phpstan errors
1 parent f2f1064 commit fee79e0

11 files changed

Lines changed: 88 additions & 10 deletions

File tree

Build/Scripts/phpstan.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
THIS_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
4+
cd "$THIS_SCRIPT_DIR" || exit 1
5+
cd ../../ || exit 1
6+
CORE_ROOT="${PWD}"
7+
8+
Build/Scripts/runTests.sh -s composerInstall
9+
10+
Build/Scripts/runTests.sh -s phpstan
11+
12+
Build/Scripts/runTests.sh -s clean
13+
Build/Scripts/additionalTests.sh -s clean
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameters:
2+
ignoreErrors:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
// testing-framework defines this, used in various tests.
4+
define('ORIGINAL_ROOT', dirname(__FILE__, 2) . '/');

Build/phpstan/phpstan.local.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
includes:
2+
- phpstan.neon

Build/phpstan/phpstan.neon

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
- ../vendor/friendsoftypo3/phpstan-typo3/extension.neon
4+
5+
parameters:
6+
# Use local .cache dir instead of /tmp
7+
tmpDir: ../.cache/phpstan
8+
9+
level: 6
10+
11+
bootstrapFiles:
12+
- phpstan-constants.php
13+
14+
paths:
15+
- ../../
16+
17+
excludePaths:
18+
# we do not check required extensions
19+
- ../../Build/*
20+
# ext_emconf.php get the $_EXTKEY set from outside. We'll ignore all of them
21+
- ../ext_emconf.php

Classes/Controller/FileController.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ public function convertFileAction(ServerRequestInterface $request): ResponseInte
115115
return $moduleTemplate->renderResponse('File/ConvertFile');
116116
}
117117

118+
/**
119+
* @return array<string|array<array<string, string>>>
120+
* @throws PropagateResponseException
121+
*/
118122
protected function prepareExtensions(ServerRequestInterface $request, bool $selected = true): array
119123
{
120124
$extensions = $this->extensionService->getLocalExtensions();
@@ -133,6 +137,10 @@ protected function prepareExtensions(ServerRequestInterface $request, bool $sele
133137
return [$extensions, $selectedExtension, $selectedExtensionKey];
134138
}
135139

140+
/**
141+
* @return array<string|array<array<string, string>>>
142+
* @throws PropagateResponseException
143+
*/
136144
protected function prepareFiles(ServerRequestInterface $request, string $extension, bool $selected = true): array
137145
{
138146
$files = $this->extensionService->getFilesOfExtension($extension);
@@ -152,6 +160,7 @@ protected function prepareFiles(ServerRequestInterface $request, string $extensi
152160
}
153161

154162
/**
163+
* @param array<string, mixed> $extensions
155164
* @throws PropagateResponseException
156165
*/
157166
protected function getSelectedExtension(ServerRequestInterface $request, array $extensions): string
@@ -164,6 +173,7 @@ protected function getSelectedExtension(ServerRequestInterface $request, array $
164173
}
165174

166175
/**
176+
* @param array<string, mixed> $files
167177
* @throws PropagateResponseException
168178
*/
169179
protected function getSelectedFile(ServerRequestInterface $request, array $files): string
@@ -175,6 +185,9 @@ protected function getSelectedFile(ServerRequestInterface $request, array $files
175185
return $selectedFile;
176186
}
177187

188+
/**
189+
* @param array<string, mixed> $values
190+
*/
178191
protected function isArgumentSetAndAvailable(ServerRequestInterface $request, array $values, string $key): ?string
179192
{
180193
$formFieldValue = (string)($request->getParsedBody()[$key] ?? $request->getQueryParams()[$key] ?? '');

Classes/File/Converter.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ protected function checkLanguageFilename(string $xmlFile): string
105105

106106
/**
107107
* @param string $languageFile Absolute reference to the base locallang file
108-
*
109-
* @return array
108+
* @return string[]
110109
*/
111110
protected function getAvailableTranslations(string $languageFile): array
112111
{
@@ -198,10 +197,9 @@ protected function getOriginalFileName(string $filename, string $langKey): strin
198197

199198
/**
200199
* Reads/Requires locallang files and returns raw $LOCAL_LANG array
201-
*
202200
* @param string $languageFile Absolute reference to the ll-XML locallang file.
203-
*
204-
* @return array LOCAL_LANG array from ll-XML file (with all possible sub-files for languages included)
201+
* @return array<string, array<string, string>> LOCAL_LANG array from ll-XML file
202+
* (with all possible sub-files for languages included)
205203
*/
206204
protected function getCombinedTranslationFileContent(string $languageFile): array
207205
{
@@ -211,15 +209,15 @@ protected function getCombinedTranslationFileContent(string $languageFile): arra
211209
$includedLanguages = array_keys($ll['data']);
212210

213211
foreach ($includedLanguages as $langKey) {
214-
/** @var $parser LocallangXmlParser */
212+
/** @var LocallangXmlParser $parser */
215213
$parser = GeneralUtility::makeInstance(LocallangXmlParser::class);
216214
$localLangContent = $parser->getParsedData($languageFile, $langKey);
217215
unset($parser);
218216
$LOCAL_LANG[$langKey] = $localLangContent[$langKey];
219217
}
220218
} else {
221219
require($languageFile);
222-
$includedLanguages = isset($LOCAL_LANG) ? array_keys($LOCAL_LANG) : [];
220+
$includedLanguages = array_keys($LOCAL_LANG);
223221
}
224222

225223
if (empty($includedLanguages)) {
@@ -238,7 +236,7 @@ protected function getCombinedTranslationFileContent(string $languageFile): arra
238236
* @param string $namespacePrefix The tag-prefix resolve, e.g. a namespace like "T3:"
239237
* @param bool $reportDocTag If set, the document tag will be set in the key "_DOCUMENT_TAG" of the output array
240238
*
241-
* @return array|string If the parsing had errors, a string with the error message is returned.
239+
* @return array<string, mixed>|string If the parsing had errors, a string with the error message is returned.
242240
* Otherwise, an array with the content.
243241
*
244242
* @see GeneralUtility::array2xml(),GeneralUtility::xml2arrayProcess()

Classes/File/TransUnit.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121

2222
protected string $target;
2323

24+
/**
25+
* @param string|array<string, string> $data
26+
* @param string $key
27+
* @param string $langKey
28+
* @param array<string, array<string, string>> $LOCAL_LANG
29+
*/
2430
public function __construct(
2531
string|array $data,
2632
protected string $key,

Classes/Localization/Parser/LocallangXmlParser.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class LocallangXmlParser extends AbstractXmlParser
2929
{
3030
/**
3131
* Associative array of "filename => parsed data" pairs.
32+
* @var array<string, array<string, mixed>> $parsedTargetFiles
3233
*/
3334
protected array $parsedTargetFiles = [];
3435

@@ -38,7 +39,7 @@ class LocallangXmlParser extends AbstractXmlParser
3839
* @param string $sourcePath Source file path
3940
* @param string $languageKey Language key
4041
*
41-
* @return array
42+
* @return array<string, array<string, string>>
4243
*
4344
* @throws FileNotFoundException
4445
* @throws InvalidXmlFileException
@@ -71,6 +72,7 @@ public function getParsedData($sourcePath, $languageKey): array
7172

7273
/**
7374
* Parse the given language key tag
75+
* @return array<string, array<string, string>>
7476
*/
7577
protected function getParsedDataForElement(\SimpleXMLElement $bodyOfFileTag, string $element): array
7678
{
@@ -97,6 +99,7 @@ protected function getParsedDataForElement(\SimpleXMLElement $bodyOfFileTag, str
9799

98100
/**
99101
* Returns array representation of XLIFF data, starting from a root node.
102+
* @return array<string, array<string, string>>
100103
*/
101104
protected function doParsingFromRoot(\SimpleXMLElement $root): array
102105
{
@@ -105,6 +108,7 @@ protected function doParsingFromRoot(\SimpleXMLElement $root): array
105108

106109
/**
107110
* Returns array representation of XLIFF data, starting from a root node.
111+
* @return array<string, array<string, string>>
108112
*/
109113
protected function doParsingTargetFromRoot(\SimpleXMLElement $root): array
110114
{
@@ -113,6 +117,7 @@ protected function doParsingTargetFromRoot(\SimpleXMLElement $root): array
113117

114118
/**
115119
* Returns array representation of XLIFF data, starting from a root node.
120+
* @return array<string, array<string, string>>
116121
*/
117122
protected function doParsingFromRootForElement(\SimpleXMLElement $root, string $element): array
118123
{
@@ -153,6 +158,7 @@ protected function doParsingFromRootForElement(\SimpleXMLElement $root, string $
153158
* Returns parsed representation of XML file.
154159
*
155160
* Parses XML if it wasn't done before. Caches parsed data.
161+
* @return array<string, array<string, string>>
156162
*/
157163
protected function getParsedTargetData(string $path): array
158164
{
@@ -164,6 +170,7 @@ protected function getParsedTargetData(string $path): array
164170

165171
/**
166172
* Reads and parses XML file and returns internal representation of data.
173+
* @return array<string, array<string, string>>
167174
*/
168175
protected function parseXmlTargetFile(string $targetPath): array
169176
{

Classes/Service/ExtensionService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public function __construct(
2727
protected Converter $converter,
2828
) {}
2929

30+
/**
31+
* @return array<array<string, mixed>>
32+
*/
3033
public function getLocalExtensions(): array
3134
{
3235
$availableExtensions = $this->listUtility->getAvailableExtensions();
@@ -52,6 +55,7 @@ function (array $extension) {
5255

5356
/**
5457
* Gather files for given extension key that need to be converted
58+
* @return array<string, array<string, string>>
5559
*/
5660
public function getFilesOfExtension(string $extensionKey): array
5761
{
@@ -82,6 +86,10 @@ protected function isLanguageFile(string $filePath): bool
8286
return str_contains($filePath, 'Resources/Private/Language/');
8387
}
8488

89+
/**
90+
* @param array<string, array<string, string>> $files
91+
* @return array<string, string|bool>
92+
*/
8593
public function convertLanguageFile(string $selectedExtension, string $selectedFile, array $files): array
8694
{
8795
$wasConvertedPreviously = false;

0 commit comments

Comments
 (0)