Skip to content

Commit 207849f

Browse files
author
Konrad Michalik
authored
Merge pull request #35 from move-elevator/phpstan-7
build: update phpstan level to 7
2 parents d26b001 + 337d271 commit 207849f

33 files changed

Lines changed: 555 additions & 67 deletions

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
],
1313
"require": {
1414
"php": "^8.1",
15+
"ext-libxml": "*",
1516
"ext-mbstring": "*",
1617
"ext-simplexml": "*",
1718
"composer-plugin-api": "^1.0 || ^2.0",

composer.lock

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan-baseline.neon

Lines changed: 0 additions & 2 deletions
This file was deleted.

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 6
2+
level: 7
33
paths:
44
- src
55
- tests/src

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
44
displayDetailsOnTestsThatTriggerWarnings="true"
5+
displayDetailsOnTestsThatTriggerNotices="true"
56
bootstrap="vendor/autoload.php"
67
colors="true"
78
>

src/Command/ValidateTranslationCommand.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,14 @@ private function resolveValidators(
271271
$only = !empty($inputOnly) ? $inputOnly : $config->getOnly();
272272
$skip = !empty($inputSkip) ? $inputSkip : $config->getSkip();
273273

274-
return match (true) {
274+
/** @var array<int, class-string<ValidatorInterface>> $result */
275+
$result = match (true) {
275276
!empty($only) => $only,
276-
!empty($skip) => array_diff(ValidatorRegistry::getAvailableValidators(), $skip),
277+
!empty($skip) => array_values(array_diff(ValidatorRegistry::getAvailableValidators(), $skip)),
277278
default => ValidatorRegistry::getAvailableValidators(),
278279
};
280+
281+
return $result;
279282
}
280283

281284
/**
@@ -291,6 +294,7 @@ private function validateClassInput(
291294
}
292295

293296
$classNames = str_contains($className, ',') ? explode(',', $className) : [$className];
297+
/** @var array<int, class-string> $classes */
294298
$classes = [];
295299

296300
foreach ($classNames as $name) {
@@ -300,7 +304,9 @@ private function validateClassInput(
300304
$type,
301305
$name
302306
);
303-
$classes[] = $name;
307+
/** @var class-string $validatedName */
308+
$validatedName = $name;
309+
$classes[] = $validatedName;
304310
}
305311

306312
return $classes;

src/Config/ConfigReader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ public function readFromComposerJson(string $composerJsonPath): ?TranslationVali
5353
return null;
5454
}
5555

56-
$composerData = json_decode(file_get_contents($composerJsonPath), true, 512, JSON_THROW_ON_ERROR);
56+
$content = file_get_contents($composerJsonPath);
57+
if (false === $content) {
58+
return null;
59+
}
60+
61+
$composerData = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
5762
if (!is_array($composerData)) {
5863
return null;
5964
}

src/Config/SchemaValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function validate(array $data): void
4040
*/
4141
private function loadSchema(): object
4242
{
43-
if (!file_exists(self::SCHEMA_PATH)) {
43+
if (!file_exists(self::SCHEMA_PATH) || !is_readable(self::SCHEMA_PATH) || !is_file(self::SCHEMA_PATH)) {
4444
throw new \RuntimeException('JSON Schema file not found: '.self::SCHEMA_PATH);
4545
}
4646

src/FileDetector/Collector.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ public function collectFiles(
3535
}
3636

3737
foreach (ParserRegistry::getAvailableParsers() as $parserClass) {
38+
$globFiles = glob($path.'/*');
39+
if (false === $globFiles) {
40+
continue;
41+
}
42+
3843
$files = array_filter(
39-
glob($path.'/*'),
44+
$globFiles,
4045
static fn ($file) => in_array(
4146
pathinfo($file, PATHINFO_EXTENSION),
4247
$parserClass::getSupportedFileExtensions(),

src/Parser/ParserCache.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ParserCache
99
/** @var array<string, ParserInterface> */
1010
private static array $cache = [];
1111

12-
public static function get(string $filePath, ?string $parserClass): ParserInterface|bool
12+
public static function get(string $filePath, ?string $parserClass): ParserInterface|false
1313
{
1414
if (null === $parserClass) {
1515
return false;
@@ -18,7 +18,9 @@ public static function get(string $filePath, ?string $parserClass): ParserInterf
1818
$cacheKey = $filePath.'::'.$parserClass;
1919

2020
if (!isset(self::$cache[$cacheKey])) {
21-
self::$cache[$cacheKey] = new $parserClass($filePath);
21+
/** @var ParserInterface $parser */
22+
$parser = new $parserClass($filePath);
23+
self::$cache[$cacheKey] = $parser;
2224
}
2325

2426
return self::$cache[$cacheKey];

0 commit comments

Comments
 (0)