From 02dd89e69f7747ff2461a04d5e0e803bdf1f78d6 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Wed, 24 Jul 2024 11:16:51 +0200 Subject: [PATCH] cs --- config/cache.php | 9 +- config/services.php | 267 ++++++++++++------ src/Contract/Config/Collector/BoolConfig.php | 3 +- .../InputCollector/FileInputCollector.php | 3 +- .../DependencyInjection/Configuration.php | 27 +- .../GraphVizOutputFormatter.php | 3 +- tests/Core/Ast/AstMapFlattenGeneratorTest.php | 6 +- .../Collector/AttributeCollectorTest.php | 3 +- .../Layer/Collector/BoolCollectorTest.php | 6 +- .../Layer/Collector/ExtendsCollectorTest.php | 15 +- .../Collector/ImplementsCollectorTest.php | 15 +- .../InheritanceLevelCollectorTest.php | 9 +- .../Layer/Collector/InheritsCollectorTest.php | 15 +- .../Layer/Collector/LayerCollectorTest.php | 21 +- .../Layer/Collector/MethodCollectorTest.php | 6 +- .../Layer/Collector/UsesCollectorTest.php | 15 +- tests/Core/Layer/LayerResolverTest.php | 6 +- 17 files changed, 286 insertions(+), 143 deletions(-) diff --git a/config/cache.php b/config/cache.php index 77dee588..728debc1 100644 --- a/config/cache.php +++ b/config/cache.php @@ -16,11 +16,13 @@ $services ->defaults() - ->public(); + ->public() + ; $services ->set(AstFileReferenceFileCache::class) - ->args(['%cache_file%', Application::VERSION]); + ->args(['%cache_file%', Application::VERSION]) + ; $services->alias(AstFileReferenceDeferredCacheInterface::class, AstFileReferenceFileCache::class); $services->alias(AstFileReferenceCacheInterface::class, AstFileReferenceDeferredCacheInterface::class); @@ -28,5 +30,6 @@ $services ->set(CacheableFileSubscriber::class) ->args([service(AstFileReferenceFileCache::class)]) - ->tag('kernel.event_subscriber'); + ->tag('kernel.event_subscriber') + ; }; diff --git a/config/services.php b/config/services.php index 96475f2f..0333bfb2 100644 --- a/config/services.php +++ b/config/services.php @@ -122,7 +122,8 @@ $services ->defaults() - ->autowire(); + ->autowire() + ; /* * Utilities @@ -137,14 +138,16 @@ '$paths' => param('paths'), '$excludedFilePatterns' => param('exclude_files'), '$basePath' => param('projectDirectory'), - ]); + ]) + ; $services->alias(InputCollectorInterface::class, FileInputCollector::class); $services->set(YmlFileLoader::class); $services ->set(Dumper::class) ->args([ '$templateFile' => __DIR__.'/deptrac_template.yaml', - ]); + ]) + ; /* * AST @@ -157,46 +160,58 @@ ->factory([service(ParserFactory::class), 'create']) ->args([ '$kind' => ParserFactory::PREFER_PHP7, - ]); + ]) + ; $services->set(AstFileReferenceInMemoryCache::class); $services->alias(AstFileReferenceCacheInterface::class, AstFileReferenceInMemoryCache::class); $services ->set(NikicPhpParser::class) ->args([ '$extractors' => tagged_iterator('reference_extractors'), - ]); + ]) + ; $services->alias(ParserInterface::class, NikicPhpParser::class); $services->set(TypeResolver::class); $services ->set(AnnotationReferenceExtractor::class) - ->tag('reference_extractors'); + ->tag('reference_extractors') + ; $services ->set(AnonymousClassExtractor::class) - ->tag('reference_extractors'); + ->tag('reference_extractors') + ; $services ->set(ClassConstantExtractor::class) - ->tag('reference_extractors'); + ->tag('reference_extractors') + ; $services ->set(FunctionLikeExtractor::class) - ->tag('reference_extractors'); + ->tag('reference_extractors') + ; $services ->set(PropertyExtractor::class) - ->tag('reference_extractors'); + ->tag('reference_extractors') + ; $services ->set(KeywordExtractor::class) - ->tag('reference_extractors'); + ->tag('reference_extractors') + ; $services ->set(StaticExtractor::class) - ->tag('reference_extractors'); + ->tag('reference_extractors') + ; $services ->set(FunctionLikeExtractor::class) - ->tag('reference_extractors'); + ->tag('reference_extractors') + ; $services ->set(VariableExtractor::class) - ->tag('reference_extractors'); + ->tag('reference_extractors') + ; $services ->set(FunctionCallResolver::class) - ->tag('reference_extractors'); + ->tag('reference_extractors') + ; /* * Dependency @@ -206,30 +221,38 @@ ->args([ '$config' => param('analyser'), '$emitterLocator' => tagged_locator('dependency_emitter', 'key'), - ]); + ]) + ; $services->set(TokenResolver::class); $services->set(InheritanceFlattener::class); $services ->set(ClassDependencyEmitter::class) - ->tag('dependency_emitter', ['key' => EmitterType::CLASS_TOKEN->value]); + ->tag('dependency_emitter', ['key' => EmitterType::CLASS_TOKEN->value]) + ; $services ->set(ClassSuperglobalDependencyEmitter::class) - ->tag('dependency_emitter', ['key' => EmitterType::CLASS_SUPERGLOBAL_TOKEN->value]); + ->tag('dependency_emitter', ['key' => EmitterType::CLASS_SUPERGLOBAL_TOKEN->value]) + ; $services ->set(FileDependencyEmitter::class) - ->tag('dependency_emitter', ['key' => EmitterType::FILE_TOKEN->value]); + ->tag('dependency_emitter', ['key' => EmitterType::FILE_TOKEN->value]) + ; $services ->set(FunctionDependencyEmitter::class) - ->tag('dependency_emitter', ['key' => EmitterType::FUNCTION_TOKEN->value]); + ->tag('dependency_emitter', ['key' => EmitterType::FUNCTION_TOKEN->value]) + ; $services ->set(FunctionCallDependencyEmitter::class) - ->tag('dependency_emitter', ['key' => EmitterType::FUNCTION_CALL->value]); + ->tag('dependency_emitter', ['key' => EmitterType::FUNCTION_CALL->value]) + ; $services ->set(FunctionSuperglobalDependencyEmitter::class) - ->tag('dependency_emitter', ['key' => EmitterType::FUNCTION_SUPERGLOBAL_TOKEN->value]); + ->tag('dependency_emitter', ['key' => EmitterType::FUNCTION_SUPERGLOBAL_TOKEN->value]) + ; $services ->set(UsesDependencyEmitter::class) - ->tag('dependency_emitter', ['key' => EmitterType::USE_TOKEN->value]); + ->tag('dependency_emitter', ['key' => EmitterType::USE_TOKEN->value]) + ; /* * Layer @@ -238,81 +261,104 @@ ->set(LayerResolver::class) ->args([ '$layersConfig' => param('layers'), - ]); + ]) + ; $services->alias(LayerResolverInterface::class, LayerResolver::class); $services ->set(CollectorProvider::class) ->args([ '$collectorLocator' => tagged_locator('collector', 'type'), - ]); + ]) + ; $services->set(CollectorResolver::class); $services->alias(CollectorResolverInterface::class, CollectorResolver::class); $services ->set(AttributeCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_ATTRIBUTE->value]); + ->tag('collector', ['type' => CollectorType::TYPE_ATTRIBUTE->value]) + ; $services ->set(BoolCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_BOOL->value]); + ->tag('collector', ['type' => CollectorType::TYPE_BOOL->value]) + ; $services ->set(ClassCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_CLASS->value]); + ->tag('collector', ['type' => CollectorType::TYPE_CLASS->value]) + ; $services ->set(ClassLikeCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_CLASSLIKE->value]); + ->tag('collector', ['type' => CollectorType::TYPE_CLASSLIKE->value]) + ; $services ->set(ClassNameRegexCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_CLASS_NAME_REGEX->value]); + ->tag('collector', ['type' => CollectorType::TYPE_CLASS_NAME_REGEX->value]) + ; $services ->set(TagValueRegexCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_TAG_VALUE_REGEX->value]); + ->tag('collector', ['type' => CollectorType::TYPE_TAG_VALUE_REGEX->value]) + ; $services ->set(DirectoryCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_DIRECTORY->value]); + ->tag('collector', ['type' => CollectorType::TYPE_DIRECTORY->value]) + ; $services ->set(ExtendsCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_EXTENDS->value]); + ->tag('collector', ['type' => CollectorType::TYPE_EXTENDS->value]) + ; $services ->set(FunctionNameCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_FUNCTION_NAME->value]); + ->tag('collector', ['type' => CollectorType::TYPE_FUNCTION_NAME->value]) + ; $services ->set(GlobCollector::class) ->args([ '$basePath' => param('projectDirectory'), ]) - ->tag('collector', ['type' => CollectorType::TYPE_GLOB->value]); + ->tag('collector', ['type' => CollectorType::TYPE_GLOB->value]) + ; $services ->set(ImplementsCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_IMPLEMENTS->value]); + ->tag('collector', ['type' => CollectorType::TYPE_IMPLEMENTS->value]) + ; $services ->set(InheritanceLevelCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_INHERITANCE->value]); + ->tag('collector', ['type' => CollectorType::TYPE_INHERITANCE->value]) + ; $services ->set(InterfaceCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_INTERFACE->value]); + ->tag('collector', ['type' => CollectorType::TYPE_INTERFACE->value]) + ; $services ->set(InheritsCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_INHERITS->value]); + ->tag('collector', ['type' => CollectorType::TYPE_INHERITS->value]) + ; $services ->set(LayerCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_LAYER->value]); + ->tag('collector', ['type' => CollectorType::TYPE_LAYER->value]) + ; $services ->set(MethodCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_METHOD->value]); + ->tag('collector', ['type' => CollectorType::TYPE_METHOD->value]) + ; $services ->set(SuperglobalCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_SUPERGLOBAL->value]); + ->tag('collector', ['type' => CollectorType::TYPE_SUPERGLOBAL->value]) + ; $services ->set(TraitCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_TRAIT->value]); + ->tag('collector', ['type' => CollectorType::TYPE_TRAIT->value]) + ; $services ->set(UsesCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_USES->value]); + ->tag('collector', ['type' => CollectorType::TYPE_USES->value]) + ; $services ->set(PhpInternalCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_PHP_INTERNAL->value]); + ->tag('collector', ['type' => CollectorType::TYPE_PHP_INTERNAL->value]) + ; $services ->set(ComposerCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_COMPOSER->value]); + ->tag('collector', ['type' => CollectorType::TYPE_COMPOSER->value]) + ; /* * Analyser @@ -323,53 +369,66 @@ ->args([ '$ignoreUncoveredInternalClasses' => param('ignore_uncovered_internal_classes'), ]) - ->tag('kernel.event_subscriber'); + ->tag('kernel.event_subscriber') + ; $services ->set(MatchingLayersHandler::class) - ->tag('kernel.event_subscriber'); + ->tag('kernel.event_subscriber') + ; $services ->set(LayerProvider::class) ->args([ '$allowedLayers' => param('ruleset'), - ]); + ]) + ; $services ->set(AllowDependencyHandler::class) - ->tag('kernel.event_subscriber'); + ->tag('kernel.event_subscriber') + ; $services ->set(DependsOnDisallowedLayer::class) - ->tag('kernel.event_subscriber'); + ->tag('kernel.event_subscriber') + ; $services ->set(DependsOnPrivateLayer::class) - ->tag('kernel.event_subscriber'); + ->tag('kernel.event_subscriber') + ; $services ->set(DependsOnInternalToken::class) ->tag('kernel.event_subscriber') ->args([ '$config' => param('analyser'), - ]); + ]) + ; $services ->set(UnmatchedSkippedViolations::class) - ->tag('kernel.event_subscriber'); + ->tag('kernel.event_subscriber') + ; $services->set(EventHelper::class) ->args([ '$skippedViolations' => param('skip_violations'), - ]); + ]) + ; $services - ->set(DependencyLayersAnalyser::class); + ->set(DependencyLayersAnalyser::class) + ; $services->set(TokenInLayerAnalyser::class) ->args([ '$config' => param('analyser'), - ]); + ]) + ; $services->set(LayerForTokenAnalyser::class); $services->set(UnassignedTokenAnalyser::class) ->args([ '$config' => param('analyser'), - ]); + ]) + ; $services->set(LayerDependenciesAnalyser::class); $services->set(RulesetUsageAnalyser::class) ->args([ '$layers' => param('layers'), - ]); + ]) + ; /* * OutputFormatter @@ -378,51 +437,66 @@ ->set(FormatterConfiguration::class) ->args([ '$config' => param('formatters'), - ]); + ]) + ; $services ->set(FormatterProvider::class) ->args([ '$formatterLocator' => tagged_locator('output_formatter', null, 'getName'), - ]); + ]) + ; $services ->set(ConsoleOutputFormatter::class) - ->tag('output_formatter'); + ->tag('output_formatter') + ; $services ->set(GithubActionsOutputFormatter::class) - ->tag('output_formatter'); + ->tag('output_formatter') + ; $services ->set(JUnitOutputFormatter::class) - ->tag('output_formatter'); + ->tag('output_formatter') + ; $services ->set(TableOutputFormatter::class) - ->tag('output_formatter'); + ->tag('output_formatter') + ; $services ->set(XMLOutputFormatter::class) - ->tag('output_formatter'); + ->tag('output_formatter') + ; $services ->set(BaselineOutputFormatter::class) - ->tag('output_formatter'); + ->tag('output_formatter') + ; $services ->set(JsonOutputFormatter::class) - ->tag('output_formatter'); + ->tag('output_formatter') + ; $services ->set(GraphVizOutputDisplayFormatter::class) - ->tag('output_formatter'); + ->tag('output_formatter') + ; $services ->set(GraphVizOutputImageFormatter::class) - ->tag('output_formatter'); + ->tag('output_formatter') + ; $services ->set(GraphVizOutputDotFormatter::class) - ->tag('output_formatter'); + ->tag('output_formatter') + ; $services ->set(GraphVizOutputHtmlFormatter::class) - ->tag('output_formatter'); + ->tag('output_formatter') + ; $services ->set(CodeclimateOutputFormatter::class) - ->tag('output_formatter'); + ->tag('output_formatter') + ; $services ->set(MermaidJSOutputFormatter::class) - ->tag('output_formatter'); + ->tag('output_formatter') + ; /* * Console @@ -430,57 +504,72 @@ $services ->set(InitCommand::class) ->autowire() - ->tag('console.command'); + ->tag('console.command') + ; $services ->set(AnalyseRunner::class) - ->autowire(); + ->autowire() + ; $services ->set(AnalyseCommand::class) ->autowire() - ->tag('console.command'); + ->tag('console.command') + ; $services ->set(ChangedFilesRunner::class) - ->autowire(); + ->autowire() + ; $services ->set(ChangedFilesCommand::class) ->autowire() - ->tag('console.command'); + ->tag('console.command') + ; $services ->set(DebugLayerRunner::class) ->autowire() ->args([ '$layers' => param('layers'), - ]); + ]) + ; $services ->set(DebugLayerCommand::class) ->autowire() - ->tag('console.command'); + ->tag('console.command') + ; $services ->set(DebugTokenRunner::class) - ->autowire(); + ->autowire() + ; $services ->set(DebugTokenCommand::class) ->autowire() - ->tag('console.command'); + ->tag('console.command') + ; $services ->set(DebugUnassignedRunner::class) - ->autowire(); + ->autowire() + ; $services ->set(DebugUnassignedCommand::class) ->autowire() - ->tag('console.command'); + ->tag('console.command') + ; $services ->set(DebugDependenciesRunner::class) - ->autowire(); + ->autowire() + ; $services ->set(DebugDependenciesCommand::class) ->autowire() - ->tag('console.command'); + ->tag('console.command') + ; $services ->set(DebugUnusedRunner::class) - ->autowire(); + ->autowire() + ; $services ->set(DebugUnusedCommand::class) ->autowire() - ->tag('console.command'); + ->tag('console.command') + ; }; diff --git a/src/Contract/Config/Collector/BoolConfig.php b/src/Contract/Config/Collector/BoolConfig.php index 207043ce..014c2a8e 100644 --- a/src/Contract/Config/Collector/BoolConfig.php +++ b/src/Contract/Config/Collector/BoolConfig.php @@ -25,7 +25,8 @@ public static function create(array $must = [], array $mostNot = []): self { return (new self()) ->must(...$must) - ->mustNot(...$mostNot); + ->mustNot(...$mostNot) + ; } public function mustNot(CollectorConfig ...$collectorConfigs): self diff --git a/src/Core/InputCollector/FileInputCollector.php b/src/Core/InputCollector/FileInputCollector.php index f8823f11..45b0a12f 100644 --- a/src/Core/InputCollector/FileInputCollector.php +++ b/src/Core/InputCollector/FileInputCollector.php @@ -64,7 +64,8 @@ public function collect(): array ->ignoreUnreadableDirs() ->ignoreVCS(true) ->notPath($this->excludedFilePatterns) - ->sortByName(); + ->sortByName() + ; $customFilterIterator = $finder->getIterator(); } catch (LogicException|DirectoryNotFoundException $exception) { diff --git a/src/Supportive/DependencyInjection/Configuration.php b/src/Supportive/DependencyInjection/Configuration.php index 43aa84b0..ece50320 100644 --- a/src/Supportive/DependencyInjection/Configuration.php +++ b/src/Supportive/DependencyInjection/Configuration.php @@ -55,7 +55,8 @@ private function appendAnalysedPaths(ArrayNodeDefinition $node): void ->defaultValue('src/') ->end() ->end() - ->end(); + ->end() + ; } private function appendExcludePatterns(ArrayNodeDefinition $node): void @@ -70,7 +71,8 @@ private function appendExcludePatterns(ArrayNodeDefinition $node): void ->cannotBeEmpty() ->end() ->end() - ->end(); + ->end() + ; } private function appendLayers(ArrayNodeDefinition $node): void @@ -105,7 +107,8 @@ private function appendLayers(ArrayNodeDefinition $node): void ->end() ->end() ->end() - ->end(); + ->end() + ; } private function appendRuleset(ArrayNodeDefinition $node): void @@ -118,7 +121,8 @@ private function appendRuleset(ArrayNodeDefinition $node): void ->scalarPrototype()->end() ->end() ->end() - ->end(); + ->end() + ; } private function appendSkippedViolations(ArrayNodeDefinition $node): void @@ -133,7 +137,8 @@ private function appendSkippedViolations(ArrayNodeDefinition $node): void ->scalarPrototype()->end() ->end() ->end() - ->end(); + ->end() + ; } /** @@ -209,7 +214,8 @@ private function appendFormatters(ArrayNodeDefinition $node): void ->end() ->end() ->end() - ->end(); + ->end() + ; } /** @@ -240,7 +246,8 @@ private function appendEmitterTypes(ArrayNodeDefinition $node): void ->end() ->end() ->end() - ->end(); + ->end() + ; } private function appendIgnoreUncoveredInternalClasses(ArrayNodeDefinition $node): void @@ -250,7 +257,8 @@ private function appendIgnoreUncoveredInternalClasses(ArrayNodeDefinition $node) ->booleanNode('ignore_uncovered_internal_classes') ->defaultTrue() ->end() - ->end(); + ->end() + ; } private function appendCacheFile(ArrayNodeDefinition $node): void @@ -260,6 +268,7 @@ private function appendCacheFile(ArrayNodeDefinition $node): void ->scalarNode('cache_file') ->defaultValue('.deptrac.cache') ->end() - ->end(); + ->end() + ; } } diff --git a/src/Supportive/OutputFormatter/GraphVizOutputFormatter.php b/src/Supportive/OutputFormatter/GraphVizOutputFormatter.php index 36b18c6a..4e972d97 100644 --- a/src/Supportive/OutputFormatter/GraphVizOutputFormatter.php +++ b/src/Supportive/OutputFormatter/GraphVizOutputFormatter.php @@ -185,7 +185,8 @@ private function addNodesToGraph(Graph $graph, array $nodes, ConfigurationGraphV { foreach ($outputConfig->groupsLayerMap as $groupName => $groupLayerNames) { $subgraph = Graph::create($this->getSubgraphName($groupName)) - ->setAttribute('label', $groupName); + ->setAttribute('label', $groupName) + ; $graph->addGraph($subgraph); foreach ($groupLayerNames as $groupLayerName) { diff --git a/tests/Core/Ast/AstMapFlattenGeneratorTest.php b/tests/Core/Ast/AstMapFlattenGeneratorTest.php index 86b24a8d..dd5bdf55 100644 --- a/tests/Core/Ast/AstMapFlattenGeneratorTest.php +++ b/tests/Core/Ast/AstMapFlattenGeneratorTest.php @@ -275,7 +275,8 @@ public function testSkipsErrorsAndDisptachesErrorEventAndReturnsEmptyAstMap(): v ->expects(self::atLeastOnce()) ->method('parseFile') ->with(__DIR__.'/Fixtures/BasicInheritance/FixtureBasicInheritanceWithNoise.php') - ->willThrowException(new CouldNotParseFileException('Syntax Error')); + ->willThrowException(new CouldNotParseFileException('Syntax Error')) + ; $astLoader->createAstMap([__DIR__.'/Fixtures/BasicInheritance/FixtureBasicInheritanceWithNoise.php']); @@ -292,7 +293,8 @@ public function testThrowsOtherExceptions(): void ->expects(self::atLeastOnce()) ->method('parseFile') ->with(__DIR__.'/Fixtures/BasicInheritance/FixtureBasicInheritanceWithNoise.php') - ->willThrowException(new LogicException('Uncaught exception')); + ->willThrowException(new LogicException('Uncaught exception')) + ; $this->expectException(LogicException::class); $this->expectExceptionMessage('Uncaught exception'); diff --git a/tests/Core/Layer/Collector/AttributeCollectorTest.php b/tests/Core/Layer/Collector/AttributeCollectorTest.php index d2866793..2c2f7e9c 100644 --- a/tests/Core/Layer/Collector/AttributeCollectorTest.php +++ b/tests/Core/Layer/Collector/AttributeCollectorTest.php @@ -44,7 +44,8 @@ public function testSatisfy(array $config, bool $expected): void ->newClass('App\Foo', [], []) ->attribute('App\MyAttribute', 2) ->attribute('MyAttribute', 3) - ->build(); + ->build() + ; $actual = $this->collector->satisfy($config, $classLikeReference); self::assertSame($expected, $actual); diff --git a/tests/Core/Layer/Collector/BoolCollectorTest.php b/tests/Core/Layer/Collector/BoolCollectorTest.php index f3ca7582..ac83e6e1 100644 --- a/tests/Core/Layer/Collector/BoolCollectorTest.php +++ b/tests/Core/Layer/Collector/BoolCollectorTest.php @@ -25,13 +25,15 @@ protected function setUp(): void $collector ->method('satisfy') ->with($this->callback(static fn (array $config): bool => 'custom' === $config['type'])) - ->willReturnCallback(static fn (array $config): bool => (bool) $config['satisfy'] ?? false); + ->willReturnCallback(static fn (array $config): bool => (bool) $config['satisfy'] ?? false) + ; $resolver = $this->createMock(CollectorResolverInterface::class); $resolver ->method('resolve') ->with($this->callback(static fn (array $config): bool => 'custom' === $config['type'])) - ->willReturnCallback(static fn (array $config): Collectable => new Collectable($collector, $config)); + ->willReturnCallback(static fn (array $config): Collectable => new Collectable($collector, $config)) + ; $this->collector = new BoolCollector($resolver); } diff --git a/tests/Core/Layer/Collector/ExtendsCollectorTest.php b/tests/Core/Layer/Collector/ExtendsCollectorTest.php index e146881b..87d17d34 100644 --- a/tests/Core/Layer/Collector/ExtendsCollectorTest.php +++ b/tests/Core/Layer/Collector/ExtendsCollectorTest.php @@ -29,13 +29,15 @@ public function testSatisfy(array $configuration, bool $expected): void $fooFileReferenceBuilder = FileReferenceBuilder::create('foo.php'); $fooFileReferenceBuilder ->newClassLike('App\Foo', [], []) - ->implements('App\Bar', 2); + ->implements('App\Bar', 2) + ; $fooFileReference = $fooFileReferenceBuilder->build(); $barFileReferenceBuilder = FileReferenceBuilder::create('bar.php'); $barFileReferenceBuilder ->newClassLike('App\Bar', [], []) - ->implements('App\Baz', 2); + ->implements('App\Baz', 2) + ; $barFileReference = $barFileReferenceBuilder->build(); $bazFileReferenceBuilder = FileReferenceBuilder::create('baz.php'); @@ -44,20 +46,23 @@ public function testSatisfy(array $configuration, bool $expected): void $fizTraitFileReferenceBuilder = FileReferenceBuilder::create('fiztrait.php'); $fizTraitFileReferenceBuilder - ->newClassLike('App\FizTrait', [], []); + ->newClassLike('App\FizTrait', [], []) + ; $fizTraitFileReference = $fizTraitFileReferenceBuilder->build(); $fooBarFileReferenceBuilder = FileReferenceBuilder::create('foobar.php'); $fooBarFileReferenceBuilder ->newClassLike('App\FooBar', [], []) ->extends('App\Foo', 2) - ->trait('App\FizTrait', 4); + ->trait('App\FizTrait', 4) + ; $fooBarFileReference = $fooBarFileReferenceBuilder->build(); $astMap = new AstMap([$fooFileReference, $barFileReference, $bazFileReference, $fooBarFileReference, $fizTraitFileReference]); $astMapExtractor = $this->createMock(AstMapExtractor::class); $astMapExtractor->method('extract') - ->willReturn($astMap); + ->willReturn($astMap) + ; $collector = new ExtendsCollector($astMapExtractor); $actual = $collector->satisfy( diff --git a/tests/Core/Layer/Collector/ImplementsCollectorTest.php b/tests/Core/Layer/Collector/ImplementsCollectorTest.php index 0532bb48..f2293606 100644 --- a/tests/Core/Layer/Collector/ImplementsCollectorTest.php +++ b/tests/Core/Layer/Collector/ImplementsCollectorTest.php @@ -29,13 +29,15 @@ public function testSatisfy(array $configuration, bool $expected): void $fooFileReferenceBuilder = FileReferenceBuilder::create('foo.php'); $fooFileReferenceBuilder ->newClassLike('App\Foo', [], []) - ->implements('App\Bar', 2); + ->implements('App\Bar', 2) + ; $fooFileReference = $fooFileReferenceBuilder->build(); $barFileReferenceBuilder = FileReferenceBuilder::create('bar.php'); $barFileReferenceBuilder ->newClassLike('App\Bar', [], []) - ->implements('App\Baz', 2); + ->implements('App\Baz', 2) + ; $barFileReference = $barFileReferenceBuilder->build(); $bazFileReferenceBuilder = FileReferenceBuilder::create('baz.php'); @@ -44,14 +46,16 @@ public function testSatisfy(array $configuration, bool $expected): void $fizTraitFileReferenceBuilder = FileReferenceBuilder::create('fiztrait.php'); $fizTraitFileReferenceBuilder - ->newClassLike('App\FizTrait', [], []); + ->newClassLike('App\FizTrait', [], []) + ; $fizTraitFileReference = $fizTraitFileReferenceBuilder->build(); $fooBarFileReferenceBuilder = FileReferenceBuilder::create('foobar.php'); $fooBarFileReferenceBuilder ->newClassLike('App\FooBar', [], []) ->extends('App\Foo', 2) - ->trait('App\FizTrait', 4); + ->trait('App\FizTrait', 4) + ; $fooBarFileReference = $fooBarFileReferenceBuilder->build(); $astMap = new AstMap( @@ -59,7 +63,8 @@ public function testSatisfy(array $configuration, bool $expected): void ); $astMapExtractor = $this->createMock(AstMapExtractor::class); $astMapExtractor->method('extract') - ->willReturn($astMap); + ->willReturn($astMap) + ; $collector = new ImplementsCollector($astMapExtractor); $actual = $collector->satisfy( diff --git a/tests/Core/Layer/Collector/InheritanceLevelCollectorTest.php b/tests/Core/Layer/Collector/InheritanceLevelCollectorTest.php index 3b1f415d..69330415 100644 --- a/tests/Core/Layer/Collector/InheritanceLevelCollectorTest.php +++ b/tests/Core/Layer/Collector/InheritanceLevelCollectorTest.php @@ -33,16 +33,19 @@ public function testSatisfy(int $pathLevel, int $levelConfig, bool $expected): v { $classInherit = $this->createMock(AstInherit::class); $classInherit->method('getPath') - ->willReturn(array_fill(0, $pathLevel, 1)); + ->willReturn(array_fill(0, $pathLevel, 1)) + ; $astMap = $this->createMock(AstMap::class); $astMap->method('getClassInherits') ->with(ClassLikeToken::fromFQCN(AstInherit::class)) - ->willReturn([$classInherit]); + ->willReturn([$classInherit]) + ; $astMapExtractor = $this->createMock(AstMapExtractor::class); $astMapExtractor->method('extract') - ->willReturn($astMap); + ->willReturn($astMap) + ; $collector = new InheritanceLevelCollector($astMapExtractor); $actual = $collector->satisfy( diff --git a/tests/Core/Layer/Collector/InheritsCollectorTest.php b/tests/Core/Layer/Collector/InheritsCollectorTest.php index 95787bb9..46c23fca 100644 --- a/tests/Core/Layer/Collector/InheritsCollectorTest.php +++ b/tests/Core/Layer/Collector/InheritsCollectorTest.php @@ -29,13 +29,15 @@ public function testSatisfy(array $configuration, bool $expected): void $fooFileReferenceBuilder = FileReferenceBuilder::create('foo.php'); $fooFileReferenceBuilder ->newClassLike('App\Foo', [], []) - ->implements('App\Bar', 2); + ->implements('App\Bar', 2) + ; $fooFileReference = $fooFileReferenceBuilder->build(); $barFileReferenceBuilder = FileReferenceBuilder::create('bar.php'); $barFileReferenceBuilder ->newClassLike('App\Bar', [], []) - ->implements('App\Baz', 2); + ->implements('App\Baz', 2) + ; $barFileReference = $barFileReferenceBuilder->build(); $bazFileReferenceBuilder = FileReferenceBuilder::create('baz.php'); @@ -44,14 +46,16 @@ public function testSatisfy(array $configuration, bool $expected): void $fizTraitFileReferenceBuilder = FileReferenceBuilder::create('fiztrait.php'); $fizTraitFileReferenceBuilder - ->newClassLike('App\FizTrait', [], []); + ->newClassLike('App\FizTrait', [], []) + ; $fizTraitFileReference = $fizTraitFileReferenceBuilder->build(); $fooBarFileReferenceBuilder = FileReferenceBuilder::create('foobar.php'); $fooBarFileReferenceBuilder ->newClassLike('App\FooBar', [], []) ->extends('App\Foo', 2) - ->trait('App\FizTrait', 4); + ->trait('App\FizTrait', 4) + ; $fooBarFileReference = $fooBarFileReferenceBuilder->build(); $astMap = new AstMap( @@ -59,7 +63,8 @@ public function testSatisfy(array $configuration, bool $expected): void ); $astMapExtractor = $this->createMock(AstMapExtractor::class); $astMapExtractor->method('extract') - ->willReturn($astMap); + ->willReturn($astMap) + ; $collector = new InheritsCollector($astMapExtractor); $actual = $collector->satisfy( diff --git a/tests/Core/Layer/Collector/LayerCollectorTest.php b/tests/Core/Layer/Collector/LayerCollectorTest.php index b17eeca5..2edf39ad 100644 --- a/tests/Core/Layer/Collector/LayerCollectorTest.php +++ b/tests/Core/Layer/Collector/LayerCollectorTest.php @@ -43,7 +43,8 @@ public function testSatisfyWithUnknownLayer(): void ->expects($this->once()) ->method('has') ->with('test') - ->willReturn(false); + ->willReturn(false) + ; $this->expectException(InvalidCollectorDefinitionException::class); $this->expectExceptionMessage('Unknown layer "test" specified in collector.'); @@ -60,13 +61,15 @@ public function testCircularReference(): void $this->resolver ->method('has') ->with('FooLayer') - ->willReturn(true); + ->willReturn(true) + ; $this->resolver ->method('isReferenceInLayer') ->with('FooLayer', $reference) ->willReturnCallback(function (string $layerName, ClassLikeReference $reference) { return $this->collector->satisfy(['value' => 'FooLayer'], $reference); - }); + }) + ; $this->expectException(InvalidLayerDefinitionException::class); $this->expectExceptionMessage('Circular dependency between layers detected. Token "App\Foo" could not be resolved.'); @@ -83,11 +86,13 @@ public function testSatisfyWhenReferenceIsInLayer(): void $this->resolver ->method('has') ->with('AppLayer') - ->willReturn(true); + ->willReturn(true) + ; $this->resolver ->method('isReferenceInLayer') ->with('AppLayer', $reference) - ->willReturn(true); + ->willReturn(true) + ; $actual = $this->collector->satisfy( ['value' => 'AppLayer'], @@ -103,11 +108,13 @@ public function testSatisfyWhenReferenceIsNotInLayer(): void $this->resolver ->method('has') ->with('AppLayer') - ->willReturn(true); + ->willReturn(true) + ; $this->resolver ->method('isReferenceInLayer') ->with('AppLayer', $reference) - ->willReturn(false); + ->willReturn(false) + ; $actual = $this->collector->satisfy( ['value' => 'AppLayer'], diff --git a/tests/Core/Layer/Collector/MethodCollectorTest.php b/tests/Core/Layer/Collector/MethodCollectorTest.php index 5ae05c23..d8adbfa1 100644 --- a/tests/Core/Layer/Collector/MethodCollectorTest.php +++ b/tests/Core/Layer/Collector/MethodCollectorTest.php @@ -70,7 +70,8 @@ public function testSatisfy(array $configuration, array $methods, bool $expected $this->astParser ->method('getNodeForClassLikeReference') ->with($astClassReference) - ->willReturn($classLike); + ->willReturn($classLike) + ; $actual = $this->collector->satisfy( $configuration, @@ -86,7 +87,8 @@ public function testClassLikeAstNotFoundDoesNotSatisfy(): void $this->astParser ->method('getNodeForClassLikeReference') ->with($astClassReference) - ->willReturn(null); + ->willReturn(null) + ; $actual = $this->collector->satisfy( ['value' => 'abc'], diff --git a/tests/Core/Layer/Collector/UsesCollectorTest.php b/tests/Core/Layer/Collector/UsesCollectorTest.php index d9f63104..b1044f2d 100644 --- a/tests/Core/Layer/Collector/UsesCollectorTest.php +++ b/tests/Core/Layer/Collector/UsesCollectorTest.php @@ -29,13 +29,15 @@ public function testSatisfy(array $configuration, bool $expected): void $fooFileReferenceBuilder = FileReferenceBuilder::create('foo.php'); $fooFileReferenceBuilder ->newClassLike('App\Foo', [], []) - ->implements('App\Bar', 2); + ->implements('App\Bar', 2) + ; $fooFileReference = $fooFileReferenceBuilder->build(); $barFileReferenceBuilder = FileReferenceBuilder::create('bar.php'); $barFileReferenceBuilder ->newClassLike('App\Bar', [], []) - ->implements('App\Baz', 2); + ->implements('App\Baz', 2) + ; $barFileReference = $barFileReferenceBuilder->build(); $bazFileReferenceBuilder = FileReferenceBuilder::create('baz.php'); @@ -44,14 +46,16 @@ public function testSatisfy(array $configuration, bool $expected): void $fizTraitFileReferenceBuilder = FileReferenceBuilder::create('fiztrait.php'); $fizTraitFileReferenceBuilder - ->newClassLike('App\FizTrait', [], []); + ->newClassLike('App\FizTrait', [], []) + ; $fizTraitFileReference = $fizTraitFileReferenceBuilder->build(); $fooBarFileReferenceBuilder = FileReferenceBuilder::create('foobar.php'); $fooBarFileReferenceBuilder ->newClassLike('App\FooBar', [], []) ->extends('App\Foo', 2) - ->trait('App\FizTrait', 4); + ->trait('App\FizTrait', 4) + ; $fooBarFileReference = $fooBarFileReferenceBuilder->build(); $astMap = new AstMap( @@ -59,7 +63,8 @@ public function testSatisfy(array $configuration, bool $expected): void ); $astMapExtractor = $this->createMock(AstMapExtractor::class); $astMapExtractor->method('extract') - ->willReturn($astMap); + ->willReturn($astMap) + ; $collector = new UsesCollector($astMapExtractor); diff --git a/tests/Core/Layer/LayerResolverTest.php b/tests/Core/Layer/LayerResolverTest.php index 9ae5fdb7..9836187d 100644 --- a/tests/Core/Layer/LayerResolverTest.php +++ b/tests/Core/Layer/LayerResolverTest.php @@ -189,13 +189,15 @@ private function buildCollectorResolverWithFakeCollector(): CollectorResolverInt $collector ->method('satisfy') ->with($this->callback(static fn (array $config): bool => 'custom' === $config['type'])) - ->willReturnCallback(static fn (array $config): bool => (bool) $config['satisfy'] ?? false); + ->willReturnCallback(static fn (array $config): bool => (bool) $config['satisfy'] ?? false) + ; $resolver = $this->createMock(CollectorResolverInterface::class); $resolver ->method('resolve') ->with($this->callback(static fn (array $config): bool => 'custom' === $config['type'])) - ->willReturnCallback(static fn (array $config): Collectable => new Collectable($collector, $config)); + ->willReturnCallback(static fn (array $config): Collectable => new Collectable($collector, $config)) + ; return $resolver; }