Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code hardening - solving baseline issues in SA tools #1103

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 0 additions & 84 deletions baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,88 +11,4 @@
<code>list&lt;RuleInterface&gt;</code>
</MixedReturnTypeCoercion>
</file>
<file src="src/Core/Ast/Parser/Cache/AstFileReferenceFileCache.php">
<MissingThrowsDocblock occurrences="3">
<code>has</code>
<code>normalizeFilepath</code>
<code>normalizeFilepath</code>
</MissingThrowsDocblock>
</file>
<file src="src/Core/Layer/Collector/GlobCollector.php">
<MissingThrowsDocblock occurrences="1">
<code>Path::makeRelative($normalizedPath, $this-&gt;basePath)</code>
</MissingThrowsDocblock>
</file>
<file src="src/Core/Layer/Collector/MethodCollector.php">
<MissingThrowsDocblock occurrences="1">
<code>getNodeForClassLikeReference</code>
</MissingThrowsDocblock>
</file>
<file src="src/Supportive/Console/Application.php">
<MissingThrowsDocblock occurrences="4"/>
</file>
<file src="src/Supportive/Console/Command/AnalyseCommand.php">
<MissingThrowsDocblock occurrences="13">
<code>addOption</code>
<code>addOption</code>
<code>addOption</code>
<code>addOption</code>
<code>addOption</code>
<code>addOption</code>
<code>getOption</code>
<code>getOption</code>
<code>getOption</code>
<code>getOption</code>
<code>getOption</code>
<code>getOption</code>
<code>parent::__construct()</code>
</MissingThrowsDocblock>
</file>
<file src="src/Supportive/Console/Command/DebugLayerCommand.php">
<MissingThrowsDocblock occurrences="3">
<code>addArgument</code>
<code>getArgument</code>
<code>parent::__construct()</code>
</MissingThrowsDocblock>
</file>
<file src="src/Supportive/Console/Command/DebugTokenCommand.php">
<MissingThrowsDocblock occurrences="5">
<code>addArgument</code>
<code>addArgument</code>
<code>getArgument</code>
<code>getArgument</code>
<code>parent::__construct()</code>
</MissingThrowsDocblock>
</file>
<file src="src/Supportive/Console/Command/DebugUnassignedCommand.php">
<MissingThrowsDocblock occurrences="1">
<code>parent::__construct()</code>
</MissingThrowsDocblock>
</file>
<file src="src/Supportive/Console/Command/InitCommand.php">
<MissingThrowsDocblock occurrences="3">
<code>getOption</code>
<code>parent::__construct()</code>
<code>setName</code>
</MissingThrowsDocblock>
</file>
<file src="src/Supportive/DependencyInjection/Configuration.php">
<MissingThrowsDocblock occurrences="2">
<code>end</code>
<code>thenInvalid</code>
</MissingThrowsDocblock>
</file>
<file src="src/Supportive/DependencyInjection/DeptracExtension.php">
<MissingThrowsDocblock occurrences="2">
<code>getParameter</code>
<code>getParameter</code>
</MissingThrowsDocblock>
</file>
<file src="src/Supportive/DependencyInjection/ServiceContainerBuilder.php">
<MissingThrowsDocblock occurrences="3">
<code>Path::makeAbsolute($cacheFile, $this-&gt;workingDirectory)</code>
<code>Path::makeAbsolute($cacheFile, $this-&gt;workingDirectory)</code>
<code>Path::makeAbsolute($configFile, $this-&gt;workingDirectory)</code>
</MissingThrowsDocblock>
</file>
</files>
4 changes: 0 additions & 4 deletions deptrac.baseline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ deptrac:
- Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType
Qossmic\Deptrac\Core\Analyser\UnassignedTokenAnalyser:
- Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType
Qossmic\Deptrac\Core\Ast\Parser\Cache\AstFileReferenceFileCache:
- Qossmic\Deptrac\Supportive\File\Exception\CouldNotReadFileException
Qossmic\Deptrac\Core\Ast\Parser\NikicPhpParser\NikicPhpParser:
- Qossmic\Deptrac\Supportive\File\Exception\CouldNotReadFileException
35 changes: 0 additions & 35 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,3 @@ parameters:
message: "#^Method Qossmic\\\\Deptrac\\\\Contract\\\\Result\\\\OutputResult\\:\\:allRules\\(\\) should return list\\<Qossmic\\\\Deptrac\\\\Contract\\\\Result\\\\RuleInterface\\> but returns array\\.$#"
count: 1
path: src/Contract/Result/OutputResult.php

-
message: "#^@readonly property Qossmic\\\\Deptrac\\\\Core\\\\Ast\\\\AstMap\\\\AstInherit\\:\\:\\$path is assigned outside of the constructor\\.$#"
count: 1
path: src/Core/Ast/AstMap/AstInherit.php

-
message: "#^Method Qossmic\\\\Deptrac\\\\Core\\\\Layer\\\\Collector\\\\MethodCollector\\:\\:satisfy\\(\\) throws checked exception Qossmic\\\\Deptrac\\\\Core\\\\Ast\\\\Parser\\\\CouldNotParseFileException but it's missing from the PHPDoc @throws tag\\.$#"
count: 1
path: src/Core/Layer/Collector/MethodCollector.php

-
message: "#^Method Qossmic\\\\Deptrac\\\\Supportive\\\\DependencyInjection\\\\Configuration\\:\\:appendEmitterTypes\\(\\) throws checked exception InvalidArgumentException but it's missing from the PHPDoc @throws tag\\.$#"
count: 1
path: src/Supportive/DependencyInjection/Configuration.php

-
message: "#^Method Qossmic\\\\Deptrac\\\\Supportive\\\\DependencyInjection\\\\Configuration\\:\\:appendEmitterTypes\\(\\) throws checked exception RuntimeException but it's missing from the PHPDoc @throws tag\\.$#"
count: 1
path: src/Supportive/DependencyInjection/Configuration.php

-
message: "#^Method Qossmic\\\\Deptrac\\\\Supportive\\\\DependencyInjection\\\\Configuration\\:\\:appendFormatters\\(\\) throws checked exception RuntimeException but it's missing from the PHPDoc @throws tag\\.$#"
count: 1
path: src/Supportive/DependencyInjection/Configuration.php

-
message: "#^Strict comparison using \\=\\=\\= between null and SplFileInfo will always evaluate to false\\.$#"
count: 1
path: src/Supportive/DependencyInjection/ServiceContainerBuilder.php

-
message: "#^Strict comparison using \\=\\=\\= between null and SplFileInfo will always evaluate to false\\.$#"
count: 1
path: src/Supportive/OutputFormatter/GraphVizOutputImageFormatter.php
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
</projectFiles>
<issueHandlers>
<RedundantIdentityWithTrue errorLevel="suppress"/> <!-- Causes trouble with `match(true)` -->
<MissingThrowsDocblock errorLevel="suppress"/> <!-- PHPStan does it better with @throws void -->
</issueHandlers>
</psalm>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Qossmic\Deptrac\Core\Ast\Parser;
namespace Qossmic\Deptrac\Contract\Ast;

use Qossmic\Deptrac\Contract\ExceptionInterface;
use RuntimeException;
Expand Down
2 changes: 2 additions & 0 deletions src/Contract/Layer/CollectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Qossmic\Deptrac\Contract\Layer;

use Qossmic\Deptrac\Contract\Ast\CouldNotParseFileException;
use Qossmic\Deptrac\Contract\Ast\TokenReferenceInterface;

/**
Expand All @@ -16,6 +17,7 @@ interface CollectorInterface
*
* @throws InvalidLayerDefinitionException
* @throws InvalidCollectorDefinitionException
* @throws CouldNotParseFileException
*/
public function satisfy(array $config, TokenReferenceInterface $reference): bool;
}
6 changes: 6 additions & 0 deletions src/Core/Analyser/AnalyserException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Qossmic\Deptrac\Core\Analyser;

use Qossmic\Deptrac\Contract\Ast\CouldNotParseFileException;
use Qossmic\Deptrac\Contract\ExceptionInterface;
use Qossmic\Deptrac\Contract\Layer\InvalidCollectorDefinitionException;
use Qossmic\Deptrac\Contract\Layer\InvalidLayerDefinitionException;
Expand Down Expand Up @@ -38,4 +39,9 @@ public static function failedAstParsing(AstException $e): self
{
return new self('Failed Ast parsing.', 0, $e);
}

public static function couldNotParseFile(CouldNotParseFileException $e): self
{
return new self('Could not parse file.', 0, $e);
}
}
3 changes: 3 additions & 0 deletions src/Core/Analyser/DependencyLayersAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Qossmic\Deptrac\Contract\Analyser\AnalysisResult;
use Qossmic\Deptrac\Contract\Analyser\PostProcessEvent;
use Qossmic\Deptrac\Contract\Analyser\ProcessEvent;
use Qossmic\Deptrac\Contract\Ast\CouldNotParseFileException;
use Qossmic\Deptrac\Contract\Layer\InvalidCollectorDefinitionException;
use Qossmic\Deptrac\Contract\Layer\InvalidLayerDefinitionException;
use Qossmic\Deptrac\Contract\Result\Warning;
Expand Down Expand Up @@ -85,6 +86,8 @@ public function analyse(): AnalysisResult
throw AnalyserException::invalidCollectorDefinition($e);
} catch (AstException $e) {
throw AnalyserException::failedAstParsing($e);
} catch (CouldNotParseFileException $e) {
throw AnalyserException::couldNotParseFile($e);
}
}
}
4 changes: 4 additions & 0 deletions src/Core/Analyser/LayerForTokenAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Qossmic\Deptrac\Core\Analyser;

use Qossmic\Deptrac\Contract\Ast\CouldNotParseFileException;
use Qossmic\Deptrac\Contract\Ast\TokenReferenceInterface;
use Qossmic\Deptrac\Contract\Layer\InvalidCollectorDefinitionException;
use Qossmic\Deptrac\Contract\Layer\InvalidLayerDefinitionException;
Expand Down Expand Up @@ -59,6 +60,8 @@ public function findLayerForToken(string $tokenName, TokenType $tokenType): arra
throw AnalyserException::invalidCollectorDefinition($e);
} catch (AstException $e) {
throw AnalyserException::failedAstParsing($e);
} catch (CouldNotParseFileException $e) {
throw AnalyserException::couldNotParseFile($e);
}
}

Expand All @@ -70,6 +73,7 @@ public function findLayerForToken(string $tokenName, TokenType $tokenType): arra
* @throws \Qossmic\Deptrac\Core\Dependency\UnrecognizedTokenException
* @throws \Qossmic\Deptrac\Contract\Layer\InvalidLayerDefinitionException
* @throws \Qossmic\Deptrac\Contract\Layer\InvalidCollectorDefinitionException
* @throws \Qossmic\Deptrac\Contract\Ast\CouldNotParseFileException
*/
private function findLayersForReferences(array $references, string $tokenName, AstMap $astMap): array
{
Expand Down
3 changes: 3 additions & 0 deletions src/Core/Analyser/TokenInLayerAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Qossmic\Deptrac\Core\Analyser;

use Qossmic\Deptrac\Contract\Ast\CouldNotParseFileException;
use Qossmic\Deptrac\Contract\Layer\InvalidCollectorDefinitionException;
use Qossmic\Deptrac\Contract\Layer\InvalidLayerDefinitionException;
use Qossmic\Deptrac\Core\Ast\AstException;
Expand Down Expand Up @@ -94,6 +95,8 @@ public function findTokensInLayer(string $layer): array
throw AnalyserException::invalidCollectorDefinition($e);
} catch (AstException $e) {
throw AnalyserException::failedAstParsing($e);
} catch (CouldNotParseFileException $e) {
throw AnalyserException::couldNotParseFile($e);
}
}
}
3 changes: 3 additions & 0 deletions src/Core/Analyser/UnassignedTokenAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Qossmic\Deptrac\Core\Analyser;

use Qossmic\Deptrac\Contract\Ast\CouldNotParseFileException;
use Qossmic\Deptrac\Contract\Layer\InvalidCollectorDefinitionException;
use Qossmic\Deptrac\Contract\Layer\InvalidLayerDefinitionException;
use Qossmic\Deptrac\Core\Ast\AstException;
Expand Down Expand Up @@ -89,6 +90,8 @@ public function findUnassignedTokens(): array
throw AnalyserException::invalidCollectorDefinition($e);
} catch (AstException $e) {
throw AnalyserException::failedAstParsing($e);
} catch (CouldNotParseFileException $e) {
throw AnalyserException::couldNotParseFile($e);
}
}
}
2 changes: 1 addition & 1 deletion src/Core/Ast/AstLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use Psr\EventDispatcher\EventDispatcherInterface;
use Qossmic\Deptrac\Contract\Ast\AstFileAnalysedEvent;
use Qossmic\Deptrac\Contract\Ast\AstFileSyntaxErrorEvent;
use Qossmic\Deptrac\Contract\Ast\CouldNotParseFileException;
use Qossmic\Deptrac\Contract\Ast\PostCreateAstMapEvent;
use Qossmic\Deptrac\Contract\Ast\PreCreateAstMapEvent;
use Qossmic\Deptrac\Core\Ast\AstMap\AstMap;
use Qossmic\Deptrac\Core\Ast\Parser\CouldNotParseFileException;
use Qossmic\Deptrac\Core\Ast\Parser\ParserInterface;

class AstLoader
Expand Down
16 changes: 8 additions & 8 deletions src/Core/Ast/AstMap/AstInherit.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ class AstInherit implements Stringable
*/
private array $path;

/**
* @param AstInherit[] $path
*/
public function __construct(
public readonly ClassLikeToken $classLikeName,
public readonly FileOccurrence $fileOccurrence,
public readonly AstInheritType $type
public readonly AstInheritType $type,
array $path = []
) {
$this->path = [];
$this->path = $path;
}

/**
Expand All @@ -52,12 +56,8 @@ public function __toString(): string
/**
* @param AstInherit[] $path
*/
public function withPath(array $path): self
public function replacePath(array $path): self
{
$self = clone $this;

$self->path = $path;

return $self;
return new self($this->classLikeName, $this->fileOccurrence, $this->type, $path);
patrickkusebauch marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 1 addition & 1 deletion src/Core/Ast/AstMap/AstMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private function recursivelyResolveDependencies(

/** @var AstInherit[] $path */
$path = iterator_to_array($pathStack);
yield $inherit->withPath($path);
yield $inherit->replacePath($path);

$pathStack->push($inherit);

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Ast/Parser/NikicPhpParser/NikicPhpParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
use PhpParser\NodeVisitor\FindingVisitor;
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\Parser;
use Qossmic\Deptrac\Contract\Ast\CouldNotParseFileException;
use Qossmic\Deptrac\Core\Ast\AstMap\ClassLike\ClassLikeReference;
use Qossmic\Deptrac\Core\Ast\AstMap\File\FileReference;
use Qossmic\Deptrac\Core\Ast\AstMap\File\FileReferenceBuilder;
use Qossmic\Deptrac\Core\Ast\Parser\Cache\AstFileReferenceCacheInterface;
use Qossmic\Deptrac\Core\Ast\Parser\CouldNotParseFileException;
use Qossmic\Deptrac\Core\Ast\Parser\Extractors\ReferenceExtractorInterface;
use Qossmic\Deptrac\Core\Ast\Parser\ParserInterface;
use Qossmic\Deptrac\Core\Ast\Parser\TypeResolver;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Ast/Parser/ParserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Qossmic\Deptrac\Core\Ast\Parser;

use Qossmic\Deptrac\Contract\Ast\CouldNotParseFileException;
use Qossmic\Deptrac\Core\Ast\AstMap\File\FileReference;

interface ParserInterface
Expand Down
3 changes: 3 additions & 0 deletions src/Core/Layer/LayerResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Qossmic\Deptrac\Core\Layer;

use Qossmic\Deptrac\Contract\Ast\CouldNotParseFileException;
use Qossmic\Deptrac\Contract\Ast\TokenReferenceInterface;
use Qossmic\Deptrac\Contract\Layer\InvalidCollectorDefinitionException;
use Qossmic\Deptrac\Contract\Layer\InvalidLayerDefinitionException;
Expand All @@ -15,12 +16,14 @@ interface LayerResolverInterface
*
* @throws InvalidLayerDefinitionException
* @throws InvalidCollectorDefinitionException
* @throws CouldNotParseFileException
*/
public function getLayersForReference(TokenReferenceInterface $reference): array;

/**
* @throws InvalidLayerDefinitionException
* @throws InvalidCollectorDefinitionException
* @throws CouldNotParseFileException
*/
public function isReferenceInLayer(string $layer, TokenReferenceInterface $reference): bool;

Expand Down
Loading