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

Exception clean up #1079

Merged
merged 5 commits into from
Jan 18, 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
95 changes: 84 additions & 11 deletions baseline.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.x-dev@">
<file src="src/Ast/Parser/NikicPhpParser/FileReferenceVisitor.php">
<RedundantConditionGivenDocblockType occurrences="2">
<code>isset($node-&gt;namespacedName)</code>
<code>isset($node-&gt;namespacedName)</code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Ast/Parser/NikicPhpParser/NikicPhpParser.php">
<RedundantConditionGivenDocblockType occurrences="1">
<code>isset($classLikeNode-&gt;namespacedName)</code>
</RedundantConditionGivenDocblockType>
<files psalm-version="4.30.0@d0bc6e25d89f649e4f36a534f330f8bb4643dd69">
<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: 4 additions & 0 deletions deptrac.baseline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ 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
3 changes: 0 additions & 3 deletions deptrac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ services:
- class: Internal\Qossmic\Deptrac\IgnoreDependenciesOnContract
tags:
- { name: kernel.event_listener, event: Qossmic\Deptrac\Contract\Analyser\ProcessEvent }
- class: Internal\Qossmic\Deptrac\IgnoreDependenciesOnShouldNotHappenException
tags:
- { name: kernel.event_listener, event: Qossmic\Deptrac\Contract\Analyser\ProcessEvent }

deptrac:
paths:
Expand Down
17 changes: 0 additions & 17 deletions internal/deptrac/IgnoreDependenciesOnShouldNotHappenException.php

This file was deleted.

20 changes: 20 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ parameters:
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
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ parameters:
- internal/stubs/Function_.php
- internal/stubs/ClassLike.php
- internal/stubs/Name.php
exceptions:
implicitThrows: false
check:
missingCheckedExceptionInThrows: true
tooWideThrowType: true
5 changes: 5 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<psalm
errorLevel="1"
resolveFromConfigFile="true"
checkForThrowsDocblock="true"
checkForThrowsInGlobalScope="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand All @@ -13,4 +15,7 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<RedundantIdentityWithTrue errorLevel="suppress"/> <!-- Causes trouble with `match(true)` -->
</issueHandlers>
</psalm>
3 changes: 3 additions & 0 deletions src/Contract/Layer/CollectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ interface CollectorInterface
{
/**
* @param array<string, bool|string|array<string, string>> $config
*
* @throws InvalidLayerDefinitionException
* @throws InvalidCollectorDefinitionException
*/
public function satisfy(array $config, TokenReferenceInterface $reference): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Qossmic\Deptrac\Core\Layer\Exception;
namespace Qossmic\Deptrac\Contract\Layer;

use Psr\Container\ContainerExceptionInterface;
use Qossmic\Deptrac\Contract\ExceptionInterface;
Expand All @@ -28,4 +28,21 @@ public static function unsupportedType(string $collectorType, array $supportedTy
$previous
);
}

public static function unsupportedClass(string $id, mixed $collector): self
{
$message = sprintf(
'Type "%s" is not valid collector (expected "%s", but is "%s").',
$id,
CollectorInterface::class,
get_debug_type($collector)
);

return new self($message);
}

public static function invalidCollectorConfiguration(string $message): self
{
return new self($message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Qossmic\Deptrac\Core\Layer\Exception;
namespace Qossmic\Deptrac\Contract\Layer;

use Qossmic\Deptrac\Contract\ExceptionInterface;
use RuntimeException;
Expand Down Expand Up @@ -30,4 +30,9 @@ public static function layerRequired(): self
{
return new self('Layer configuration is empty. You need to define at least 1 layer.');
}

public static function circularTokenReference(string $tokenName): self
{
return new self(sprintf('Circular dependency between layers detected. Token "%s" could not be resolved.', $tokenName));
}
}
16 changes: 16 additions & 0 deletions src/Contract/OutputFormatter/OutputException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Qossmic\Deptrac\Contract\OutputFormatter;

use Qossmic\Deptrac\Contract\ExceptionInterface;
use RuntimeException;

class OutputException extends RuntimeException implements ExceptionInterface
{
public static function withMessage(string $message): self
{
return new self($message);
}
}
2 changes: 2 additions & 0 deletions src/Contract/OutputFormatter/OutputFormatterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public static function getName(): string;

/**
* Renders the final result.
*
* @throws OutputException
*/
public function finish(
LegacyResult $result,
Expand Down
41 changes: 41 additions & 0 deletions src/Core/Analyser/AnalyserException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Qossmic\Deptrac\Core\Analyser;

use Qossmic\Deptrac\Contract\ExceptionInterface;
use Qossmic\Deptrac\Contract\Layer\InvalidCollectorDefinitionException;
use Qossmic\Deptrac\Contract\Layer\InvalidLayerDefinitionException;
use Qossmic\Deptrac\Core\Ast\AstException;
use Qossmic\Deptrac\Core\Dependency\InvalidEmitterConfigurationException;
use Qossmic\Deptrac\Core\Dependency\UnrecognizedTokenException;
use RuntimeException;

final class AnalyserException extends RuntimeException implements ExceptionInterface
{
public static function invalidEmitterConfiguration(InvalidEmitterConfigurationException $e): self
{
return new self('Invalid emitter configuration.', 0, $e);
}

public static function unrecognizedToken(UnrecognizedTokenException $e): self
{
return new self('Unrecognized token.', 0, $e);
}

public static function invalidLayerDefinition(InvalidLayerDefinitionException $e): self
{
return new self('Invalid layer definition.', 0, $e);
}

public static function invalidCollectorDefinition(InvalidCollectorDefinitionException $e): self
{
return new self('Invalid collector definition.', 0, $e);
}

public static function failedAstParsing(AstException $e): self
{
return new self('Failed Ast parsing.', 0, $e);
}
}
Loading