Skip to content

Commit

Permalink
Make static analysers happier.
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkusebauch committed Mar 10, 2024
1 parent a38c029 commit 263016e
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 71 deletions.
37 changes: 25 additions & 12 deletions baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.20.0@3f284e96c9d9be6fe6b15c79416e1d1903dcfef4">
<files psalm-version="5.23.0@005e3184fb6de4350a873b9b8c4dc3cede9db762">
<file src="src/Contract/Result/OutputResult.php">
<InvalidReturnStatement>
<code><![CDATA[array_key_exists($type, $this->rules) ? array_values($this->rules[$type]) : []]]></code>
Expand All @@ -10,19 +10,32 @@
</file>
<file src="src/Core/Ast/AstMap/ClassLike/ClassLikeToken.php">
<ArgumentTypeCoercion>
<code>$pattern</code>
<code><![CDATA[$pattern]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Core/Ast/AstMap/Function/FunctionToken.php">
<ArgumentTypeCoercion>
<code>$pattern</code>
<code><![CDATA[$pattern]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Core/Ast/Parser/TypeScope.php">
<file src="src/Core/Ast/Parser/Extractors/ClassMethodExtractor.php">
<RedundantCondition>
<code><![CDATA[$resolvedPhpDoc->getThrowsTag()?->getType()->getReferencedClasses()]]></code>
</RedundantCondition>
<TypeDoesNotContainNull>
<code><![CDATA[[]]]></code>
</TypeDoesNotContainNull>
</file>
<file src="src/Core/Ast/Parser/NikicPhpParser/TypeScope.php">
<RiskyTruthyFalsyComparison>
<code>$alias</code>
<code><![CDATA[$alias]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Core/Ast/Parser/PhpStanParser/PhpStanTypeResolver.php">
<NamedArgumentNotAllowed>
<code><![CDATA[array_map(static fn ($type): array => self::resolveType($type, $scope), $type->types)]]></code>
</NamedArgumentNotAllowed>
</file>
<file src="src/Core/Layer/Collector/BoolCollector.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[!$configuration['must']]]></code>
Expand All @@ -31,7 +44,7 @@
</file>
<file src="src/Core/Layer/Collector/ComposerFilesParser.php">
<InvalidReturnStatement>
<code>$lockedPackages</code>
<code><![CDATA[$lockedPackages]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[array<string, array{
Expand All @@ -42,32 +55,32 @@
</file>
<file src="src/Core/Layer/Collector/DirectoryCollector.php">
<ArgumentTypeCoercion>
<code>$validatedPattern</code>
<code><![CDATA[$validatedPattern]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Core/Layer/Collector/GlobCollector.php">
<ArgumentTypeCoercion>
<code>$validatedPattern</code>
<code><![CDATA[$validatedPattern]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Core/Layer/Collector/MethodCollector.php">
<ArgumentTypeCoercion>
<code>$pattern</code>
<code><![CDATA[$pattern]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Core/Layer/Collector/RegexCollector.php">
<ArgumentTypeCoercion>
<code>$pattern</code>
<code><![CDATA[$pattern]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Core/Layer/Collector/TagValueRegexCollector.php">
<ArgumentTypeCoercion>
<code>$pattern</code>
<code><![CDATA[$pattern]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Supportive/Console/Command/DebugLayerRunner.php">
<RiskyTruthyFalsyComparison>
<code>$layer</code>
<code><![CDATA[$layer]]></code>
</RiskyTruthyFalsyComparison>
</file>
</files>
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,6 @@ parameters:
count: 1
path: src/Contract/Result/OutputResult.php

-
message: "#^Parameter \\#1 \\$array \\(list\\<string\\>\\) of array_values is already a list, call has no effect\\.$#"
count: 1
path: src/Core/Analyser/LayerForTokenAnalyser.php

-
message: "#^Parameter \\#1 \\$array \\(list\\<string\\>\\) of array_values is already a list, call has no effect\\.$#"
count: 1
path: src/Core/Analyser/TokenInLayerAnalyser.php

-
message: "#^Parameter \\#1 \\$array \\(list\\<string\\>\\) of array_values is already a list, call has no effect\\.$#"
count: 1
path: src/Core/Analyser/UnassignedTokenAnalyser.php

-
message: "#^Method Qossmic\\\\Deptrac\\\\Core\\\\Ast\\\\AstMap\\\\ReferenceBuilder\\:\\:superglobal\\(\\) throws checked exception TypeError but it's missing from the PHPDoc @throws tag\\.$#"
count: 1
Expand Down
8 changes: 3 additions & 5 deletions src/Core/Ast/Parser/Extractors/PropertyExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,9 @@ public function processNodeWithPhpStanScope(Node $node, ReferenceBuilder $refere
$function = $scope->getFunction();
$resolvedPhpDoc = $fileTypeMapper->getResolvedPhpDoc(
$scope->getFile(),
$scope->isInClass() ? $scope->getClassReflection()
->getName() : null,
$scope->isInTrait() ? $scope->getTraitReflection()
->getName() : null,
null !== $function ? $function->getName() : null,
$scope->getClassReflection()?->getName(),
$scope->getTraitReflection()?->getName(),
$function?->getName(),
$docComment->getText(),
);

Expand Down
8 changes: 3 additions & 5 deletions src/Core/Ast/Parser/Extractors/VariableExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ public function processNodeWithPhpStanScope(Node $node, ReferenceBuilder $refere
$function = $scope->getFunction();
$resolvedPhpDoc = $fileTypeMapper->getResolvedPhpDoc(
$scope->getFile(),
$scope->isInClass() ? $scope->getClassReflection()
->getName() : null,
$scope->isInTrait() ? $scope->getTraitReflection()
->getName() : null,
null !== $function ? $function->getName() : null,
$scope->getClassReflection()?->getName(),
$scope->getTraitReflection()?->getName(),
$function?->getName(),
$docComment->getText(),
);

Expand Down
13 changes: 4 additions & 9 deletions tests/Core/Ast/AstMapFlattenGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@
use Qossmic\Deptrac\Core\Ast\AstMap\ClassLike\ClassLikeToken;
use Qossmic\Deptrac\Core\Ast\Parser\Cache\AstFileReferenceInMemoryCache;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\ClassExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\ClassMethodExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\InterfaceExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\NewExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\PropertyExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\VariableExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\NikicPhpParser\NikicPhpParser;
use Qossmic\Deptrac\Core\Ast\Parser\NikicPhpParser\NikicTypeResolver;
use Qossmic\Deptrac\Core\Ast\Parser\ParserInterface;
use Qossmic\Deptrac\Core\Ast\Parser\PhpStanParser\PhpStanContainerDecorator;
use Qossmic\Deptrac\Core\Ast\Parser\PhpStanParser\PhpStanParser;
Expand Down Expand Up @@ -76,16 +71,16 @@ protected function setUp(): void
public static function createParser(): array
{
$phpStanContainer = new PhpStanContainerDecorator('', []);
$extractors = [
$extractors = [
new ClassExtractor(),
new InterfaceExtractor(),
];
$cache = new AstFileReferenceInMemoryCache();
$parser = new NikicPhpParser(
$cache = new AstFileReferenceInMemoryCache();
$parser = new NikicPhpParser(
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()), $cache, $extractors
);

$phpstanParser = new PhpStanParser($phpStanContainer, $cache, $extractors);
$phpstanParser = new PhpStanParser($phpStanContainer, $cache, $extractors);

return [
'Nikic Parser' => [$parser],
Expand Down
10 changes: 3 additions & 7 deletions tests/Core/Ast/AstMapGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\AnonymousClassExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\ClassConstantExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\ClassExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\ClassMethodExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\GroupUseExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\NewExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\PropertyExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\TraitUseExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\UseExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\VariableExtractor;
use Qossmic\Deptrac\Core\Ast\Parser\NikicPhpParser\NikicPhpParser;
use Qossmic\Deptrac\Core\Ast\Parser\NikicPhpParser\NikicTypeResolver;
use Qossmic\Deptrac\Core\Ast\Parser\ParserInterface;
use Qossmic\Deptrac\Core\Ast\Parser\PhpStanParser\PhpStanContainerDecorator;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Tests\Qossmic\Deptrac\Core\Ast\Fixtures\BasicDependency\BasicDependencyClassB;
use Tests\Qossmic\Deptrac\Core\Ast\Fixtures\BasicDependency\BasicDependencyClassC;
Expand Down Expand Up @@ -56,8 +51,9 @@ public static function createParser(): array
new TraitUseExtractor($typeResolver),
]
);

return [
'Nikic Parser' => [$parser]
'Nikic Parser' => [$parser],
];
}

Expand Down Expand Up @@ -145,7 +141,7 @@ static function (DependencyToken $dependency) {

private function getAstMap(ParserInterface $parser, string $fixture): AstMap
{
$astRunner = new AstLoader(
$astRunner = new AstLoader(
$parser,
new EventDispatcher()
);
Expand Down
10 changes: 5 additions & 5 deletions tests/Core/Ast/Parser/AnnotationReferenceExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ public function testPropertyDependencyResolving(ParserInterface $parser): void
*/
public static function createParser(): array
{
$typeResolver = new NikicTypeResolver();
$typeResolver = new NikicTypeResolver();
$phpStanContainer = new PhpStanContainerDecorator('', []);
$cache = new AstFileReferenceInMemoryCache();
$extractors = [
$cache = new AstFileReferenceInMemoryCache();
$extractors = [
new PropertyExtractor($phpStanContainer, $typeResolver),
new VariableExtractor($phpStanContainer, $typeResolver),
new ClassMethodExtractor($phpStanContainer, $typeResolver),
new NewExtractor($typeResolver),
];
$nikicPhpParser = new NikicPhpParser(
$nikicPhpParser = new NikicPhpParser(
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()), $cache, $extractors
);

$phpstanParser = new PhpStanParser($phpStanContainer, $cache, $extractors);

return [
Expand Down
5 changes: 2 additions & 3 deletions tests/Core/Ast/Parser/AnonymousClassExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ final class AnonymousClassExtractorTest extends TestCase
public static function createParser(): array
{
$phpStanContainer = new PhpStanContainerDecorator('', []);
$cache = new AstFileReferenceInMemoryCache();
$cache = new AstFileReferenceInMemoryCache();
$extractors = [
new AnonymousClassExtractor(),
];
$nikicPhpParser = new NikicPhpParser(
$nikicPhpParser = new NikicPhpParser(
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()), $cache, $extractors
);
$phpstanParser = new PhpStanParser($phpStanContainer, $cache, $extractors);


return [
'Nikic Parser' => [$nikicPhpParser],
'PHPStan Parser' => [$phpstanParser],
Expand Down
8 changes: 4 additions & 4 deletions tests/Core/Ast/Parser/ClassConstantExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public function testPropertyDependencyResolving(ParserInterface $parser): void
public static function createParser(): array
{
$phpStanContainer = new PhpStanContainerDecorator('', []);
$extractors = [
$extractors = [
new ClassConstantExtractor(),
];
$cache = new AstFileReferenceInMemoryCache();
$parser = new NikicPhpParser(
$cache = new AstFileReferenceInMemoryCache();
$parser = new NikicPhpParser(
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()), $cache, $extractors
);
$phpstanParser = new PhpStanParser($phpStanContainer, $cache, $extractors);
$phpstanParser = new PhpStanParser($phpStanContainer, $cache, $extractors);

return [
'Nikic Parser' => [$parser],
Expand Down
6 changes: 3 additions & 3 deletions tests/Core/Ast/Parser/ClassDocBlockExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public static function createParser(): array
{
$typeResolver = new NikicTypeResolver();
$phpStanContainer = new PhpStanContainerDecorator('', []);
$extractors = [
$extractors = [
new ClassLikeExtractor($typeResolver),
];
$cache = new AstFileReferenceInMemoryCache();
$parser = new NikicPhpParser(
$cache = new AstFileReferenceInMemoryCache();
$parser = new NikicPhpParser(
(new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer()), $cache, $extractors
);
$phpstanParser = new PhpStanParser($phpStanContainer, $cache, $extractors);
Expand Down
6 changes: 3 additions & 3 deletions tests/Core/Ast/Parser/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ public static function createParser(): array
$typeResolver = new NikicTypeResolver();
$phpStanContainer = new PhpStanContainerDecorator('', []);

$cache = new AstFileReferenceInMemoryCache();
$extractors = [
$cache = new AstFileReferenceInMemoryCache();
$extractors = [
new UseExtractor(),
new ClassLikeExtractor($typeResolver),
];
$nikicPhpParser = new NikicPhpParser(
(new ParserFactory())->create(
(new ParserFactory())->create(
ParserFactory::ONLY_PHP7,
new Lexer()
), $cache, $extractors
Expand Down

0 comments on commit 263016e

Please sign in to comment.