From bfb213dead3dbe013acb2c3cd232324c70060619 Mon Sep 17 00:00:00 2001 From: patrickkusebauch Date: Wed, 7 Feb 2024 19:06:08 +0100 Subject: [PATCH] Refactor DependencyInterface to use DependencyContext instead of FileOccurence and DependencyType, so that we do not add a new method to the interface and constructor parameters every time we want to add a piece of information about the dependency. Created to enable https://github.com/qossmic/deptrac/pull/1359 --- src/Contract/Ast/DependencyContext.php | 20 +++++++ .../Dependency/DependencyInterface.php | 7 +-- src/Core/Ast/AstMap/DependencyToken.php | 6 +-- .../Ast/AstMap/File/FileReferenceBuilder.php | 4 +- src/Core/Ast/AstMap/ReferenceBuilder.php | 54 ++++++++----------- src/Core/Dependency/Dependency.php | 17 ++---- .../Emitter/ClassDependencyEmitter.php | 11 ++-- .../ClassSuperglobalDependencyEmitter.php | 5 +- .../Emitter/FileDependencyEmitter.php | 7 ++- .../Emitter/FunctionCallDependencyEmitter.php | 4 +- .../Emitter/FunctionDependencyEmitter.php | 7 ++- .../FunctionSuperglobalDependencyEmitter.php | 5 +- .../Emitter/UsesDependencyEmitter.php | 5 +- src/Core/Dependency/InheritDependency.php | 14 ++--- .../Layer/Collector/AttributeCollector.php | 2 +- .../Command/DebugDependenciesRunner.php | 2 +- .../CodeclimateOutputFormatter.php | 8 +-- .../ConsoleOutputFormatter.php | 4 +- .../GithubActionsOutputFormatter.php | 8 +-- .../OutputFormatter/JUnitOutputFormatter.php | 4 +- .../OutputFormatter/JsonOutputFormatter.php | 12 ++--- .../OutputFormatter/TableOutputFormatter.php | 6 +-- .../OutputFormatter/XMLOutputFormatter.php | 2 +- .../DependsOnInternalTokenTest.php | 5 +- .../AnnotationReferenceExtractorTest.php | 36 ++++++------- .../Parser/AnonymousClassExtractorTest.php | 12 ++--- .../Ast/Parser/ClassConstantExtractorTest.php | 6 +-- .../Ast/Parser/ClassDocBlockExtractorTest.php | 2 +- tests/Core/Dependency/DependencyListTest.php | 13 +++-- tests/Core/Dependency/DependencyTest.php | 9 ++-- .../Core/Dependency/Emitter/EmitterTrait.php | 2 +- .../Core/Dependency/InheritDependencyTest.php | 6 ++- .../BaselineOutputFormatterTest.php | 9 ++-- .../CodeclimateOutputFormatterTest.php | 23 ++++---- .../ConsoleOutputFormatterTest.php | 11 ++-- .../GithubActionsOutputFormatterTest.php | 13 ++--- .../GraphVizDotOutputFormatterTest.php | 15 +++--- .../JUnitOutputFormatterTest.php | 9 ++-- .../JsonOutputFormatterTest.php | 23 ++++---- .../TableOutputFormatterTest.php | 13 ++--- .../XMLOutputFormatterTest.php | 9 ++-- 41 files changed, 216 insertions(+), 214 deletions(-) create mode 100644 src/Contract/Ast/DependencyContext.php diff --git a/src/Contract/Ast/DependencyContext.php b/src/Contract/Ast/DependencyContext.php new file mode 100644 index 000000000..db9dda326 --- /dev/null +++ b/src/Contract/Ast/DependencyContext.php @@ -0,0 +1,20 @@ + */ public function serialize(): array; - - public function getType(): DependencyType; } diff --git a/src/Core/Ast/AstMap/DependencyToken.php b/src/Core/Ast/AstMap/DependencyToken.php index c98447e5d..0ed1d41af 100644 --- a/src/Core/Ast/AstMap/DependencyToken.php +++ b/src/Core/Ast/AstMap/DependencyToken.php @@ -4,8 +4,7 @@ namespace Qossmic\Deptrac\Core\Ast\AstMap; -use Qossmic\Deptrac\Contract\Ast\DependencyType; -use Qossmic\Deptrac\Contract\Ast\FileOccurrence; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\TokenInterface; /** @@ -15,7 +14,6 @@ class DependencyToken { public function __construct( public readonly TokenInterface $token, - public readonly FileOccurrence $fileOccurrence, - public readonly DependencyType $type + public readonly DependencyContext $context, ) {} } diff --git a/src/Core/Ast/AstMap/File/FileReferenceBuilder.php b/src/Core/Ast/AstMap/File/FileReferenceBuilder.php index e433b8272..435a8b926 100644 --- a/src/Core/Ast/AstMap/File/FileReferenceBuilder.php +++ b/src/Core/Ast/AstMap/File/FileReferenceBuilder.php @@ -5,7 +5,6 @@ namespace Qossmic\Deptrac\Core\Ast\AstMap\File; use Qossmic\Deptrac\Contract\Ast\DependencyType; -use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Core\Ast\AstMap\ClassLike\ClassLikeReferenceBuilder; use Qossmic\Deptrac\Core\Ast\AstMap\ClassLike\ClassLikeToken; use Qossmic\Deptrac\Core\Ast\AstMap\DependencyToken; @@ -29,8 +28,7 @@ public function useStatement(string $classLikeName, int $occursAtLine): self { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::USE + $this->createContext($occursAtLine, DependencyType::USE), ); return $this; diff --git a/src/Core/Ast/AstMap/ReferenceBuilder.php b/src/Core/Ast/AstMap/ReferenceBuilder.php index 4ff20047e..49998cc3b 100644 --- a/src/Core/Ast/AstMap/ReferenceBuilder.php +++ b/src/Core/Ast/AstMap/ReferenceBuilder.php @@ -4,6 +4,7 @@ namespace Qossmic\Deptrac\Core\Ast\AstMap; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Core\Ast\AstMap\ClassLike\ClassLikeToken; @@ -28,6 +29,11 @@ final public function getTokenTemplates(): array return $this->tokenTemplates; } + protected function createContext(int $occursAtLine, DependencyType $type): DependencyContext + { + return new DependencyContext(new FileOccurrence($this->filepath, $occursAtLine), $type); + } + /** * Unqualified function and constant names inside a namespace cannot be * statically resolved. Inside a namespace Foo, a call to strlen() may @@ -39,8 +45,7 @@ public function unresolvedFunctionCall(string $functionName, int $occursAtLine): { $this->dependencies[] = new DependencyToken( FunctionToken::fromFQCN($functionName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::UNRESOLVED_FUNCTION_CALL + $this->createContext($occursAtLine, DependencyType::UNRESOLVED_FUNCTION_CALL), ); return $this; @@ -50,8 +55,7 @@ public function variable(string $classLikeName, int $occursAtLine): self { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::VARIABLE + $this->createContext($occursAtLine, DependencyType::VARIABLE), ); return $this; @@ -61,8 +65,7 @@ public function superglobal(string $superglobalName, int $occursAtLine): void { $this->dependencies[] = new DependencyToken( SuperGlobalToken::from($superglobalName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::SUPERGLOBAL_VARIABLE + $this->createContext($occursAtLine, DependencyType::SUPERGLOBAL_VARIABLE), ); } @@ -70,8 +73,7 @@ public function returnType(string $classLikeName, int $occursAtLine): self { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::RETURN_TYPE + $this->createContext($occursAtLine, DependencyType::RETURN_TYPE), ); return $this; @@ -81,8 +83,7 @@ public function throwStatement(string $classLikeName, int $occursAtLine): self { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::THROW + $this->createContext($occursAtLine, DependencyType::THROW), ); return $this; @@ -92,8 +93,7 @@ public function anonymousClassExtends(string $classLikeName, int $occursAtLine): { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::ANONYMOUS_CLASS_EXTENDS + $this->createContext($occursAtLine, DependencyType::ANONYMOUS_CLASS_EXTENDS), ); } @@ -101,8 +101,7 @@ public function anonymousClassTrait(string $classLikeName, int $occursAtLine): v { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::ANONYMOUS_CLASS_TRAIT + $this->createContext($occursAtLine, DependencyType::ANONYMOUS_CLASS_TRAIT), ); } @@ -110,8 +109,7 @@ public function constFetch(string $classLikeName, int $occursAtLine): void { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::CONST + $this->createContext($occursAtLine, DependencyType::CONST), ); } @@ -119,8 +117,7 @@ public function anonymousClassImplements(string $classLikeName, int $occursAtLin { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::ANONYMOUS_CLASS_IMPLEMENTS + $this->createContext($occursAtLine, DependencyType::ANONYMOUS_CLASS_IMPLEMENTS), ); } @@ -128,8 +125,7 @@ public function parameter(string $classLikeName, int $occursAtLine): self { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::PARAMETER + $this->createContext($occursAtLine, DependencyType::PARAMETER), ); return $this; @@ -139,8 +135,7 @@ public function attribute(string $classLikeName, int $occursAtLine): self { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::ATTRIBUTE + $this->createContext($occursAtLine, DependencyType::ATTRIBUTE), ); return $this; @@ -150,8 +145,7 @@ public function instanceof(string $classLikeName, int $occursAtLine): self { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::INSTANCEOF + $this->createContext($occursAtLine, DependencyType::INSTANCEOF), ); return $this; @@ -161,8 +155,7 @@ public function newStatement(string $classLikeName, int $occursAtLine): self { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::NEW + $this->createContext($occursAtLine, DependencyType::NEW), ); return $this; @@ -172,8 +165,7 @@ public function staticProperty(string $classLikeName, int $occursAtLine): self { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::STATIC_PROPERTY + $this->createContext($occursAtLine, DependencyType::STATIC_PROPERTY), ); return $this; @@ -183,8 +175,7 @@ public function staticMethod(string $classLikeName, int $occursAtLine): self { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::STATIC_METHOD + $this->createContext($occursAtLine, DependencyType::STATIC_METHOD), ); return $this; @@ -194,8 +185,7 @@ public function catchStmt(string $classLikeName, int $occursAtLine): self { $this->dependencies[] = new DependencyToken( ClassLikeToken::fromFQCN($classLikeName), - new FileOccurrence($this->filepath, $occursAtLine), - DependencyType::CATCH + $this->createContext($occursAtLine, DependencyType::CATCH), ); return $this; diff --git a/src/Core/Dependency/Dependency.php b/src/Core/Dependency/Dependency.php index 4a8d551b4..cc77d36f8 100644 --- a/src/Core/Dependency/Dependency.php +++ b/src/Core/Dependency/Dependency.php @@ -4,8 +4,7 @@ namespace Qossmic\Deptrac\Core\Dependency; -use Qossmic\Deptrac\Contract\Ast\DependencyType; -use Qossmic\Deptrac\Contract\Ast\FileOccurrence; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\TokenInterface; use Qossmic\Deptrac\Contract\Dependency\DependencyInterface; @@ -14,15 +13,14 @@ class Dependency implements DependencyInterface public function __construct( private readonly TokenInterface $depender, private readonly TokenInterface $dependent, - private readonly FileOccurrence $fileOccurrence, - private readonly DependencyType $dependencyType + private readonly DependencyContext $context, ) {} public function serialize(): array { return [[ 'name' => $this->dependent->toString(), - 'line' => $this->fileOccurrence->line, + 'line' => $this->context->fileOccurrence->line, ]]; } @@ -36,13 +34,8 @@ public function getDependent(): TokenInterface return $this->dependent; } - public function getFileOccurrence(): FileOccurrence + public function getContext(): DependencyContext { - return $this->fileOccurrence; - } - - public function getType(): DependencyType - { - return $this->dependencyType; + return $this->context; } } diff --git a/src/Core/Dependency/Emitter/ClassDependencyEmitter.php b/src/Core/Dependency/Emitter/ClassDependencyEmitter.php index d7280d81d..f5014d4cb 100644 --- a/src/Core/Dependency/Emitter/ClassDependencyEmitter.php +++ b/src/Core/Dependency/Emitter/ClassDependencyEmitter.php @@ -4,6 +4,7 @@ namespace Qossmic\Deptrac\Core\Dependency\Emitter; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Core\Ast\AstMap\AstMap; use Qossmic\Deptrac\Core\Dependency\Dependency; @@ -22,10 +23,10 @@ public function applyDependencies(AstMap $astMap, DependencyList $dependencyList $classLikeName = $classReference->getToken(); foreach ($classReference->dependencies as $dependency) { - if (DependencyType::SUPERGLOBAL_VARIABLE === $dependency->type) { + if (DependencyType::SUPERGLOBAL_VARIABLE === $dependency->context->dependencyType) { continue; } - if (DependencyType::UNRESOLVED_FUNCTION_CALL === $dependency->type) { + if (DependencyType::UNRESOLVED_FUNCTION_CALL === $dependency->context->dependencyType) { continue; } @@ -33,8 +34,7 @@ public function applyDependencies(AstMap $astMap, DependencyList $dependencyList new Dependency( $classLikeName, $dependency->token, - $dependency->fileOccurrence, - $dependency->type + $dependency->context, ) ); } @@ -44,8 +44,7 @@ public function applyDependencies(AstMap $astMap, DependencyList $dependencyList new Dependency( $classLikeName, $inherit->classLikeName, - $inherit->fileOccurrence, - DependencyType::INHERIT + new DependencyContext($inherit->fileOccurrence, DependencyType::INHERIT), ) ); } diff --git a/src/Core/Dependency/Emitter/ClassSuperglobalDependencyEmitter.php b/src/Core/Dependency/Emitter/ClassSuperglobalDependencyEmitter.php index 43739eb27..709bc25f6 100644 --- a/src/Core/Dependency/Emitter/ClassSuperglobalDependencyEmitter.php +++ b/src/Core/Dependency/Emitter/ClassSuperglobalDependencyEmitter.php @@ -20,15 +20,14 @@ public function applyDependencies(AstMap $astMap, DependencyList $dependencyList { foreach ($astMap->getClassLikeReferences() as $classReference) { foreach ($classReference->dependencies as $dependency) { - if (DependencyType::SUPERGLOBAL_VARIABLE !== $dependency->type) { + if (DependencyType::SUPERGLOBAL_VARIABLE !== $dependency->context->dependencyType) { continue; } $dependencyList->addDependency( new Dependency( $classReference->getToken(), $dependency->token, - $dependency->fileOccurrence, - $dependency->type + $dependency->context, ) ); } diff --git a/src/Core/Dependency/Emitter/FileDependencyEmitter.php b/src/Core/Dependency/Emitter/FileDependencyEmitter.php index aa3f13fe5..461412aad 100644 --- a/src/Core/Dependency/Emitter/FileDependencyEmitter.php +++ b/src/Core/Dependency/Emitter/FileDependencyEmitter.php @@ -20,11 +20,11 @@ public function applyDependencies(AstMap $astMap, DependencyList $dependencyList { foreach ($astMap->getFileReferences() as $fileReference) { foreach ($fileReference->dependencies as $dependency) { - if (DependencyType::USE === $dependency->type) { + if (DependencyType::USE === $dependency->context->dependencyType) { continue; } - if (DependencyType::UNRESOLVED_FUNCTION_CALL === $dependency->type) { + if (DependencyType::UNRESOLVED_FUNCTION_CALL === $dependency->context->dependencyType) { continue; } @@ -32,8 +32,7 @@ public function applyDependencies(AstMap $astMap, DependencyList $dependencyList new Dependency( $fileReference->getToken(), $dependency->token, - $dependency->fileOccurrence, - $dependency->type + $dependency->context, ) ); } diff --git a/src/Core/Dependency/Emitter/FunctionCallDependencyEmitter.php b/src/Core/Dependency/Emitter/FunctionCallDependencyEmitter.php index 1624ac93c..27f9652b4 100644 --- a/src/Core/Dependency/Emitter/FunctionCallDependencyEmitter.php +++ b/src/Core/Dependency/Emitter/FunctionCallDependencyEmitter.php @@ -34,7 +34,7 @@ private function createDependenciesForReferences(array $references, AstMap $astM { foreach ($references as $reference) { foreach ($reference->dependencies as $dependency) { - if (DependencyType::UNRESOLVED_FUNCTION_CALL !== $dependency->type) { + if (DependencyType::UNRESOLVED_FUNCTION_CALL !== $dependency->context->dependencyType) { continue; } @@ -46,7 +46,7 @@ private function createDependenciesForReferences(array $references, AstMap $astM $dependencyList->addDependency( new Dependency( - $reference->getToken(), $dependency->token, $dependency->fileOccurrence, $dependency->type + $reference->getToken(), $dependency->token, $dependency->context ) ); } diff --git a/src/Core/Dependency/Emitter/FunctionDependencyEmitter.php b/src/Core/Dependency/Emitter/FunctionDependencyEmitter.php index 6a74f58c7..ccaa10186 100644 --- a/src/Core/Dependency/Emitter/FunctionDependencyEmitter.php +++ b/src/Core/Dependency/Emitter/FunctionDependencyEmitter.php @@ -21,11 +21,11 @@ public function applyDependencies(AstMap $astMap, DependencyList $dependencyList foreach ($astMap->getFileReferences() as $astFileReference) { foreach ($astFileReference->functionReferences as $astFunctionReference) { foreach ($astFunctionReference->dependencies as $dependency) { - if (DependencyType::SUPERGLOBAL_VARIABLE === $dependency->type) { + if (DependencyType::SUPERGLOBAL_VARIABLE === $dependency->context->dependencyType) { continue; } - if (DependencyType::UNRESOLVED_FUNCTION_CALL === $dependency->type) { + if (DependencyType::UNRESOLVED_FUNCTION_CALL === $dependency->context->dependencyType) { continue; } @@ -33,8 +33,7 @@ public function applyDependencies(AstMap $astMap, DependencyList $dependencyList new Dependency( $astFunctionReference->getToken(), $dependency->token, - $dependency->fileOccurrence, - $dependency->type + $dependency->context, ) ); } diff --git a/src/Core/Dependency/Emitter/FunctionSuperglobalDependencyEmitter.php b/src/Core/Dependency/Emitter/FunctionSuperglobalDependencyEmitter.php index 0025a0bcd..926b15d8f 100644 --- a/src/Core/Dependency/Emitter/FunctionSuperglobalDependencyEmitter.php +++ b/src/Core/Dependency/Emitter/FunctionSuperglobalDependencyEmitter.php @@ -21,15 +21,14 @@ public function applyDependencies(AstMap $astMap, DependencyList $dependencyList foreach ($astMap->getFileReferences() as $astFileReference) { foreach ($astFileReference->functionReferences as $astFunctionReference) { foreach ($astFunctionReference->dependencies as $dependency) { - if (DependencyType::SUPERGLOBAL_VARIABLE !== $dependency->type) { + if (DependencyType::SUPERGLOBAL_VARIABLE !== $dependency->context->dependencyType) { continue; } $dependencyList->addDependency( new Dependency( $astFunctionReference->getToken(), $dependency->token, - $dependency->fileOccurrence, - $dependency->type + $dependency->context, ) ); } diff --git a/src/Core/Dependency/Emitter/UsesDependencyEmitter.php b/src/Core/Dependency/Emitter/UsesDependencyEmitter.php index e1068e003..0b274fd8d 100644 --- a/src/Core/Dependency/Emitter/UsesDependencyEmitter.php +++ b/src/Core/Dependency/Emitter/UsesDependencyEmitter.php @@ -38,15 +38,14 @@ public function applyDependencies(AstMap $astMap, DependencyList $dependencyList foreach ($astMap->getFileReferences() as $fileReference) { foreach ($fileReference->classLikeReferences as $astClassReference) { foreach ($fileReference->dependencies as $emittedDependency) { - if (DependencyType::USE === $emittedDependency->type + if (DependencyType::USE === $emittedDependency->context->dependencyType && $this->isFQDN($emittedDependency, $FQDNIndex) ) { $dependencyList->addDependency( new Dependency( $astClassReference->getToken(), $emittedDependency->token, - $emittedDependency->fileOccurrence, - $emittedDependency->type + $emittedDependency->context, ) ); } diff --git a/src/Core/Dependency/InheritDependency.php b/src/Core/Dependency/InheritDependency.php index c21a183bf..8069ea18f 100644 --- a/src/Core/Dependency/InheritDependency.php +++ b/src/Core/Dependency/InheritDependency.php @@ -4,8 +4,7 @@ namespace Qossmic\Deptrac\Core\Dependency; -use Qossmic\Deptrac\Contract\Ast\DependencyType; -use Qossmic\Deptrac\Contract\Ast\FileOccurrence; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\TokenInterface; use Qossmic\Deptrac\Contract\Dependency\DependencyInterface; use Qossmic\Deptrac\Core\Ast\AstMap\AstInherit; @@ -28,7 +27,7 @@ public function serialize(): array } $buffer[] = ['name' => $this->inheritPath->classLikeName->toString(), 'line' => $this->inheritPath->fileOccurrence->line]; - $buffer[] = ['name' => $this->originalDependency->getDependent()->toString(), 'line' => $this->originalDependency->getFileOccurrence()->line]; + $buffer[] = ['name' => $this->originalDependency->getDependent()->toString(), 'line' => $this->originalDependency->getContext()->fileOccurrence->line]; return $buffer; } @@ -38,18 +37,13 @@ public function getDepender(): ClassLikeToken return $this->depender; } - public function getFileOccurrence(): FileOccurrence - { - return $this->originalDependency->getFileOccurrence(); - } - public function getDependent(): TokenInterface { return $this->dependent; } - public function getType(): DependencyType + public function getContext(): DependencyContext { - return $this->originalDependency->getType(); + return $this->originalDependency->getContext(); } } diff --git a/src/Core/Layer/Collector/AttributeCollector.php b/src/Core/Layer/Collector/AttributeCollector.php index 698bce65c..2575dcc44 100644 --- a/src/Core/Layer/Collector/AttributeCollector.php +++ b/src/Core/Layer/Collector/AttributeCollector.php @@ -28,7 +28,7 @@ public function satisfy(array $config, TokenReferenceInterface $reference): bool $match = $this->getSearchedSubstring($config); foreach ($reference->dependencies as $dependency) { - if (DependencyType::ATTRIBUTE !== $dependency->type) { + if (DependencyType::ATTRIBUTE !== $dependency->context->dependencyType) { continue; } diff --git a/src/Supportive/Console/Command/DebugDependenciesRunner.php b/src/Supportive/Console/Command/DebugDependenciesRunner.php index ad508c018..4e5733ccf 100644 --- a/src/Supportive/Console/Command/DebugDependenciesRunner.php +++ b/src/Supportive/Console/Command/DebugDependenciesRunner.php @@ -50,7 +50,7 @@ private function formatRow(Uncovered $rule): array $rule->layer ); - $fileOccurrence = $dependency->getFileOccurrence(); + $fileOccurrence = $dependency->getContext()->fileOccurrence; $message .= sprintf("\n%s:%d", $fileOccurrence->filepath, $fileOccurrence->line); return [$message]; diff --git a/src/Supportive/OutputFormatter/CodeclimateOutputFormatter.php b/src/Supportive/OutputFormatter/CodeclimateOutputFormatter.php index d2fb0b2be..b50393fa4 100644 --- a/src/Supportive/OutputFormatter/CodeclimateOutputFormatter.php +++ b/src/Supportive/OutputFormatter/CodeclimateOutputFormatter.php @@ -189,9 +189,9 @@ private function buildRuleArray(RuleInterface $rule, string $message, string $se 'categories' => ['Style', 'Complexity'], 'severity' => $severity, 'location' => [ - 'path' => $rule->getDependency()->getFileOccurrence()->filepath, + 'path' => $rule->getDependency()->getContext()->fileOccurrence->filepath, 'lines' => [ - 'begin' => $rule->getDependency()->getFileOccurrence()->line, + 'begin' => $rule->getDependency()->getContext()->fileOccurrence->line, ], ], ]; @@ -203,8 +203,8 @@ private function buildFingerprint(RuleInterface $rule): string $rule::class, $rule->getDependency()->getDepender()->toString(), $rule->getDependency()->getDependent()->toString(), - $rule->getDependency()->getFileOccurrence()->filepath, - $rule->getDependency()->getFileOccurrence()->line, + $rule->getDependency()->getContext()->fileOccurrence->filepath, + $rule->getDependency()->getContext()->fileOccurrence->line, ])); } } diff --git a/src/Supportive/OutputFormatter/ConsoleOutputFormatter.php b/src/Supportive/OutputFormatter/ConsoleOutputFormatter.php index 46276d251..4509e6225 100644 --- a/src/Supportive/OutputFormatter/ConsoleOutputFormatter.php +++ b/src/Supportive/OutputFormatter/ConsoleOutputFormatter.php @@ -71,7 +71,7 @@ private function printViolation(Violation|SkippedViolation $rule, OutputInterfac $rule->getDependentLayer() ) ); - $this->printFileOccurrence($output, $dependency->getFileOccurrence()); + $this->printFileOccurrence($output, $dependency->getContext()->fileOccurrence); if (count($dependency->serialize()) > 1) { $this->printMultilinePath($output, $dependency); @@ -160,7 +160,7 @@ private function printUncovered(OutputResult $result, OutputInterface $output): $u->layer ) ); - $this->printFileOccurrence($output, $dependency->getFileOccurrence()); + $this->printFileOccurrence($output, $dependency->getContext()->fileOccurrence); if (count($dependency->serialize()) > 1) { $this->printMultilinePath($output, $dependency); diff --git a/src/Supportive/OutputFormatter/GithubActionsOutputFormatter.php b/src/Supportive/OutputFormatter/GithubActionsOutputFormatter.php index 1d982add8..d11593ef4 100644 --- a/src/Supportive/OutputFormatter/GithubActionsOutputFormatter.php +++ b/src/Supportive/OutputFormatter/GithubActionsOutputFormatter.php @@ -66,8 +66,8 @@ private function printUncovered(OutputResult $result, OutputInterface $output, b sprintf( '::%s file=%s,line=%s::%s has uncovered dependency on %s (%s)', $reportAsError ? 'error' : 'warning', - $dependency->getFileOccurrence()->filepath, - $dependency->getFileOccurrence()->line, + $dependency->getContext()->fileOccurrence->filepath, + $dependency->getContext()->fileOccurrence->line, $dependency->getDepender()->toString(), $dependency->getDependent()->toString(), $u->layer @@ -124,8 +124,8 @@ private function printViolation(Violation|SkippedViolation $rule, OutputInterfac sprintf( '::%s file=%s,line=%s::%s', $this->determineLogLevel($rule), - $dependency->getFileOccurrence()->filepath, - $dependency->getFileOccurrence()->line, + $dependency->getContext()->fileOccurrence->filepath, + $dependency->getContext()->fileOccurrence->line, $message ) ); diff --git a/src/Supportive/OutputFormatter/JUnitOutputFormatter.php b/src/Supportive/OutputFormatter/JUnitOutputFormatter.php index 7cccd3af7..278ad5943 100644 --- a/src/Supportive/OutputFormatter/JUnitOutputFormatter.php +++ b/src/Supportive/OutputFormatter/JUnitOutputFormatter.php @@ -194,7 +194,7 @@ private function addFailure(Violation $violation, DOMDocument $xmlDoc, DOMElemen $message = sprintf( '%s:%d must not depend on %s (%s on %s)', $dependency->getDepender()->toString(), - $dependency->getFileOccurrence()->line, + $dependency->getContext()->fileOccurrence->line, $dependency->getDependent()->toString(), $violation->getDependerLayer(), $violation->getDependentLayer() @@ -224,7 +224,7 @@ private function addWarning(Uncovered $rule, DOMDocument $xmlDoc, DOMElement $te $message = sprintf( '%s:%d has uncovered dependency on %s (%s)', $dependency->getDepender()->toString(), - $dependency->getFileOccurrence()->line, + $dependency->getContext()->fileOccurrence->line, $dependency->getDependent()->toString(), $rule->layer ); diff --git a/src/Supportive/OutputFormatter/JsonOutputFormatter.php b/src/Supportive/OutputFormatter/JsonOutputFormatter.php index 149754b20..22562868a 100644 --- a/src/Supportive/OutputFormatter/JsonOutputFormatter.php +++ b/src/Supportive/OutputFormatter/JsonOutputFormatter.php @@ -92,11 +92,11 @@ public function finish( */ private function addFailure(array &$violationsArray, Violation $violation): void { - $className = $violation->getDependency()->getFileOccurrence()->filepath; + $className = $violation->getDependency()->getContext()->fileOccurrence->filepath; $violationsArray[$className]['messages'][] = [ 'message' => $this->getFailureMessage($violation), - 'line' => $violation->getDependency()->getFileOccurrence()->line, + 'line' => $violation->getDependency()->getContext()->fileOccurrence->line, 'type' => 'error', ]; } @@ -119,11 +119,11 @@ private function getFailureMessage(Violation $violation): string */ private function addSkipped(array &$violationsArray, SkippedViolation $violation): void { - $className = $violation->getDependency()->getFileOccurrence()->filepath; + $className = $violation->getDependency()->getContext()->fileOccurrence->filepath; $violationsArray[$className]['messages'][] = [ 'message' => $this->getWarningMessage($violation), - 'line' => $violation->getDependency()->getFileOccurrence()->line, + 'line' => $violation->getDependency()->getContext()->fileOccurrence->line, 'type' => 'warning', ]; } @@ -146,11 +146,11 @@ private function getWarningMessage(SkippedViolation $violation): string */ private function addUncovered(array &$violationsArray, Uncovered $violation): void { - $className = $violation->getDependency()->getFileOccurrence()->filepath; + $className = $violation->getDependency()->getContext()->fileOccurrence->filepath; $violationsArray[$className]['messages'][] = [ 'message' => $this->getUncoveredMessage($violation), - 'line' => $violation->getDependency()->getFileOccurrence()->line, + 'line' => $violation->getDependency()->getContext()->fileOccurrence->line, 'type' => 'warning', ]; } diff --git a/src/Supportive/OutputFormatter/TableOutputFormatter.php b/src/Supportive/OutputFormatter/TableOutputFormatter.php index ef85440d2..439414db3 100644 --- a/src/Supportive/OutputFormatter/TableOutputFormatter.php +++ b/src/Supportive/OutputFormatter/TableOutputFormatter.php @@ -92,7 +92,7 @@ private function skippedViolationRow(SkippedViolation $rule): array $message .= "\n".$this->formatMultilinePath($dependency); } - $fileOccurrence = $rule->getDependency()->getFileOccurrence(); + $fileOccurrence = $rule->getDependency()->getContext()->fileOccurrence; $message .= sprintf("\n%s:%d", $fileOccurrence->filepath, $fileOccurrence->line); return ['Skipped', $message]; @@ -116,7 +116,7 @@ private function violationRow(Violation $rule): array $message .= "\n".$this->formatMultilinePath($dependency); } - $fileOccurrence = $rule->getDependency()->getFileOccurrence(); + $fileOccurrence = $rule->getDependency()->getContext()->fileOccurrence; $message .= sprintf("\n%s:%d", $fileOccurrence->filepath, $fileOccurrence->line); return [sprintf('%s', $rule->ruleName()), $message]; @@ -175,7 +175,7 @@ private function uncoveredRow(Uncovered $rule, bool $reportAsError): array $message .= "\n".$this->formatMultilinePath($dependency); } - $fileOccurrence = $rule->getDependency()->getFileOccurrence(); + $fileOccurrence = $rule->getDependency()->getContext()->fileOccurrence; $message .= sprintf("\n%s:%d", $fileOccurrence->filepath, $fileOccurrence->line); return [ diff --git a/src/Supportive/OutputFormatter/XMLOutputFormatter.php b/src/Supportive/OutputFormatter/XMLOutputFormatter.php index 9c6130ebc..0f3e4f972 100644 --- a/src/Supportive/OutputFormatter/XMLOutputFormatter.php +++ b/src/Supportive/OutputFormatter/XMLOutputFormatter.php @@ -89,7 +89,7 @@ private function addRule(string $type, DOMElement $rootEntry, DOMDocument $xmlDo /** @throws void */ $entry->appendChild($xmlDoc->createElement('ClassB', $dependency->getDependent()->toString())); - $fileOccurrence = $dependency->getFileOccurrence(); + $fileOccurrence = $dependency->getContext()->fileOccurrence; /** @throws void */ $occurrence = $xmlDoc->createElement('occurrence'); $occurrence->setAttribute('file', $fileOccurrence->filepath); diff --git a/tests/Core/Analyser/EventHandler/DependsOnInternalTokenTest.php b/tests/Core/Analyser/EventHandler/DependsOnInternalTokenTest.php index 0e4a57902..202163c18 100644 --- a/tests/Core/Analyser/EventHandler/DependsOnInternalTokenTest.php +++ b/tests/Core/Analyser/EventHandler/DependsOnInternalTokenTest.php @@ -8,6 +8,7 @@ use Qossmic\Deptrac\Contract\Analyser\AnalysisResult; use Qossmic\Deptrac\Contract\Analyser\EventHelper; use Qossmic\Deptrac\Contract\Analyser\ProcessEvent; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Contract\Layer\LayerProvider; @@ -38,8 +39,8 @@ private function makeEvent( new Dependency( $dependerToken, $dependentToken, - new FileOccurrence('test', 1), - DependencyType::STATIC_METHOD + new DependencyContext(new FileOccurrence('test', 1), + DependencyType::STATIC_METHOD) ), new ClassLikeReference($dependerToken, ClassLikeType::TYPE_CLASS, [], [], $dependerTags), diff --git a/tests/Core/Ast/Parser/AnnotationReferenceExtractorTest.php b/tests/Core/Ast/Parser/AnnotationReferenceExtractorTest.php index d2b01cfe7..0f198f986 100644 --- a/tests/Core/Ast/Parser/AnnotationReferenceExtractorTest.php +++ b/tests/Core/Ast/Parser/AnnotationReferenceExtractorTest.php @@ -42,48 +42,48 @@ public function testPropertyDependencyResolving(): void 'Tests\Qossmic\Deptrac\Core\Ast\Parser\Fixtures\AnnotationDependencyChild', $annotationDependency[0]->token->toString() ); - self::assertSame($filePath, $annotationDependency[0]->fileOccurrence->filepath); - self::assertSame(9, $annotationDependency[0]->fileOccurrence->line); - self::assertSame('variable', $annotationDependency[0]->type->value); + self::assertSame($filePath, $annotationDependency[0]->context->fileOccurrence->filepath); + self::assertSame(9, $annotationDependency[0]->context->fileOccurrence->line); + self::assertSame('variable', $annotationDependency[0]->context->dependencyType->value); self::assertSame( 'Tests\Qossmic\Deptrac\Core\Ast\Parser\Fixtures\AnnotationDependencyChild', $annotationDependency[1]->token->toString() ); - self::assertSame($filePath, $annotationDependency[1]->fileOccurrence->filepath); - self::assertSame(23, $annotationDependency[1]->fileOccurrence->line); - self::assertSame('variable', $annotationDependency[1]->type->value); + self::assertSame($filePath, $annotationDependency[1]->context->fileOccurrence->filepath); + self::assertSame(23, $annotationDependency[1]->context->fileOccurrence->line); + self::assertSame('variable', $annotationDependency[1]->context->dependencyType->value); self::assertSame( 'Tests\Qossmic\Deptrac\Core\Ast\Parser\Fixtures\AnnotationDependencyChild', $annotationDependency[2]->token->toString() ); - self::assertSame($filePath, $annotationDependency[2]->fileOccurrence->filepath); - self::assertSame(26, $annotationDependency[2]->fileOccurrence->line); - self::assertSame('variable', $annotationDependency[2]->type->value); + self::assertSame($filePath, $annotationDependency[2]->context->fileOccurrence->filepath); + self::assertSame(26, $annotationDependency[2]->context->fileOccurrence->line); + self::assertSame('variable', $annotationDependency[2]->context->dependencyType->value); self::assertSame( 'Symfony\Component\Console\Exception\RuntimeException', $annotationDependency[3]->token->toString() ); - self::assertSame($filePath, $annotationDependency[3]->fileOccurrence->filepath); - self::assertSame(29, $annotationDependency[3]->fileOccurrence->line); - self::assertSame('variable', $annotationDependency[3]->type->value); + self::assertSame($filePath, $annotationDependency[3]->context->fileOccurrence->filepath); + self::assertSame(29, $annotationDependency[3]->context->fileOccurrence->line); + self::assertSame('variable', $annotationDependency[3]->context->dependencyType->value); self::assertSame( 'Symfony\Component\Finder\SplFileInfo', $annotationDependency[4]->token->toString() ); - self::assertSame($filePath, $annotationDependency[4]->fileOccurrence->filepath); - self::assertSame(14, $annotationDependency[4]->fileOccurrence->line); - self::assertSame('parameter', $annotationDependency[4]->type->value); + self::assertSame($filePath, $annotationDependency[4]->context->fileOccurrence->filepath); + self::assertSame(14, $annotationDependency[4]->context->fileOccurrence->line); + self::assertSame('parameter', $annotationDependency[4]->context->dependencyType->value); self::assertSame( 'Tests\Qossmic\Deptrac\Core\Ast\Parser\Fixtures\AnnotationDependencyChild', $annotationDependency[5]->token->toString() ); - self::assertSame($filePath, $annotationDependency[5]->fileOccurrence->filepath); - self::assertSame(14, $annotationDependency[5]->fileOccurrence->line); - self::assertSame('returntype', $annotationDependency[5]->type->value); + self::assertSame($filePath, $annotationDependency[5]->context->fileOccurrence->filepath); + self::assertSame(14, $annotationDependency[5]->context->fileOccurrence->line); + self::assertSame('returntype', $annotationDependency[5]->context->dependencyType->value); } } diff --git a/tests/Core/Ast/Parser/AnonymousClassExtractorTest.php b/tests/Core/Ast/Parser/AnonymousClassExtractorTest.php index fbf6305e5..6a8118b53 100644 --- a/tests/Core/Ast/Parser/AnonymousClassExtractorTest.php +++ b/tests/Core/Ast/Parser/AnonymousClassExtractorTest.php @@ -41,16 +41,16 @@ public function testPropertyDependencyResolving(): void 'Tests\Qossmic\Deptrac\Core\Ast\Parser\Fixtures\ClassA', $dependencies[0]->token->toString() ); - self::assertSame($filePath, $dependencies[0]->fileOccurrence->filepath); - self::assertSame(19, $dependencies[0]->fileOccurrence->line); - self::assertSame('anonymous_class_extends', $dependencies[0]->type->value); + self::assertSame($filePath, $dependencies[0]->context->fileOccurrence->filepath); + self::assertSame(19, $dependencies[0]->context->fileOccurrence->line); + self::assertSame('anonymous_class_extends', $dependencies[0]->context->dependencyType->value); self::assertSame( 'Tests\Qossmic\Deptrac\Core\Ast\Parser\Fixtures\InterfaceC', $dependencies[1]->token->toString() ); - self::assertSame($filePath, $dependencies[1]->fileOccurrence->filepath); - self::assertSame(19, $dependencies[1]->fileOccurrence->line); - self::assertSame('anonymous_class_implements', $dependencies[1]->type->value); + self::assertSame($filePath, $dependencies[1]->context->fileOccurrence->filepath); + self::assertSame(19, $dependencies[1]->context->fileOccurrence->line); + self::assertSame('anonymous_class_implements', $dependencies[1]->context->dependencyType->value); } } diff --git a/tests/Core/Ast/Parser/ClassConstantExtractorTest.php b/tests/Core/Ast/Parser/ClassConstantExtractorTest.php index fde614f8a..bcdab8377 100644 --- a/tests/Core/Ast/Parser/ClassConstantExtractorTest.php +++ b/tests/Core/Ast/Parser/ClassConstantExtractorTest.php @@ -39,8 +39,8 @@ public function testPropertyDependencyResolving(): void 'Tests\Qossmic\Deptrac\Core\Ast\Parser\Fixtures\ClassA', $dependencies[0]->token->toString() ); - self::assertSame($filePath, $dependencies[0]->fileOccurrence->filepath); - self::assertSame(15, $dependencies[0]->fileOccurrence->line); - self::assertSame('const', $dependencies[0]->type->value); + self::assertSame($filePath, $dependencies[0]->context->fileOccurrence->filepath); + self::assertSame(15, $dependencies[0]->context->fileOccurrence->line); + self::assertSame('const', $dependencies[0]->context->dependencyType->value); } } diff --git a/tests/Core/Ast/Parser/ClassDocBlockExtractorTest.php b/tests/Core/Ast/Parser/ClassDocBlockExtractorTest.php index f09d36911..b8852c80d 100644 --- a/tests/Core/Ast/Parser/ClassDocBlockExtractorTest.php +++ b/tests/Core/Ast/Parser/ClassDocBlockExtractorTest.php @@ -44,7 +44,7 @@ public function testMethodResolving(): void foreach ($dependencies as $key => $dependency) { self::assertSame(self::EXPECTED[$key][0], $dependency->token->toString()); - self::assertSame(self::EXPECTED[$key][1], $dependency->type); + self::assertSame(self::EXPECTED[$key][1], $dependency->context->dependencyType); } } } diff --git a/tests/Core/Dependency/DependencyListTest.php b/tests/Core/Dependency/DependencyListTest.php index 0fed798bc..f3445407b 100644 --- a/tests/Core/Dependency/DependencyListTest.php +++ b/tests/Core/Dependency/DependencyListTest.php @@ -5,6 +5,7 @@ namespace Tests\Qossmic\Deptrac\Core\Dependency; use PHPUnit\Framework\TestCase; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Core\Ast\AstMap\AstInherit; @@ -23,9 +24,12 @@ public function testAddDependency(): void $classC = ClassLikeToken::fromFQCN('C'); $dependencyResult = new DependencyList(); - $dependencyResult->addDependency($dep1 = new Dependency($classA, $classB, new FileOccurrence('a.php', 12), DependencyType::PARAMETER)); - $dependencyResult->addDependency($dep2 = new Dependency($classB, $classC, new FileOccurrence('b.php', 12), DependencyType::PARAMETER)); - $dependencyResult->addDependency($dep3 = new Dependency($classA, $classC, new FileOccurrence('a.php', 12), DependencyType::PARAMETER)); + $dependencyResult->addDependency($dep1 = new Dependency($classA, $classB, new DependencyContext( + new FileOccurrence('a.php', 12), DependencyType::PARAMETER))); + $dependencyResult->addDependency($dep2 = new Dependency($classB, $classC, new DependencyContext( + new FileOccurrence('b.php', 12), DependencyType::PARAMETER))); + $dependencyResult->addDependency($dep3 = new Dependency($classA, $classC, new DependencyContext( + new FileOccurrence('a.php', 12), DependencyType::PARAMETER))); self::assertSame([$dep1, $dep3], $dependencyResult->getDependenciesByClass($classA)); self::assertSame([$dep2], $dependencyResult->getDependenciesByClass($classB)); self::assertSame([], $dependencyResult->getDependenciesByClass($classC)); @@ -38,7 +42,8 @@ public function testGetDependenciesAndInheritDependencies(): void $classB = ClassLikeToken::fromFQCN('B'); $dependencyResult = new DependencyList(); - $dependencyResult->addDependency($dep1 = new Dependency($classA, $classB, new FileOccurrence('a.php', 12), DependencyType::PARAMETER)); + $dependencyResult->addDependency($dep1 = new Dependency($classA, $classB, new DependencyContext( + new FileOccurrence('a.php', 12), DependencyType::PARAMETER))); $dependencyResult->addInheritDependency($dep2 = new InheritDependency($classA, $classB, $dep1, new AstInherit( $classB, diff --git a/tests/Core/Dependency/DependencyTest.php b/tests/Core/Dependency/DependencyTest.php index d655f70e8..0691568cd 100644 --- a/tests/Core/Dependency/DependencyTest.php +++ b/tests/Core/Dependency/DependencyTest.php @@ -5,6 +5,7 @@ namespace Tests\Qossmic\Deptrac\Core\Dependency; use PHPUnit\Framework\TestCase; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Core\Ast\AstMap\ClassLike\ClassLikeToken; @@ -16,11 +17,11 @@ public function testGetSet(): void { $dependency = new Dependency( ClassLikeToken::fromFQCN('a'), - ClassLikeToken::fromFQCN('b'), new FileOccurrence('/foo.php', 23), DependencyType::PARAMETER - ); + ClassLikeToken::fromFQCN('b'), new DependencyContext(new FileOccurrence('/foo.php', 23), DependencyType::PARAMETER + )); self::assertSame('a', $dependency->getDepender()->toString()); - self::assertSame('/foo.php', $dependency->getFileOccurrence()->filepath); - self::assertSame(23, $dependency->getFileOccurrence()->line); + self::assertSame('/foo.php', $dependency->getContext()->fileOccurrence->filepath); + self::assertSame(23, $dependency->getContext()->fileOccurrence->line); self::assertSame('b', $dependency->getDependent()->toString()); } } diff --git a/tests/Core/Dependency/Emitter/EmitterTrait.php b/tests/Core/Dependency/Emitter/EmitterTrait.php index d712e234a..aa5145a8c 100644 --- a/tests/Core/Dependency/Emitter/EmitterTrait.php +++ b/tests/Core/Dependency/Emitter/EmitterTrait.php @@ -55,7 +55,7 @@ public function getEmittedDependencies(DependencyEmitterInterface $emitter, $fil static function (DependencyInterface $d) { return sprintf('%s:%d on %s', $d->getDepender()->toString(), - $d->getFileOccurrence()->line, + $d->getContext()->fileOccurrence->line, $d->getDependent()->toString() ); }, diff --git a/tests/Core/Dependency/InheritDependencyTest.php b/tests/Core/Dependency/InheritDependencyTest.php index a0a701d86..c9f7af2c8 100644 --- a/tests/Core/Dependency/InheritDependencyTest.php +++ b/tests/Core/Dependency/InheritDependencyTest.php @@ -5,6 +5,7 @@ namespace Tests\Qossmic\Deptrac\Core\Dependency; use PHPUnit\Framework\TestCase; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Core\Ast\AstMap\AstInherit; @@ -24,13 +25,14 @@ public function testGetSet(): void $dependency = new InheritDependency( $classLikeNameA, $classLikeNameB, - $dep = new Dependency($classLikeNameA, $classLikeNameB, $fileOccurrence, DependencyType::PARAMETER), + $dep = new Dependency($classLikeNameA, $classLikeNameB, new DependencyContext( + $fileOccurrence, DependencyType::PARAMETER)), $astInherit = new AstInherit($classLikeNameB, $fileOccurrence, AstInheritType::EXTENDS) ); self::assertSame($classLikeNameA, $dependency->getDepender()); self::assertSame($classLikeNameB, $dependency->getDependent()); - self::assertSame(1, $dependency->getFileOccurrence()->line); + self::assertSame(1, $dependency->getContext()->fileOccurrence->line); self::assertSame($dep, $dependency->originalDependency); self::assertSame($astInherit, $dependency->inheritPath); } diff --git a/tests/Supportive/OutputFormatter/BaselineOutputFormatterTest.php b/tests/Supportive/OutputFormatter/BaselineOutputFormatterTest.php index cb5eddba6..bb796fb1e 100644 --- a/tests/Supportive/OutputFormatter/BaselineOutputFormatterTest.php +++ b/tests/Supportive/OutputFormatter/BaselineOutputFormatterTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Qossmic\Deptrac\Contract\Analyser\AnalysisResult; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Contract\OutputFormatter\OutputFormatterInput; @@ -44,7 +45,7 @@ public static function basicDataProvider(): iterable new InheritDependency( ClassLikeToken::fromFQCN('ClassA'), ClassLikeToken::fromFQCN('ClassB'), - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('originalA.php', 3), AstInheritType::EXTENDS @@ -78,7 +79,7 @@ public static function basicDataProvider(): iterable yield [ [ new Violation( - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), 'LayerA', 'LayerB', new DummyViolationCreatingRule() @@ -95,7 +96,7 @@ public static function basicDataProvider(): iterable yield [ [ new SkippedViolation( - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), 'LayerA', 'LayerB' ), @@ -106,7 +107,7 @@ public static function basicDataProvider(): iterable yield [ [ new Uncovered( - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), 'LayerA' ), ], diff --git a/tests/Supportive/OutputFormatter/CodeclimateOutputFormatterTest.php b/tests/Supportive/OutputFormatter/CodeclimateOutputFormatterTest.php index ab23d1fce..f915afb0b 100644 --- a/tests/Supportive/OutputFormatter/CodeclimateOutputFormatterTest.php +++ b/tests/Supportive/OutputFormatter/CodeclimateOutputFormatterTest.php @@ -7,6 +7,7 @@ use Exception; use PHPUnit\Framework\TestCase; use Qossmic\Deptrac\Contract\Analyser\AnalysisResult; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Contract\OutputFormatter\OutputFormatterInput; @@ -54,7 +55,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassB'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -89,7 +90,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassD'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassC.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassC.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -124,7 +125,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassE'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassC.php', 15), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassC.php', 15), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -162,7 +163,7 @@ public static function basicDataProvider(): iterable new Violation( new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER) ), 'LayerA', 'LayerB', @@ -185,7 +186,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassB'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -219,7 +220,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassD'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassC.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassC.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -259,7 +260,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassB'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -291,7 +292,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassB'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassA.php', 15), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassA.php', 15), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -322,7 +323,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassD'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassC.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassC.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -350,7 +351,7 @@ public static function basicDataProvider(): iterable new Uncovered( new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('OriginalA.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('OriginalA.php', 12), DependencyType::PARAMETER) ), 'LayerA' ), @@ -462,7 +463,7 @@ public function testJsonRenderError(): void $violation = new Violation( new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'.$malformedCharacters), new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'.$malformedCharacters), new DependencyContext(new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER) ), 'LayerA', 'LayerB', diff --git a/tests/Supportive/OutputFormatter/ConsoleOutputFormatterTest.php b/tests/Supportive/OutputFormatter/ConsoleOutputFormatterTest.php index 70c56181b..1b3ac9540 100644 --- a/tests/Supportive/OutputFormatter/ConsoleOutputFormatterTest.php +++ b/tests/Supportive/OutputFormatter/ConsoleOutputFormatterTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Qossmic\Deptrac\Contract\Analyser\AnalysisResult; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Contract\OutputFormatter\OutputFormatterInput; @@ -46,7 +47,7 @@ public static function basicDataProvider(): iterable new InheritDependency( ClassLikeToken::fromFQCN('ClassA'), ClassLikeToken::fromFQCN('ClassB'), - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('originalA.php', 3), AstInheritType::EXTENDS @@ -98,7 +99,7 @@ public static function basicDataProvider(): iterable yield [ [ new Violation( - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), 'LayerA', 'LayerB', new DummyViolationCreatingRule() @@ -139,7 +140,7 @@ public static function basicDataProvider(): iterable yield [ [ new SkippedViolation( - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), 'LayerA', 'LayerB' ), @@ -162,7 +163,7 @@ public static function basicDataProvider(): iterable yield [ [ new Uncovered( - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), 'LayerA' ), ], @@ -245,7 +246,7 @@ public function testWithoutSkippedViolations(): void $analysisResult = new AnalysisResult(); $analysisResult->addRule(new SkippedViolation( - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), 'LayerA', 'LayerB' )); diff --git a/tests/Supportive/OutputFormatter/GithubActionsOutputFormatterTest.php b/tests/Supportive/OutputFormatter/GithubActionsOutputFormatterTest.php index 17f5b6038..8f5277a05 100644 --- a/tests/Supportive/OutputFormatter/GithubActionsOutputFormatterTest.php +++ b/tests/Supportive/OutputFormatter/GithubActionsOutputFormatterTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Qossmic\Deptrac\Contract\Analyser\AnalysisResult; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Contract\OutputFormatter\OutputFormatterInput; @@ -86,7 +87,7 @@ public static function finishProvider(): iterable yield 'Simple Violation' => [ 'violations' => [ new Violation( - new Dependency($originalA, $originalB, $originalAOccurrence, DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext($originalAOccurrence, DependencyType::PARAMETER)), 'LayerA', 'LayerB', new DummyViolationCreatingRule() @@ -100,7 +101,7 @@ public static function finishProvider(): iterable yield 'Skipped Violation' => [ 'violations' => [ new SkippedViolation( - new Dependency($originalA, $originalB, $originalAOccurrence, DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext($originalAOccurrence, DependencyType::PARAMETER)), 'LayerA', 'LayerB' ), @@ -113,7 +114,7 @@ public static function finishProvider(): iterable yield 'Uncovered Dependency' => [ 'violations' => [ new Uncovered( - new Dependency($originalA, $originalB, $originalAOccurrence, DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext($originalAOccurrence, DependencyType::PARAMETER)), 'LayerA' ), ], @@ -128,7 +129,7 @@ public static function finishProvider(): iterable new InheritDependency( ClassLikeToken::fromFQCN('ClassA'), ClassLikeToken::fromFQCN('ClassB'), - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('originalA.php', 3), AstInheritType::EXTENDS @@ -187,7 +188,7 @@ public function testWithoutSkippedViolations(): void $analysisResult = new AnalysisResult(); $analysisResult->addRule( new SkippedViolation( - new Dependency($originalA, $originalB, $originalAOccurrence, DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext($originalAOccurrence, DependencyType::PARAMETER)), 'LayerA', 'LayerB' ) @@ -219,7 +220,7 @@ public function testUncoveredWithFailOnUncoveredAreReportedAsError(): void $analysisResult = new AnalysisResult(); $analysisResult->addRule( new Uncovered( - new Dependency($originalA, $originalB, $originalAOccurrence, DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext($originalAOccurrence, DependencyType::PARAMETER)), 'LayerA' ) ); diff --git a/tests/Supportive/OutputFormatter/GraphVizDotOutputFormatterTest.php b/tests/Supportive/OutputFormatter/GraphVizDotOutputFormatterTest.php index 57d637de9..496f97195 100644 --- a/tests/Supportive/OutputFormatter/GraphVizDotOutputFormatterTest.php +++ b/tests/Supportive/OutputFormatter/GraphVizDotOutputFormatterTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Qossmic\Deptrac\Contract\Analyser\AnalysisResult; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Contract\OutputFormatter\OutputFormatterInput; @@ -37,13 +38,13 @@ public function testFinish(): void $classA = ClassLikeToken::fromFQCN('ClassA'); $analysisResult = new AnalysisResult(); - $analysisResult->addRule(new Violation(new Dependency($classA, ClassLikeToken::fromFQCN('ClassB'), $fileOccurrenceA, DependencyType::PARAMETER), 'LayerA', 'LayerB', new DummyViolationCreatingRule())); - $analysisResult->addRule(new Violation(new Dependency($classA, ClassLikeToken::fromFQCN('ClassHidden'), $fileOccurrenceA, DependencyType::PARAMETER), 'LayerA', 'LayerHidden', new DummyViolationCreatingRule())); + $analysisResult->addRule(new Violation(new Dependency($classA, ClassLikeToken::fromFQCN('ClassB'), new DependencyContext($fileOccurrenceA, DependencyType::PARAMETER)), 'LayerA', 'LayerB', new DummyViolationCreatingRule())); + $analysisResult->addRule(new Violation(new Dependency($classA, ClassLikeToken::fromFQCN('ClassHidden'), new DependencyContext($fileOccurrenceA, DependencyType::PARAMETER)), 'LayerA', 'LayerHidden', new DummyViolationCreatingRule())); $analysisResult->addRule(new Violation(new Dependency(ClassLikeToken::fromFQCN('ClassAB'), ClassLikeToken::fromFQCN('ClassBA'), - new FileOccurrence('classAB.php', 1), DependencyType::PARAMETER + new DependencyContext(new FileOccurrence('classAB.php', 1), DependencyType::PARAMETER) ), 'LayerA', 'LayerB', new DummyViolationCreatingRule())); - $analysisResult->addRule(new Allowed(new Dependency($classA, ClassLikeToken::fromFQCN('ClassC'), $fileOccurrenceA, DependencyType::PARAMETER), 'LayerA', 'LayerC')); - $analysisResult->addRule(new Uncovered(new Dependency($classA, ClassLikeToken::fromFQCN('ClassD'), $fileOccurrenceA, DependencyType::PARAMETER), 'LayerC')); + $analysisResult->addRule(new Allowed(new Dependency($classA, ClassLikeToken::fromFQCN('ClassC'), new DependencyContext($fileOccurrenceA, DependencyType::PARAMETER)), 'LayerA', 'LayerC')); + $analysisResult->addRule(new Uncovered(new Dependency($classA, ClassLikeToken::fromFQCN('ClassD'), new DependencyContext($fileOccurrenceA, DependencyType::PARAMETER)), 'LayerC')); $bufferedOutput = new BufferedOutput(); $input = new OutputFormatterInput( @@ -78,7 +79,7 @@ public function testGroups(): void $dependency = new Dependency( ClassLikeToken::fromFQCN('ClassA'), - ClassLikeToken::fromFQCN('ClassC'), new FileOccurrence('classA.php', 0), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('ClassC'), new DependencyContext(new FileOccurrence('classA.php', 0), DependencyType::PARAMETER) ); $analysisResult = new AnalysisResult(); @@ -127,7 +128,7 @@ public function testPointToGroups(): void $dependency = new Dependency( ClassLikeToken::fromFQCN('ClassA'), - ClassLikeToken::fromFQCN('ClassC'), new FileOccurrence('classA.php', 0), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('ClassC'), new DependencyContext(new FileOccurrence('classA.php', 0), DependencyType::PARAMETER) ); $analysisResult = new AnalysisResult(); diff --git a/tests/Supportive/OutputFormatter/JUnitOutputFormatterTest.php b/tests/Supportive/OutputFormatter/JUnitOutputFormatterTest.php index 31a689ce4..6c6abebde 100644 --- a/tests/Supportive/OutputFormatter/JUnitOutputFormatterTest.php +++ b/tests/Supportive/OutputFormatter/JUnitOutputFormatterTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Qossmic\Deptrac\Contract\Analyser\AnalysisResult; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Contract\OutputFormatter\OutputFormatterInput; @@ -57,7 +58,7 @@ public static function basicDataProvider(): iterable new InheritDependency( ClassLikeToken::fromFQCN('ClassA'), ClassLikeToken::fromFQCN('ClassB'), - new Dependency($originalA, $originalB, new FileOccurrence('foo.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('foo.php', 12), DependencyType::PARAMETER)), (new AstInherit( $classInheritA, new FileOccurrence('foo.php', 3), AstInheritType::EXTENDS @@ -87,7 +88,7 @@ public static function basicDataProvider(): iterable yield [ [ new Violation( - new Dependency($originalA, $originalB, new FileOccurrence('foo.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('foo.php', 12), DependencyType::PARAMETER)), 'LayerA', 'LayerB', new DummyViolationCreatingRule() @@ -107,7 +108,7 @@ public static function basicDataProvider(): iterable new InheritDependency( ClassLikeToken::fromFQCN('ClassA'), ClassLikeToken::fromFQCN('ClassB'), - new Dependency($originalA, $originalB, new FileOccurrence('foo.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('foo.php', 12), DependencyType::PARAMETER)), (new AstInherit( $classInheritA, new FileOccurrence('foo.php', 3), AstInheritType::EXTENDS @@ -133,7 +134,7 @@ public static function basicDataProvider(): iterable new InheritDependency( ClassLikeToken::fromFQCN('ClassC'), ClassLikeToken::fromFQCN('ClassD'), - new Dependency($originalA, $originalB, new FileOccurrence('foo.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('foo.php', 12), DependencyType::PARAMETER)), (new AstInherit( $classInheritA, new FileOccurrence('foo.php', 3), AstInheritType::EXTENDS diff --git a/tests/Supportive/OutputFormatter/JsonOutputFormatterTest.php b/tests/Supportive/OutputFormatter/JsonOutputFormatterTest.php index 2a6316dc9..95b4c3c3d 100644 --- a/tests/Supportive/OutputFormatter/JsonOutputFormatterTest.php +++ b/tests/Supportive/OutputFormatter/JsonOutputFormatterTest.php @@ -7,6 +7,7 @@ use Exception; use PHPUnit\Framework\TestCase; use Qossmic\Deptrac\Contract\Analyser\AnalysisResult; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Contract\OutputFormatter\OutputFormatterInput; @@ -53,7 +54,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassB'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -88,7 +89,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassD'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassC.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassC.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -123,7 +124,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassE'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassC.php', 15), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassC.php', 15), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -161,7 +162,7 @@ public static function basicDataProvider(): iterable new Violation( new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER) ), 'LayerA', 'LayerB', @@ -184,7 +185,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassB'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -218,7 +219,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassD'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassC.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassC.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -259,7 +260,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassB'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -294,7 +295,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassB'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassA.php', 15), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassA.php', 15), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -328,7 +329,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassD'), new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('ClassC.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('ClassC.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -359,7 +360,7 @@ public static function basicDataProvider(): iterable new Uncovered( new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'), new FileOccurrence('OriginalA.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'), new DependencyContext(new FileOccurrence('OriginalA.php', 12), DependencyType::PARAMETER) ), 'LayerA' ), @@ -447,7 +448,7 @@ public function testJsonRenderError(): void $violation = new Violation( new Dependency( ClassLikeToken::fromFQCN('OriginalA'), - ClassLikeToken::fromFQCN('OriginalB'.$malformedCharacters), new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER + ClassLikeToken::fromFQCN('OriginalB'.$malformedCharacters), new DependencyContext(new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER) ), 'LayerA', 'LayerB', diff --git a/tests/Supportive/OutputFormatter/TableOutputFormatterTest.php b/tests/Supportive/OutputFormatter/TableOutputFormatterTest.php index e14d14e18..b078e6166 100644 --- a/tests/Supportive/OutputFormatter/TableOutputFormatterTest.php +++ b/tests/Supportive/OutputFormatter/TableOutputFormatterTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Qossmic\Deptrac\Contract\Analyser\AnalysisResult; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Contract\OutputFormatter\OutputFormatterInput; @@ -48,7 +49,7 @@ public static function basicDataProvider(): iterable new InheritDependency( ClassLikeToken::fromFQCN('ClassA'), ClassLikeToken::fromFQCN('ClassB'), - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('originalA.php', 3), AstInheritType::EXTENDS @@ -111,7 +112,7 @@ public static function basicDataProvider(): iterable yield [ [ new Violation( - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), 'LayerA', 'LayerB', new DummyViolationCreatingRule() @@ -164,7 +165,7 @@ public static function basicDataProvider(): iterable yield 'skipped violations' => [ [ new SkippedViolation( - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), 'LayerA', 'LayerB' ), @@ -196,7 +197,7 @@ public static function basicDataProvider(): iterable yield 'skipped violations without reporting' => [ [ new SkippedViolation( - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), 'LayerA', 'LayerB' ), @@ -223,7 +224,7 @@ public static function basicDataProvider(): iterable yield 'uncovered' => [ 'rules' => [ new Uncovered( - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), 'LayerA' ), ], @@ -254,7 +255,7 @@ public static function basicDataProvider(): iterable yield 'uncovered without reporting' => [ 'rules' => [ new Uncovered( - new Dependency($originalA, $originalB, new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER), + new Dependency($originalA, $originalB, new DependencyContext(new FileOccurrence('originalA.php', 12), DependencyType::PARAMETER)), 'LayerA' ), ], diff --git a/tests/Supportive/OutputFormatter/XMLOutputFormatterTest.php b/tests/Supportive/OutputFormatter/XMLOutputFormatterTest.php index 31ae363ae..74ce75ef0 100644 --- a/tests/Supportive/OutputFormatter/XMLOutputFormatterTest.php +++ b/tests/Supportive/OutputFormatter/XMLOutputFormatterTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Qossmic\Deptrac\Contract\Analyser\AnalysisResult; +use Qossmic\Deptrac\Contract\Ast\DependencyContext; use Qossmic\Deptrac\Contract\Ast\DependencyType; use Qossmic\Deptrac\Contract\Ast\FileOccurrence; use Qossmic\Deptrac\Contract\OutputFormatter\OutputFormatterInput; @@ -50,7 +51,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassA'), ClassLikeToken::fromFQCN('ClassB'), new Dependency(ClassLikeToken::fromFQCN('OriginalA'), ClassLikeToken::fromFQCN('OriginalB'), - new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER + new DependencyContext(new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -85,7 +86,7 @@ public static function basicDataProvider(): iterable [ new Violation( new Dependency(ClassLikeToken::fromFQCN('OriginalA'), ClassLikeToken::fromFQCN('OriginalB'), - new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER + new DependencyContext(new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER) ), 'LayerA', 'LayerB', @@ -107,7 +108,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassA'), ClassLikeToken::fromFQCN('ClassB'), new Dependency(ClassLikeToken::fromFQCN('OriginalA'), ClassLikeToken::fromFQCN('OriginalB'), - new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER + new DependencyContext(new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3), @@ -138,7 +139,7 @@ public static function basicDataProvider(): iterable ClassLikeToken::fromFQCN('ClassC'), ClassLikeToken::fromFQCN('ClassD'), new Dependency(ClassLikeToken::fromFQCN('OriginalA'), ClassLikeToken::fromFQCN('OriginalB'), - new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER + new DependencyContext(new FileOccurrence('ClassA.php', 12), DependencyType::PARAMETER) ), (new AstInherit( ClassLikeToken::fromFQCN('ClassInheritA'), new FileOccurrence('ClassA.php', 3),