From cd5573de51f76b515124bff93a69b73f57f5b3e8 Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Thu, 23 Mar 2023 09:59:05 +0100 Subject: [PATCH] Move compiling into a pipeline The compiler was introduced before we had pipelines, and to make maintenance simpler and more uniform I had moved the compiling steps into a pipeline. In addition, an extra decorator was added that will log the start, end and execution time for each stage. This will be visible when running phpDocumentor in verbose mode. --- config/pipelines.yaml | 17 ++- config/services.yaml | 77 +------------ config/stages.yaml | 109 ++++++++++++++++++ psalm.xml | 6 - src/phpDocumentor/Compiler/Compiler.php | 41 ------- .../Compiler/CompilerPassInterface.php | 6 +- src/phpDocumentor/Compiler/Linker/Linker.php | 8 +- src/phpDocumentor/Compiler/Pass/Debug.php | 6 +- .../Compiler/Pass/ElementsIndexBuilder.php | 6 +- .../Compiler/Pass/GuidesCompiler.php | 6 +- .../Compiler/Pass/MarkerFromTagsExtractor.php | 6 +- .../Compiler/Pass/NamespaceTreeBuilder.php | 10 +- .../Compiler/Pass/PackageTreeBuilder.php | 5 +- .../Compiler/Pass/RemoveSourcecode.php | 6 +- .../Compiler/Pass/ResolveInlineMarkers.php | 6 +- .../Compiler/Pass/TableOfContentsBuilder.php | 4 +- .../Compiler/Pass/UsedByBuilder.php | 6 +- .../Interfaces/ProjectInterface.php | 15 +++ .../Pipeline/PipelineFactory.php | 13 ++- src/phpDocumentor/Pipeline/Stage/Compile.php | 15 +-- .../Pipeline/Stage/TimedStageDecorator.php | 54 +++++++++ .../phpDocumentor/Compiler/CompilerTest.php | 47 -------- .../Compiler/Linker/LinkerTest.php | 4 +- .../phpDocumentor/Compiler/Pass/DebugTest.php | 4 +- .../Pass/ElementsIndexBuilderTest.php | 32 ++--- .../Pass/MarkerFromTagsExtractorTest.php | 8 +- .../Pass/NamespaceTreeBuilderTest.php | 24 ++-- .../Compiler/Pass/PackageTreeBuilderTest.php | 64 +++++----- .../Compiler/Pass/RemoveSourcecodeTest.php | 8 +- .../Pass/ResolveInlineMarkersTest.php | 2 +- .../Pass/TableOfContentsBuilderTest.php | 4 +- .../Compiler/Pass/UsedByBuilderTest.php | 2 +- .../Pipeline/PipelineFactoryTest.php | 5 +- 33 files changed, 336 insertions(+), 290 deletions(-) delete mode 100644 src/phpDocumentor/Compiler/Compiler.php create mode 100644 src/phpDocumentor/Pipeline/Stage/TimedStageDecorator.php delete mode 100644 tests/unit/phpDocumentor/Compiler/CompilerTest.php diff --git a/config/pipelines.yaml b/config/pipelines.yaml index 72268e20d3..04a99cb1f9 100644 --- a/config/pipelines.yaml +++ b/config/pipelines.yaml @@ -1,33 +1,40 @@ services: + phpDocumentor\Pipeline\PipelineFactory: ~ + # Will call all pipeline and stages tagged with 'phpdoc.pipeline.api_documentation.generate', # this includes both the parse and transform pipeline phpdoc.complete.pipeline: class: 'League\Pipeline\Pipeline' - factory: ['phpDocumentor\Pipeline\PipelineFactory', 'create'] + factory: ['@phpDocumentor\Pipeline\PipelineFactory', 'create'] arguments: [!tagged phpdoc.pipeline.api_documentation.generate] phpdoc.configuration.pipeline: class: 'League\Pipeline\Pipeline' - factory: ['phpDocumentor\Pipeline\PipelineFactory', 'create'] + factory: ['@phpDocumentor\Pipeline\PipelineFactory', 'create'] arguments: [!tagged phpdoc.pipeline.application.configuration] tags: - { name: 'phpdoc.pipeline.api_documentation.generate', priority: 10000 } phpdoc.parse.pipeline: class: 'League\Pipeline\Pipeline' - factory: ['phpDocumentor\Pipeline\PipelineFactory', 'create'] + factory: ['@phpDocumentor\Pipeline\PipelineFactory', 'create'] arguments: [!tagged phpdoc.pipeline.api_documentation.parse] tags: - { name: 'phpdoc.pipeline.api_documentation.generate', priority: 8000 } phpdoc.parse_api_documentation_set.pipeline: class: 'League\Pipeline\Pipeline' - factory: ['phpDocumentor\Pipeline\PipelineFactory', 'create'] + factory: ['@phpDocumentor\Pipeline\PipelineFactory', 'create'] arguments: [!tagged phpdoc.pipeline.api_documentation.parse_api_documentation_set] + phpdoc.compile.pipeline: + class: 'League\Pipeline\Pipeline' + factory: ['@phpDocumentor\Pipeline\PipelineFactory', 'create'] + arguments: [!tagged phpdoc.pipeline.api_documentation.compile] + phpdoc.transform.pipeline: class: 'League\Pipeline\Pipeline' - factory: ['phpDocumentor\Pipeline\PipelineFactory', 'create'] + factory: ['@phpDocumentor\Pipeline\PipelineFactory', 'create'] arguments: [!tagged phpdoc.pipeline.api_documentation.transform] tags: - { name: 'phpdoc.pipeline.api_documentation.generate', priority: 5000 } diff --git a/config/services.yaml b/config/services.yaml index 18ec0acc1a..a13a036b60 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -4,61 +4,6 @@ imports: - { resource: 'stages.yaml' } - { resource: 'guides.yaml' } -parameters: - linker.substitutions: - 'phpDocumentor\Descriptor\ProjectDescriptor': ['files'] - 'phpDocumentor\Descriptor\FileDescriptor': - - 'tags' - - 'classes' - - 'interfaces' - - 'traits' - - 'functions' - - 'constants' - 'phpDocumentor\Descriptor\ClassDescriptor': - - 'tags' - - 'parent' - - 'interfaces' - - 'constants' - - 'properties' - - 'methods' - - 'usedTraits' - 'phpDocumentor\Descriptor\InterfaceDescriptor': - - 'tags' - - 'parent' - - 'constants' - - 'methods' - 'phpDocumentor\Descriptor\TraitDescriptor': - - 'tags' - - 'properties' - - 'methods' - - 'usedTraits' - 'phpDocumentor\Descriptor\EnumDescriptor': - - 'tags' - - 'interfaces' - - 'cases' - - 'methods' - - 'usedTraits' - 'phpDocumentor\Descriptor\FunctionDescriptor': - - 'tags' - - 'arguments' - 'phpDocumentor\Descriptor\MethodDescriptor': - - 'tags' - - 'arguments' - 'phpDocumentor\Descriptor\ArgumentDescriptor': - - 'type' - 'phpDocumentor\Descriptor\PropertyDescriptor': - - 'tags' - - 'type' - 'phpDocumentor\Descriptor\ConstantDescriptor': - - 'tags' - - 'type' - 'phpDocumentor\Descriptor\Tag\ParamDescriptor': ['type'] - 'phpDocumentor\Descriptor\Tag\VarDescriptor': ['type'] - 'phpDocumentor\Descriptor\Tag\ReturnDescriptor': ['type'] - 'phpDocumentor\Descriptor\Tag\SeeDescriptor': ['reference'] - 'phpDocumentor\Descriptor\Tag\UsesDescriptor': ['reference'] - 'phpDocumentor\Descriptor\Tag\UsedByDescriptor': ['reference'] - services: _defaults: autowire: true @@ -90,6 +35,8 @@ services: phpDocumentor\: resource: '../src/phpDocumentor/*' exclude: + - '../src/phpDocumentor/Linker/Linker' + - '../src/phpDocumentor/Compiler' - '../src/phpDocumentor/**/Messages' - '../src/phpDocumentor/Pipeline/Stage' - '../src/phpDocumentor/Transformer/**/{Event, Exception}/{**}' @@ -111,9 +58,6 @@ services: resource: '../src/phpDocumentor/Transformer' exclude: '../src/phpDocumentor/Transformer/**/{Event, Exception}/{**}' - phpDocumentor\Compiler\: - resource: '../src/phpDocumentor/Compiler' - ################################################################################### ## Autoloading definitions for individual classes ################################# ################################################################################### @@ -160,23 +104,6 @@ services: '2': '@phpDocumentor\Configuration\Definition\Version2' '3': '@phpDocumentor\Configuration\Definition\Version3' - phpDocumentor\Compiler\Linker\Linker: - arguments: ['%linker.substitutions%'] - - phpDocumentor\Compiler\Compiler: - calls: - - [insert, ['@phpDocumentor\Compiler\Pass\GuidesCompiler', 3000]] - - [insert, ['@phpDocumentor\Compiler\Pass\TableOfContentsBuilder', 2000]] - - [insert, ['@phpDocumentor\Compiler\Pass\ElementsIndexBuilder', !php/const \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::COMPILER_PRIORITY]] - - [insert, ['@phpDocumentor\Compiler\Pass\MarkerFromTagsExtractor', !php/const \phpDocumentor\Compiler\Pass\MarkerFromTagsExtractor::COMPILER_PRIORITY]] - - [insert, ['@phpDocumentor\Compiler\Pass\PackageTreeBuilder', !php/const \phpDocumentor\Compiler\Pass\PackageTreeBuilder::COMPILER_PRIORITY]] - - [insert, ['@phpDocumentor\Compiler\Pass\NamespaceTreeBuilder', !php/const \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::COMPILER_PRIORITY]] - - [insert, ['@phpDocumentor\Compiler\Pass\ResolveInlineMarkers', !php/const \phpDocumentor\Compiler\Pass\ResolveInlineMarkers::COMPILER_PRIORITY]] - - [insert, ['@phpDocumentor\Compiler\Pass\UsedByBuilder', !php/const \phpDocumentor\Compiler\Pass\ResolveInlineMarkers::COMPILER_PRIORITY]] - - [insert, ['@phpDocumentor\Compiler\Pass\Debug', !php/const \phpDocumentor\Compiler\Pass\Debug::COMPILER_PRIORITY]] - - [insert, ['@phpDocumentor\Compiler\Pass\RemoveSourcecode',!php/const \phpDocumentor\Compiler\Pass\RemoveSourcecode::COMPILER_PRIORITY]] - - [insert, ['@phpDocumentor\Compiler\Linker\Linker', !php/const \phpDocumentor\Compiler\Linker\Linker::COMPILER_PRIORITY]] - phpDocumentor\Parser\Parser: ~ phpDocumentor\Reflection\DocBlock\ExampleFinder: ~ diff --git a/config/stages.yaml b/config/stages.yaml index 773559a7f2..047e4dbe1f 100644 --- a/config/stages.yaml +++ b/config/stages.yaml @@ -1,8 +1,66 @@ +parameters: + linker.substitutions: + 'phpDocumentor\Descriptor\ProjectDescriptor': ['files'] + 'phpDocumentor\Descriptor\FileDescriptor': + - 'tags' + - 'classes' + - 'interfaces' + - 'traits' + - 'functions' + - 'constants' + 'phpDocumentor\Descriptor\ClassDescriptor': + - 'tags' + - 'parent' + - 'interfaces' + - 'constants' + - 'properties' + - 'methods' + - 'usedTraits' + 'phpDocumentor\Descriptor\InterfaceDescriptor': + - 'tags' + - 'parent' + - 'constants' + - 'methods' + 'phpDocumentor\Descriptor\TraitDescriptor': + - 'tags' + - 'properties' + - 'methods' + - 'usedTraits' + 'phpDocumentor\Descriptor\EnumDescriptor': + - 'tags' + - 'interfaces' + - 'cases' + - 'methods' + - 'usedTraits' + 'phpDocumentor\Descriptor\FunctionDescriptor': + - 'tags' + - 'arguments' + 'phpDocumentor\Descriptor\MethodDescriptor': + - 'tags' + - 'arguments' + 'phpDocumentor\Descriptor\ArgumentDescriptor': + - 'type' + 'phpDocumentor\Descriptor\PropertyDescriptor': + - 'tags' + - 'type' + 'phpDocumentor\Descriptor\ConstantDescriptor': + - 'tags' + - 'type' + 'phpDocumentor\Descriptor\Tag\ParamDescriptor': ['type'] + 'phpDocumentor\Descriptor\Tag\VarDescriptor': ['type'] + 'phpDocumentor\Descriptor\Tag\ReturnDescriptor': ['type'] + 'phpDocumentor\Descriptor\Tag\SeeDescriptor': ['reference'] + 'phpDocumentor\Descriptor\Tag\UsesDescriptor': ['reference'] + 'phpDocumentor\Descriptor\Tag\UsedByDescriptor': ['reference'] + services: _defaults: autowire: true autoconfigure: true + phpDocumentor\Compiler\: + resource: '../src/phpDocumentor/Compiler' + phpDocumentor\Pipeline\Stage\Configure: arguments: $currentWorkingDir: "@=service('kernel').getWorkingDir()" @@ -61,11 +119,62 @@ services: tags: - { name: 'phpdoc.pipeline.api_documentation.parse_api_documentation_set', priority: 0 } + ################################################################################### + ## Autoloading definitions for compiler stages ################################# + ################################################################################### + + phpDocumentor\Compiler\Pass\ElementsIndexBuilder: + tags: + - { name: 'phpdoc.pipeline.api_documentation.compile', priority: 15000 } + + phpDocumentor\Compiler\Linker\Linker: + arguments: ['%linker.substitutions%'] + tags: + - { name: 'phpdoc.pipeline.api_documentation.compile', priority: 10000 } + + phpDocumentor\Compiler\Pass\PackageTreeBuilder: + tags: + - { name: 'phpdoc.pipeline.api_documentation.compile', priority: 9001 } + + phpDocumentor\Compiler\Pass\MarkerFromTagsExtractor: + tags: + - { name: 'phpdoc.pipeline.api_documentation.compile', priority: 9000 } + + phpDocumentor\Compiler\Pass\NamespaceTreeBuilder: + tags: + - { name: 'phpdoc.pipeline.api_documentation.compile', priority: 9000 } + + phpDocumentor\Compiler\Pass\ResolveInlineMarkers: + tags: + - { name: 'phpdoc.pipeline.api_documentation.compile', priority: 9000 } + + phpDocumentor\Compiler\Pass\UsedByBuilder: + tags: + - { name: 'phpdoc.pipeline.api_documentation.compile', priority: 9000 } + + phpDocumentor\Compiler\Pass\GuidesCompiler: + tags: + - { name: 'phpdoc.pipeline.api_documentation.compile', priority: 3000 } + + phpDocumentor\Compiler\Pass\RemoveSourcecode: + tags: + - { name: 'phpdoc.pipeline.api_documentation.compile', priority: 2000 } + + phpDocumentor\Compiler\Pass\TableOfContentsBuilder: + tags: + - { name: 'phpdoc.pipeline.api_documentation.compile', priority: 2000 } + + phpDocumentor\Compiler\Pass\Debug: + tags: + - { name: 'phpdoc.pipeline.api_documentation.compile', priority: 1000 } + ################################################################################### ## Autoloading definitions for transform stages ################################# ################################################################################### phpDocumentor\Pipeline\Stage\Compile: + arguments: + $compilerPipeline: '@phpdoc.compile.pipeline' tags: - { name: 'phpdoc.pipeline.api_documentation.transform', priority: 5000 } diff --git a/psalm.xml b/psalm.xml index 4251aa7d03..12cbced9e6 100644 --- a/psalm.xml +++ b/psalm.xml @@ -70,12 +70,6 @@ - - - - - - diff --git a/src/phpDocumentor/Compiler/Compiler.php b/src/phpDocumentor/Compiler/Compiler.php deleted file mode 100644 index 42d39760f0..0000000000 --- a/src/phpDocumentor/Compiler/Compiler.php +++ /dev/null @@ -1,41 +0,0 @@ - - */ -class Compiler extends SplPriorityQueue -{ - /** @var int Default priority assigned to Compiler Passes without provided priority */ - public const PRIORITY_DEFAULT = 10000; - - /** - * @param CompilerPassInterface $value - * @param int $priority - * - * @return true - */ - public function insert($value, $priority = self::PRIORITY_DEFAULT): bool - { - Assert::isInstanceOf($value, CompilerPassInterface::class); - - return parent::insert($value, $priority); - } -} diff --git a/src/phpDocumentor/Compiler/CompilerPassInterface.php b/src/phpDocumentor/Compiler/CompilerPassInterface.php index 572b4c4dcd..998fed1b1e 100644 --- a/src/phpDocumentor/Compiler/CompilerPassInterface.php +++ b/src/phpDocumentor/Compiler/CompilerPassInterface.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Compiler; -use phpDocumentor\Descriptor\ProjectDescriptor; +use phpDocumentor\Descriptor\Interfaces\ProjectInterface; /** * Represents a single pass / business rule to be executed by the Compiler. @@ -34,7 +34,7 @@ public function getDescription(): string; * This method will execute the business logic associated with a given compiler pass and allow it to manipulate * or consumer the Object Graph using the ProjectDescriptor object. * - * @param ProjectDescriptor $project Representation of the Object Graph that can be manipulated. + * @param ProjectInterface $project Representation of the Object Graph that can be manipulated. */ - public function execute(ProjectDescriptor $project): void; + public function __invoke(ProjectInterface $project): ProjectInterface; } diff --git a/src/phpDocumentor/Compiler/Linker/Linker.php b/src/phpDocumentor/Compiler/Linker/Linker.php index 55e08936be..ccd4f51d6f 100644 --- a/src/phpDocumentor/Compiler/Linker/Linker.php +++ b/src/phpDocumentor/Compiler/Linker/Linker.php @@ -81,10 +81,12 @@ public function __construct(array $substitutions, DescriptorRepository $descript $this->descriptorRepository = $descriptorRepository; } - public function execute(ProjectInterface $project): void + public function __invoke(ProjectInterface $project): ProjectInterface { $this->descriptorRepository->setObjectAliasesList($project->getIndexes()->get('elements')->getAll()); $this->substitute($project); + + return $project; } /** @@ -122,9 +124,9 @@ public function getSubstitutions(): array * This method will return null if no substitution was possible and all of the above should not update the parent * item when null is passed. * - * @param string|Fqsen|Type|Collection|array|Descriptor $item + * @param string|Fqsen|Type|Collection|array|Descriptor|ProjectInterface $item * - * @return string|DescriptorAbstract|Collection|array|null + * @return string|ProjectInterface|DescriptorAbstract|Collection|array|null */ public function substitute($item, ?DescriptorAbstract $container = null) { diff --git a/src/phpDocumentor/Compiler/Pass/Debug.php b/src/phpDocumentor/Compiler/Pass/Debug.php index 1885c313e3..f70dd050e2 100644 --- a/src/phpDocumentor/Compiler/Pass/Debug.php +++ b/src/phpDocumentor/Compiler/Pass/Debug.php @@ -14,8 +14,8 @@ namespace phpDocumentor\Compiler\Pass; use phpDocumentor\Compiler\CompilerPassInterface; +use phpDocumentor\Descriptor\Interfaces\ProjectInterface; use phpDocumentor\Descriptor\ProjectAnalyzer; -use phpDocumentor\Descriptor\ProjectDescriptor; use Psr\Log\LoggerInterface; /** @@ -48,9 +48,11 @@ public function getDescription(): string return 'Analyze results and write report to log'; } - public function execute(ProjectDescriptor $project): void + public function __invoke(ProjectInterface $project): ProjectInterface { $this->analyzer->analyze($project); $this->log->debug((string) $this->analyzer); + + return $project; } } diff --git a/src/phpDocumentor/Compiler/Pass/ElementsIndexBuilder.php b/src/phpDocumentor/Compiler/Pass/ElementsIndexBuilder.php index b152007fa2..b18c372e91 100644 --- a/src/phpDocumentor/Compiler/Pass/ElementsIndexBuilder.php +++ b/src/phpDocumentor/Compiler/Pass/ElementsIndexBuilder.php @@ -19,8 +19,8 @@ use phpDocumentor\Descriptor\Interfaces\ElementInterface; use phpDocumentor\Descriptor\Interfaces\EnumInterface; use phpDocumentor\Descriptor\Interfaces\InterfaceInterface; +use phpDocumentor\Descriptor\Interfaces\ProjectInterface; use phpDocumentor\Descriptor\Interfaces\TraitInterface; -use phpDocumentor\Descriptor\ProjectDescriptor; use function array_merge; use function is_array; @@ -40,7 +40,7 @@ public function getDescription(): string return 'Build "elements" index'; } - public function execute(ProjectDescriptor $project): void + public function __invoke(ProjectInterface $project): ProjectInterface { $elementCollection = new Collection(); $project->getIndexes()->set('elements', $elementCollection); @@ -76,6 +76,8 @@ public function execute(ProjectDescriptor $project): void $this->addElementsToIndexes($this->getSubElements($element), [$elementCollection]); } } + + return $project; } /** diff --git a/src/phpDocumentor/Compiler/Pass/GuidesCompiler.php b/src/phpDocumentor/Compiler/Pass/GuidesCompiler.php index 49c36d9f6d..3a357a5c7f 100644 --- a/src/phpDocumentor/Compiler/Pass/GuidesCompiler.php +++ b/src/phpDocumentor/Compiler/Pass/GuidesCompiler.php @@ -7,7 +7,7 @@ use phpDocumentor\Compiler\CompilerPassInterface; use phpDocumentor\Descriptor\DocumentDescriptor; use phpDocumentor\Descriptor\GuideSetDescriptor; -use phpDocumentor\Descriptor\ProjectDescriptor; +use phpDocumentor\Descriptor\Interfaces\ProjectInterface; use phpDocumentor\Guides\Compiler\Compiler; use phpDocumentor\Guides\Metas; @@ -29,7 +29,7 @@ public function getDescription(): string return 'Compiling guides'; } - public function execute(ProjectDescriptor $project): void + public function __invoke(ProjectInterface $project): ProjectInterface { foreach ($project->getVersions() as $version) { foreach ($version->getDocumentationSets() as $documentationSet) { @@ -51,5 +51,7 @@ public function execute(ProjectDescriptor $project): void $documentationSet->setMetas(new Metas($this->metas->getAll())); } } + + return $project; } } diff --git a/src/phpDocumentor/Compiler/Pass/MarkerFromTagsExtractor.php b/src/phpDocumentor/Compiler/Pass/MarkerFromTagsExtractor.php index c0dc09f876..393ac0b4a8 100644 --- a/src/phpDocumentor/Compiler/Pass/MarkerFromTagsExtractor.php +++ b/src/phpDocumentor/Compiler/Pass/MarkerFromTagsExtractor.php @@ -17,7 +17,7 @@ use phpDocumentor\Descriptor\Collection; use phpDocumentor\Descriptor\DescriptorAbstract; use phpDocumentor\Descriptor\FileDescriptor; -use phpDocumentor\Descriptor\ProjectDescriptor; +use phpDocumentor\Descriptor\Interfaces\ProjectInterface; use phpDocumentor\Descriptor\TagDescriptor; use UnexpectedValueException; @@ -33,7 +33,7 @@ public function getDescription(): string return 'Collect all markers embedded in tags'; } - public function execute(ProjectDescriptor $project): void + public function __invoke(ProjectInterface $project): ProjectInterface { /** @var DescriptorAbstract $element */ foreach ($project->getIndexes()->fetch('elements', new Collection()) as $element) { @@ -49,6 +49,8 @@ public function execute(ProjectDescriptor $project): void $this->addTodoMarkerToFile($fileDescriptor, $todo, $element->getLine()); } } + + return $project; } /** diff --git a/src/phpDocumentor/Compiler/Pass/NamespaceTreeBuilder.php b/src/phpDocumentor/Compiler/Pass/NamespaceTreeBuilder.php index e521c97953..2743dc8d05 100644 --- a/src/phpDocumentor/Compiler/Pass/NamespaceTreeBuilder.php +++ b/src/phpDocumentor/Compiler/Pass/NamespaceTreeBuilder.php @@ -18,8 +18,8 @@ use phpDocumentor\Descriptor\Collection; use phpDocumentor\Descriptor\Interfaces\ElementInterface; use phpDocumentor\Descriptor\Interfaces\NamespaceInterface; +use phpDocumentor\Descriptor\Interfaces\ProjectInterface; use phpDocumentor\Descriptor\NamespaceDescriptor; -use phpDocumentor\Descriptor\ProjectDescriptor; use phpDocumentor\Reflection\Fqsen; use Webmozart\Assert\Assert; @@ -46,7 +46,7 @@ public function getDescription(): string return 'Build "namespaces" index and add namespaces to "elements"'; } - public function execute(ProjectDescriptor $project): void + public function __invoke(ProjectInterface $project): ProjectInterface { $project->getIndexes()->fetch('elements', new Collection())->set('~\\', $project->getNamespace()); $project->getIndexes()->fetch('namespaces', new Collection())->set('\\', $project->getNamespace()); @@ -68,6 +68,8 @@ public function execute(ProjectDescriptor $project): void $this->addToParentNamespace($project, $namespace); } + + return $project; } /** @@ -81,7 +83,7 @@ public function execute(ProjectDescriptor $project): void * This name will be transformed to a getter which must exist. Out of performance considerations will no effort * be done to verify whether the provided type is valid. */ - protected function addElementsOfTypeToNamespace(ProjectDescriptor $project, array $elements, string $type): void + protected function addElementsOfTypeToNamespace(ProjectInterface $project, array $elements, string $type): void { foreach ($elements as $element) { $namespaceName = (string) $element->getNamespace(); @@ -119,7 +121,7 @@ protected function addElementsOfTypeToNamespace(ProjectDescriptor $project, arra } } - private function addToParentNamespace(ProjectDescriptor $project, NamespaceInterface $namespace): void + private function addToParentNamespace(ProjectInterface $project, NamespaceInterface $namespace): void { /** @var NamespaceInterface|null $parent */ $parent = $project->getIndexes()->fetch( diff --git a/src/phpDocumentor/Compiler/Pass/PackageTreeBuilder.php b/src/phpDocumentor/Compiler/Pass/PackageTreeBuilder.php index 298a37ef08..1549fb02b3 100644 --- a/src/phpDocumentor/Compiler/Pass/PackageTreeBuilder.php +++ b/src/phpDocumentor/Compiler/Pass/PackageTreeBuilder.php @@ -20,7 +20,6 @@ use phpDocumentor\Descriptor\Interfaces\PackageInterface; use phpDocumentor\Descriptor\Interfaces\ProjectInterface; use phpDocumentor\Descriptor\PackageDescriptor; -use phpDocumentor\Descriptor\ProjectDescriptor; use phpDocumentor\Descriptor\TagDescriptor; use phpDocumentor\Parser\Parser; use phpDocumentor\Reflection\Fqsen; @@ -59,7 +58,7 @@ public function getDescription(): string return 'Build "packages" index'; } - public function execute(ProjectDescriptor $project): void + public function __invoke(ProjectInterface $project): ProjectInterface { $package = $project->getPackage(); Assert::isInstanceOf($package, PackageInterface::class); @@ -82,6 +81,8 @@ public function execute(ProjectDescriptor $project): void 'packages', Collection::fromInterfaceString(ElementInterface::class, $packages->getAll()) ); + + return $project; } /** diff --git a/src/phpDocumentor/Compiler/Pass/RemoveSourcecode.php b/src/phpDocumentor/Compiler/Pass/RemoveSourcecode.php index a948aca0c3..549a38e859 100644 --- a/src/phpDocumentor/Compiler/Pass/RemoveSourcecode.php +++ b/src/phpDocumentor/Compiler/Pass/RemoveSourcecode.php @@ -15,7 +15,7 @@ use phpDocumentor\Compiler\CompilerPassInterface; use phpDocumentor\Descriptor\ApiSetDescriptor; -use phpDocumentor\Descriptor\ProjectDescriptor; +use phpDocumentor\Descriptor\Interfaces\ProjectInterface; final class RemoveSourcecode implements CompilerPassInterface { @@ -26,7 +26,7 @@ public function getDescription(): string return 'Removing sourcecode from file descriptors'; } - public function execute(ProjectDescriptor $project): void + public function __invoke(ProjectInterface $project): ProjectInterface { foreach ($project->getVersions() as $version) { foreach ($version->getDocumentationSets() as $documentationSet) { @@ -42,5 +42,7 @@ public function execute(ProjectDescriptor $project): void } } } + + return $project; } } diff --git a/src/phpDocumentor/Compiler/Pass/ResolveInlineMarkers.php b/src/phpDocumentor/Compiler/Pass/ResolveInlineMarkers.php index 93b86bf222..9f63ec1dbc 100644 --- a/src/phpDocumentor/Compiler/Pass/ResolveInlineMarkers.php +++ b/src/phpDocumentor/Compiler/Pass/ResolveInlineMarkers.php @@ -16,7 +16,7 @@ use phpDocumentor\Compiler\CompilerPassInterface; use phpDocumentor\Descriptor\ApiSetDescriptor; use phpDocumentor\Descriptor\FileDescriptor; -use phpDocumentor\Descriptor\ProjectDescriptor; +use phpDocumentor\Descriptor\Interfaces\ProjectInterface; use function implode; use function preg_match_all; @@ -40,7 +40,7 @@ public function getDescription(): string /** * Scans the files for markers and records them in the markers property of a file. */ - public function execute(ProjectDescriptor $project): void + public function __invoke(ProjectInterface $project): ProjectInterface { ///This looks ugly, when versions are introduced we get rid of these 2 foreach loops. foreach ($project->getVersions() as $version) { @@ -78,5 +78,7 @@ public function execute(ProjectDescriptor $project): void } } } + + return $project; } } diff --git a/src/phpDocumentor/Compiler/Pass/TableOfContentsBuilder.php b/src/phpDocumentor/Compiler/Pass/TableOfContentsBuilder.php index 3c6f9ef579..7bc851f63b 100644 --- a/src/phpDocumentor/Compiler/Pass/TableOfContentsBuilder.php +++ b/src/phpDocumentor/Compiler/Pass/TableOfContentsBuilder.php @@ -42,7 +42,7 @@ public function getDescription(): string return 'Builds table of contents for api documentation sets'; } - public function execute(ProjectInterface $project): void + public function __invoke(ProjectInterface $project): ProjectInterface { //This looks ugly, when versions are introduced we get rid of these 2 foreach loops. foreach ($project->getVersions() as $version) { @@ -88,6 +88,8 @@ public function execute(ProjectInterface $project): void $documentationSet->addTableOfContents($guideToc); } } + + return $project; } private function createNamespaceEntries( diff --git a/src/phpDocumentor/Compiler/Pass/UsedByBuilder.php b/src/phpDocumentor/Compiler/Pass/UsedByBuilder.php index a52e3649be..fcd7d4eec2 100644 --- a/src/phpDocumentor/Compiler/Pass/UsedByBuilder.php +++ b/src/phpDocumentor/Compiler/Pass/UsedByBuilder.php @@ -16,7 +16,7 @@ use phpDocumentor\Compiler\CompilerPassInterface; use phpDocumentor\Descriptor\Collection; use phpDocumentor\Descriptor\Interfaces\ElementInterface; -use phpDocumentor\Descriptor\ProjectDescriptor; +use phpDocumentor\Descriptor\Interfaces\ProjectInterface; use phpDocumentor\Descriptor\Tag\UsedByDescriptor; use phpDocumentor\Descriptor\Tag\UsesDescriptor; use phpDocumentor\Descriptor\TagDescriptor; @@ -28,7 +28,7 @@ public function getDescription(): string return 'Creates a link for uses tags on the counter side'; } - public function execute(ProjectDescriptor $project): void + public function __invoke(ProjectInterface $project): ProjectInterface { foreach ($project->getIndexes()->get('elements') as $element) { $uses = $element->getTags()->fetch('uses', Collection::fromClassString(TagDescriptor::class)); @@ -46,5 +46,7 @@ public function execute(ProjectDescriptor $project): void )->add($tag); } } + + return $project; } } diff --git a/src/phpDocumentor/Descriptor/Interfaces/ProjectInterface.php b/src/phpDocumentor/Descriptor/Interfaces/ProjectInterface.php index 136cbc530a..c7c292940f 100644 --- a/src/phpDocumentor/Descriptor/Interfaces/ProjectInterface.php +++ b/src/phpDocumentor/Descriptor/Interfaces/ProjectInterface.php @@ -14,6 +14,7 @@ namespace phpDocumentor\Descriptor\Interfaces; use phpDocumentor\Descriptor\Collection; +use phpDocumentor\Descriptor\VersionDescriptor; /** * Describes the public interface for the description of a project. @@ -25,17 +26,31 @@ public function setName(string $name): void; public function getName(): string; /** + * @deprecated Please use the getFiles method on the DocumentationSet + * * @return Collection */ public function getFiles(): Collection; /** + * @deprecated Please use the getIndexes method on the DocumentationSet + * * @return Collection> */ public function getIndexes(): Collection; + /** + * Returns the package name for this element. + */ + public function getPackage(): ?PackageInterface; + /** * @return NamespaceInterface|string */ public function getNamespace(); + + /** + * @return Collection + */ + public function getVersions(): Collection; } diff --git a/src/phpDocumentor/Pipeline/PipelineFactory.php b/src/phpDocumentor/Pipeline/PipelineFactory.php index 29a1de90d5..e287867420 100644 --- a/src/phpDocumentor/Pipeline/PipelineFactory.php +++ b/src/phpDocumentor/Pipeline/PipelineFactory.php @@ -15,17 +15,26 @@ use League\Pipeline\PipelineBuilder; use League\Pipeline\PipelineInterface; +use phpDocumentor\Pipeline\Stage\TimedStageDecorator; +use Psr\Log\LoggerInterface; final class PipelineFactory { + private LoggerInterface $logger; + + public function __construct(LoggerInterface $logger) + { + $this->logger = $logger; + } + /** * @param iterable $stages */ - public static function create(iterable $stages): PipelineInterface + public function create(iterable $stages): PipelineInterface { $builder = new PipelineBuilder(); foreach ($stages as $stage) { - $builder->add($stage); + $builder->add(new TimedStageDecorator($this->logger, $stage)); } return $builder->build(); diff --git a/src/phpDocumentor/Pipeline/Stage/Compile.php b/src/phpDocumentor/Pipeline/Stage/Compile.php index fc8fef09cf..5ffcf6bbe6 100644 --- a/src/phpDocumentor/Pipeline/Stage/Compile.php +++ b/src/phpDocumentor/Pipeline/Stage/Compile.php @@ -14,23 +14,21 @@ namespace phpDocumentor\Pipeline\Stage; use Exception; -use phpDocumentor\Compiler\Compiler; -use phpDocumentor\Compiler\CompilerPassInterface; +use League\Pipeline\Pipeline; /** * Compiles and links the ast objects into the full ast */ final class Compile { - /** @var Compiler $compiler Collection of pre-transformation actions (Compiler Passes) */ - private $compiler; + private Pipeline $compilerPipeline; /** * Initializes the command with all necessary dependencies to construct human-suitable output from the AST. */ - public function __construct(Compiler $compiler) + public function __construct(Pipeline $compilerPipeline) { - $this->compiler = $compiler; + $this->compilerPipeline = $compilerPipeline; } /** @@ -40,10 +38,7 @@ public function __construct(Compiler $compiler) */ public function __invoke(Payload $payload): Payload { - /** @var CompilerPassInterface $pass */ - foreach ($this->compiler as $pass) { - $pass->execute($payload->getBuilder()->getProjectDescriptor()); - } + $this->compilerPipeline->process($payload->getBuilder()->getProjectDescriptor()); return $payload; } diff --git a/src/phpDocumentor/Pipeline/Stage/TimedStageDecorator.php b/src/phpDocumentor/Pipeline/Stage/TimedStageDecorator.php new file mode 100644 index 0000000000..9c79f7cee9 --- /dev/null +++ b/src/phpDocumentor/Pipeline/Stage/TimedStageDecorator.php @@ -0,0 +1,54 @@ +logger = $logger; + $this->decoratedStage = $decoratedStage; + } + + /** + * Starts a timer before entering the stage, and logs the expired time afterwards. + * + * Since we support any stage, we do not know what payload is received or returned; so both are mixed. + * + * @param mixed $payload + * + * @return mixed + */ + public function __invoke($payload) + { + $stopwatch = new Stopwatch(); + $decoratedStage = $this->decoratedStage; + $name = is_object($decoratedStage) ? get_class($decoratedStage) : 'DYNAMIC'; + + $stopwatch->start($name); + $this->logger->notice(sprintf('Starting stage: %s', $name)); + + try { + $result = $decoratedStage($payload); + } finally { + $event = $stopwatch->stop($name); + $this->logger->notice(sprintf('Completed stage: %s in %d ms', $name, $event->getDuration())); + } + + return $result; + } +} diff --git a/tests/unit/phpDocumentor/Compiler/CompilerTest.php b/tests/unit/phpDocumentor/Compiler/CompilerTest.php deleted file mode 100644 index b03c564351..0000000000 --- a/tests/unit/phpDocumentor/Compiler/CompilerTest.php +++ /dev/null @@ -1,47 +0,0 @@ -fixture = new Compiler(); - } - - /** - * @covers \phpDocumentor\Compiler\Compiler::insert - */ - public function testDefaultPassHasDefaultPriority(): void - { - $this->fixture->insert($this->prophesize(CompilerPassInterface::class)->reveal()); - $this->fixture->setExtractFlags(Compiler::EXTR_PRIORITY); - - $this->assertEquals(Compiler::PRIORITY_DEFAULT, $this->fixture->extract()); - } -} diff --git a/tests/unit/phpDocumentor/Compiler/Linker/LinkerTest.php b/tests/unit/phpDocumentor/Compiler/Linker/LinkerTest.php index 34ccfc8739..ac1471642c 100644 --- a/tests/unit/phpDocumentor/Compiler/Linker/LinkerTest.php +++ b/tests/unit/phpDocumentor/Compiler/Linker/LinkerTest.php @@ -277,7 +277,7 @@ public function testGetDescription(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testExecute(): void { @@ -297,7 +297,7 @@ public function testExecute(): void $linker = new Linker([$fqsen => ['field']], $repository->reveal()); // execute test. - $linker->execute($project); + $linker->__invoke($project); } private function givenAnExampleClassDescriptor(string $fqsenString): ClassDescriptor diff --git a/tests/unit/phpDocumentor/Compiler/Pass/DebugTest.php b/tests/unit/phpDocumentor/Compiler/Pass/DebugTest.php index f270766d6b..3deb61eadf 100644 --- a/tests/unit/phpDocumentor/Compiler/Pass/DebugTest.php +++ b/tests/unit/phpDocumentor/Compiler/Pass/DebugTest.php @@ -31,7 +31,7 @@ final class DebugTest extends TestCase use ProphecyTrait; /** - * @covers ::execute + * @covers ::__invoke */ public function testLogDebugAnalysis(): void { @@ -46,7 +46,7 @@ public function testLogDebugAnalysis(): void $analyzerMock->__toString()->shouldBeCalled()->willReturn($testString); $fixture = new Debug($loggerMock->reveal(), $analyzerMock->reveal()); - $fixture->execute($projectDescriptorMock->reveal()); + $fixture->__invoke($projectDescriptorMock->reveal()); $this->assertTrue(true); } diff --git a/tests/unit/phpDocumentor/Compiler/Pass/ElementsIndexBuilderTest.php b/tests/unit/phpDocumentor/Compiler/Pass/ElementsIndexBuilderTest.php index 1f065b174b..165ea4ce2c 100644 --- a/tests/unit/phpDocumentor/Compiler/Pass/ElementsIndexBuilderTest.php +++ b/tests/unit/phpDocumentor/Compiler/Pass/ElementsIndexBuilderTest.php @@ -65,7 +65,7 @@ public function testGetDescription(): void } /** - * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::execute + * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::__invoke * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::addElementsToIndexes * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getIndexKey */ @@ -81,7 +81,7 @@ public function testAddClassesToIndex(): void $classDescriptor2->setFullyQualifiedStructuralElementName(new Fqsen('\My\Space\Class2')); $file2->getClasses()->add($classDescriptor2); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $elements = $this->project->getIndexes()->get('elements')->getAll(); $this->assertCount(2, $elements); @@ -95,7 +95,7 @@ public function testAddClassesToIndex(): void } /** - * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::execute + * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::__invoke * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::addElementsToIndexes * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getIndexKey */ @@ -111,7 +111,7 @@ public function testAddInterfacesToIndex(): void $interfaceDescriptor2->setFullyQualifiedStructuralElementName(new Fqsen('\My\Space\Interface2')); $file2->getInterfaces()->add($interfaceDescriptor2); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $elements = $this->project->getIndexes()->get('elements')->getAll(); $this->assertCount(2, $elements); @@ -125,7 +125,7 @@ public function testAddInterfacesToIndex(): void } /** - * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::execute + * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::__invoke * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::addElementsToIndexes * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getIndexKey */ @@ -141,7 +141,7 @@ public function testAddTraitsToIndex(): void $traitDescriptor2->setFullyQualifiedStructuralElementName(new Fqsen('\My\Space\Trait2')); $file2->getTraits()->add($traitDescriptor2); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $elements = $this->project->getIndexes()->get('elements')->getAll(); $this->assertCount(2, $elements); @@ -155,7 +155,7 @@ public function testAddTraitsToIndex(): void } /** - * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::execute + * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::__invoke * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::addElementsToIndexes * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getIndexKey */ @@ -171,7 +171,7 @@ public function testAddFunctionsToIndex(): void $functionDescriptor2->setFullyQualifiedStructuralElementName(new Fqsen('\function2')); $file2->getFunctions()->add($functionDescriptor2); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $elements = $this->project->getIndexes()->get('elements')->getAll(); $this->assertCount(2, $elements); @@ -185,7 +185,7 @@ public function testAddFunctionsToIndex(): void } /** - * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::execute + * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::__invoke * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::addElementsToIndexes * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getIndexKey */ @@ -201,7 +201,7 @@ public function testAddConstantsToIndex(): void $constantDescriptor2->setFullyQualifiedStructuralElementName(new Fqsen('\CONSTANT2')); $file2->getConstants()->add($constantDescriptor2); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $elements = $this->project->getIndexes()->get('elements')->getAll(); $this->assertCount(2, $elements); @@ -215,7 +215,7 @@ public function testAddConstantsToIndex(): void } /** - * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::execute + * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::__invoke * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::addElementsToIndexes * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getIndexKey * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getSubElements @@ -240,7 +240,7 @@ public function testAddClassConstantsToIndex(): void $classConstantDescriptor2->setFullyQualifiedStructuralElementName(new Fqsen('\My\Space\Class2::CONSTANT')); $classDescriptor2->getConstants()->add($classConstantDescriptor2); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $elements = $this->project->getIndexes()->get('elements')->getAll(); $this->assertCount(4, $elements); @@ -259,7 +259,7 @@ public function testAddClassConstantsToIndex(): void } /** - * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::execute + * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::__invoke * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::addElementsToIndexes * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getIndexKey * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getSubElements @@ -284,7 +284,7 @@ public function testAddPropertiesToIndex(): void $classPropertyDescriptor2->setFullyQualifiedStructuralElementName(new Fqsen('\My\Space\Class2::$property')); $classDescriptor2->getProperties()->add($classPropertyDescriptor2); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $elements = $this->project->getIndexes()->get('elements')->getAll(); $this->assertCount(4, $elements); @@ -302,7 +302,7 @@ public function testAddPropertiesToIndex(): void } /** - * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::execute + * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::__invoke * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::addElementsToIndexes * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getIndexKey * @covers \phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getSubElements @@ -327,7 +327,7 @@ public function testAddMethodsToIndex(): void $classMethodDescriptor2->setFullyQualifiedStructuralElementName(new Fqsen('\My\Space\Class2::METHOD')); $classDescriptor2->getMethods()->add($classMethodDescriptor2); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $elements = $this->project->getIndexes()->get('elements')->getAll(); $this->assertCount(4, $elements); diff --git a/tests/unit/phpDocumentor/Compiler/Pass/MarkerFromTagsExtractorTest.php b/tests/unit/phpDocumentor/Compiler/Pass/MarkerFromTagsExtractorTest.php index e59306cb5f..58131e4609 100644 --- a/tests/unit/phpDocumentor/Compiler/Pass/MarkerFromTagsExtractorTest.php +++ b/tests/unit/phpDocumentor/Compiler/Pass/MarkerFromTagsExtractorTest.php @@ -52,7 +52,7 @@ public function testDescriptionReturnsCorrectString(): void } /** - * @covers \phpDocumentor\Compiler\Pass\MarkerFromTagsExtractor::execute + * @covers \phpDocumentor\Compiler\Pass\MarkerFromTagsExtractor::__invoke * @covers \phpDocumentor\Compiler\Pass\MarkerFromTagsExtractor::getFileDescriptor * @covers \phpDocumentor\Compiler\Pass\MarkerFromTagsExtractor::addTodoMarkerToFile */ @@ -66,7 +66,7 @@ public function testAddTodoMarkerForEachTodoTagInAnyElement(): void $classDescriptor->setStartLocation(new Location(20)); $this->givenDescriptorHasTodoTagWithDescription($classDescriptor, '789'); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $this->assertCount(2, $fileDescriptor->getTags()->get('todo')); $this->assertCount(1, $classDescriptor->getTags()->get('todo')); @@ -86,7 +86,7 @@ public function testAddTodoMarkerForEachTodoTagInAnyElement(): void } /** - * @covers \phpDocumentor\Compiler\Pass\MarkerFromTagsExtractor::execute + * @covers \phpDocumentor\Compiler\Pass\MarkerFromTagsExtractor::__invoke * @covers \phpDocumentor\Compiler\Pass\MarkerFromTagsExtractor::getFileDescriptor */ public function testExceptionShouldBeThrownIfElementHasNoFileAssociated(): void @@ -97,7 +97,7 @@ public function testExceptionShouldBeThrownIfElementHasNoFileAssociated(): void $this->expectException('UnexpectedValueException'); $this->expectExceptionMessage('An element should always have a file associated with it'); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); } protected function givenProjectHasFileDescriptor(): FileDescriptor diff --git a/tests/unit/phpDocumentor/Compiler/Pass/NamespaceTreeBuilderTest.php b/tests/unit/phpDocumentor/Compiler/Pass/NamespaceTreeBuilderTest.php index c69a86ff54..7538390b65 100644 --- a/tests/unit/phpDocumentor/Compiler/Pass/NamespaceTreeBuilderTest.php +++ b/tests/unit/phpDocumentor/Compiler/Pass/NamespaceTreeBuilderTest.php @@ -67,7 +67,7 @@ public function testGetDescription(): void } /** - * @covers ::execute + * @covers ::__invoke * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::addElementsOfTypeToNamespace */ public function testNamespaceStringIsConvertedToTreeAndAddedToElements(): void @@ -83,7 +83,7 @@ public function testNamespaceStringIsConvertedToTreeAndAddedToElements(): void $class2->setFullyQualifiedStructuralElementName(new Fqsen('\My\Space\Deeper2\Class2')); $this->project->getFiles()->get(0)->getClasses()->add($class2); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $elements = $this->project->getIndexes()->get('elements')->getAll(); $elementNames = array_keys($elements); @@ -104,7 +104,7 @@ public function testNamespaceStringIsConvertedToTreeAndAddedToElements(): void } /** - * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::execute + * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::__invoke * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::addElementsOfTypeToNamespace */ public function testAddClassToNamespace(): void @@ -120,7 +120,7 @@ public function testAddClassToNamespace(): void $class2->setFullyQualifiedStructuralElementName(new Fqsen('\My\Space\Class2')); $this->project->getFiles()->get(0)->getClasses()->add($class2); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $this->assertSame( [$class, $class2], @@ -132,7 +132,7 @@ public function testAddClassToNamespace(): void } /** - * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::execute + * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::__invoke * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::addElementsOfTypeToNamespace */ public function testAddInterfaceToNamespace(): void @@ -148,7 +148,7 @@ public function testAddInterfaceToNamespace(): void $interface2->setFullyQualifiedStructuralElementName(new Fqsen('\My\Space\Interface2')); $this->project->getFiles()->get(0)->getInterfaces()->add($interface2); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $this->assertSame( [$interface, $interface2], @@ -160,7 +160,7 @@ public function testAddInterfaceToNamespace(): void } /** - * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::execute + * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::__invoke * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::addElementsOfTypeToNamespace */ public function testAddTraitToNamespace(): void @@ -176,7 +176,7 @@ public function testAddTraitToNamespace(): void $trait2->setFullyQualifiedStructuralElementName(new Fqsen('\My\Space\Trait2')); $this->project->getFiles()->get(0)->getTraits()->add($trait2); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $this->assertSame( [$trait, $trait2], @@ -188,7 +188,7 @@ public function testAddTraitToNamespace(): void } /** - * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::execute + * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::__invoke * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::addElementsOfTypeToNamespace */ public function testAddConstantToNamespace(): void @@ -204,7 +204,7 @@ public function testAddConstantToNamespace(): void $constant2->setFullyQualifiedStructuralElementName(new Fqsen('\My\Space\Constant2')); $this->project->getFiles()->get(0)->getConstants()->add($constant2); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $this->assertSame( [$constant, $constant2], @@ -216,7 +216,7 @@ public function testAddConstantToNamespace(): void } /** - * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::execute + * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::__invoke * @covers \phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::addElementsOfTypeToNamespace */ public function testAddFunctionToNamespace(): void @@ -232,7 +232,7 @@ public function testAddFunctionToNamespace(): void $function2->setFullyQualifiedStructuralElementName(new Fqsen('\My\Space\Function2')); $this->project->getFiles()->get(0)->getFunctions()->add($function2); - $this->fixture->execute($this->project); + $this->fixture->__invoke($this->project); $this->assertSame( [$function, $function2], diff --git a/tests/unit/phpDocumentor/Compiler/Pass/PackageTreeBuilderTest.php b/tests/unit/phpDocumentor/Compiler/Pass/PackageTreeBuilderTest.php index 84fd4cefee..0b8d117005 100644 --- a/tests/unit/phpDocumentor/Compiler/Pass/PackageTreeBuilderTest.php +++ b/tests/unit/phpDocumentor/Compiler/Pass/PackageTreeBuilderTest.php @@ -65,7 +65,7 @@ public function testGetDescription(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testRootPackageIsSet(): void { @@ -73,7 +73,7 @@ public function testRootPackageIsSet(): void $set = $this->faker()->apiSetDescriptor(); $version = $this->faker()->versionDescriptor([$set]); $project->getVersions()->add($version); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); @@ -81,7 +81,7 @@ public function testRootPackageIsSet(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testFilesAreIncludedInTheIndex(): void { @@ -92,7 +92,7 @@ public function testFilesAreIncludedInTheIndex(): void $project = $this->givenProjectWithFile($file); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); @@ -101,7 +101,7 @@ public function testFilesAreIncludedInTheIndex(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testPackagesAreSetOnTheDescriptors(): void { @@ -114,7 +114,7 @@ public function testPackagesAreSetOnTheDescriptors(): void $project = $this->givenProjectWithFile($file); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); @@ -124,7 +124,7 @@ public function testPackagesAreSetOnTheDescriptors(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testMultipleElementsInTheSamePackageAreProperlyNestedUnderTheSamePackageDescriptor(): void { @@ -137,7 +137,7 @@ public function testMultipleElementsInTheSamePackageAreProperlyNestedUnderTheSam $project = $this->givenProjectWithFiles([$file1, $file2]); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); @@ -147,7 +147,7 @@ public function testMultipleElementsInTheSamePackageAreProperlyNestedUnderTheSam } /** - * @covers ::execute + * @covers ::__invoke */ public function testNestedPackagesWillBeCorrectlyFormedIntoATree(): void { @@ -161,7 +161,7 @@ public function testNestedPackagesWillBeCorrectlyFormedIntoATree(): void $project = $this->givenProjectWithFiles([$file1, $file2]); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $rootPackage = $project->getIndexes()->get('packages')['\\']; $this->assertNotNull($rootPackage->getChildren()['My']); @@ -170,7 +170,7 @@ public function testNestedPackagesWillBeCorrectlyFormedIntoATree(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testPackagesMayHaveUnderscoresAsSeparators(): void { @@ -181,7 +181,7 @@ public function testPackagesMayHaveUnderscoresAsSeparators(): void $project = $this->givenProjectWithFile($file); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); @@ -190,7 +190,7 @@ public function testPackagesMayHaveUnderscoresAsSeparators(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testPackagesMayHaveHyphensAsSeparators(): void { @@ -201,7 +201,7 @@ public function testPackagesMayHaveHyphensAsSeparators(): void $project = $this->givenProjectWithFile($file); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); @@ -210,7 +210,7 @@ public function testPackagesMayHaveHyphensAsSeparators(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testPackagesMayHaveSquareBracketsAsSeparators(): void { @@ -221,7 +221,7 @@ public function testPackagesMayHaveSquareBracketsAsSeparators(): void $project = $this->givenProjectWithFile($file); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); @@ -230,7 +230,7 @@ public function testPackagesMayHaveSquareBracketsAsSeparators(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testPackagesMayHaveDotsAsSeparators(): void { @@ -241,7 +241,7 @@ public function testPackagesMayHaveDotsAsSeparators(): void $project = $this->givenProjectWithFile($file); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); @@ -250,7 +250,7 @@ public function testPackagesMayHaveDotsAsSeparators(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testSubpackagesAndPackagesAreMergedIntoOne(): void { @@ -263,7 +263,7 @@ public function testSubpackagesAndPackagesAreMergedIntoOne(): void $project = $this->givenProjectWithFile($file); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); @@ -272,7 +272,7 @@ public function testSubpackagesAndPackagesAreMergedIntoOne(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testSubpackagesMayHaveSlashesAsPrefix(): void { @@ -285,7 +285,7 @@ public function testSubpackagesMayHaveSlashesAsPrefix(): void $project = $this->givenProjectWithFile($file); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); @@ -294,7 +294,7 @@ public function testSubpackagesMayHaveSlashesAsPrefix(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testConstantsInAFileAreIncludedInTheIndex(): void { @@ -307,7 +307,7 @@ public function testConstantsInAFileAreIncludedInTheIndex(): void $project = $this->givenProjectWithFile($file); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); @@ -316,7 +316,7 @@ public function testConstantsInAFileAreIncludedInTheIndex(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testFunctionsInAFileAreIncludedInTheIndex(): void { @@ -329,7 +329,7 @@ public function testFunctionsInAFileAreIncludedInTheIndex(): void $project = $this->givenProjectWithFile($file); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); @@ -338,7 +338,7 @@ public function testFunctionsInAFileAreIncludedInTheIndex(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testInterfacesInAFileAreIncludedInTheIndex(): void { @@ -351,7 +351,7 @@ public function testInterfacesInAFileAreIncludedInTheIndex(): void $project = $this->givenProjectWithFile($file); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); @@ -360,7 +360,7 @@ public function testInterfacesInAFileAreIncludedInTheIndex(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testTraitsInAFileAreIncludedInTheIndex(): void { @@ -373,7 +373,7 @@ public function testTraitsInAFileAreIncludedInTheIndex(): void $project = $this->givenProjectWithFile($file); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); @@ -382,7 +382,7 @@ public function testTraitsInAFileAreIncludedInTheIndex(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testClassesInAFileAreIncludedInTheIndex(): void { @@ -395,7 +395,7 @@ public function testClassesInAFileAreIncludedInTheIndex(): void $project = $this->givenProjectWithFile($file); - $this->fixture->execute($project); + $this->fixture->__invoke($project); $packages = $project->getIndexes()->get('packages'); diff --git a/tests/unit/phpDocumentor/Compiler/Pass/RemoveSourcecodeTest.php b/tests/unit/phpDocumentor/Compiler/Pass/RemoveSourcecodeTest.php index f51cde5321..364b15cd61 100644 --- a/tests/unit/phpDocumentor/Compiler/Pass/RemoveSourcecodeTest.php +++ b/tests/unit/phpDocumentor/Compiler/Pass/RemoveSourcecodeTest.php @@ -31,7 +31,7 @@ final class RemoveSourcecodeTest extends TestCase use ProphecyTrait; /** - * @covers ::execute + * @covers ::__invoke */ public function testRemovesSourceWhenDisabled(): void { @@ -39,7 +39,7 @@ public function testRemovesSourceWhenDisabled(): void $projectDescriptor = $this->giveProjectDescriptor($apiSetDescriptor); $fixture = new RemoveSourcecode(); - $fixture->execute($projectDescriptor); + $fixture->__invoke($projectDescriptor); foreach ($apiSetDescriptor->getFiles() as $file) { self::assertNull($file->getSource()); @@ -47,7 +47,7 @@ public function testRemovesSourceWhenDisabled(): void } /** - * @covers ::execute + * @covers ::__invoke */ public function testRemovesSourceWhenSourceShouldBeIncluded(): void { @@ -56,7 +56,7 @@ public function testRemovesSourceWhenSourceShouldBeIncluded(): void $projectDescriptor = $this->giveProjectDescriptor($apiSetDescriptor); $fixture = new RemoveSourcecode(); - $fixture->execute($projectDescriptor); + $fixture->__invoke($projectDescriptor); foreach ($apiSetDescriptor->getFiles() as $file) { self::assertNotNull($file->getSource()); diff --git a/tests/unit/phpDocumentor/Compiler/Pass/ResolveInlineMarkersTest.php b/tests/unit/phpDocumentor/Compiler/Pass/ResolveInlineMarkersTest.php index a7db4edb5d..f45f09069a 100644 --- a/tests/unit/phpDocumentor/Compiler/Pass/ResolveInlineMarkersTest.php +++ b/tests/unit/phpDocumentor/Compiler/Pass/ResolveInlineMarkersTest.php @@ -49,7 +49,7 @@ class Marker $projectDescriptor->getVersions()->add(new VersionDescriptor('latest', $documentationsSets)); $apiDescriptor->setFiles(new Collection([$fileDescriptor])); - $fixture->execute($projectDescriptor); + $fixture->__invoke($projectDescriptor); self::assertCount(1, $fileDescriptor->getMarkers()); } diff --git a/tests/unit/phpDocumentor/Compiler/Pass/TableOfContentsBuilderTest.php b/tests/unit/phpDocumentor/Compiler/Pass/TableOfContentsBuilderTest.php index c79bf0bb92..805fc8447d 100644 --- a/tests/unit/phpDocumentor/Compiler/Pass/TableOfContentsBuilderTest.php +++ b/tests/unit/phpDocumentor/Compiler/Pass/TableOfContentsBuilderTest.php @@ -41,7 +41,7 @@ public function testApiDocumentationSetNamespacesAreAddedAsTOC(): void return (string) $args[0]->getFullyQualifiedStructuralElementName(); }); $pass = new TableOfContentsBuilder($router->reveal(), new NullLogger()); - $pass->execute($project); + $pass->__invoke($project); self::assertCount(1, $apiDocumentationSet->getTableOfContents()); /** @var TocDescriptor $namespacesToc */ @@ -68,7 +68,7 @@ public function testApiDocumentationSetPackagesAreAddedAsTOC(): void return (string) $args[0]->getFullyQualifiedStructuralElementName(); }); $pass = new TableOfContentsBuilder($router->reveal(), new NullLogger()); - $pass->execute($project); + $pass->__invoke($project); self::assertCount(1, $apiDocumentationSet->getTableOfContents()); /** @var TocDescriptor $namespacesToc */ diff --git a/tests/unit/phpDocumentor/Compiler/Pass/UsedByBuilderTest.php b/tests/unit/phpDocumentor/Compiler/Pass/UsedByBuilderTest.php index 5c20c78b50..5088683ff2 100644 --- a/tests/unit/phpDocumentor/Compiler/Pass/UsedByBuilderTest.php +++ b/tests/unit/phpDocumentor/Compiler/Pass/UsedByBuilderTest.php @@ -36,7 +36,7 @@ public function testCounterPartOfUsesWillGetTagUsedBy(): void $apiSetDescriptor->getIndex('elements')->add($class); $apiSetDescriptor->getIndex('elements')->add($counterClass); - $this->pass->execute($projectDescriptor); + $this->pass->__invoke($projectDescriptor); $usedBy = $counterClass->getTags()->fetch( 'used-by', diff --git a/tests/unit/phpDocumentor/Pipeline/PipelineFactoryTest.php b/tests/unit/phpDocumentor/Pipeline/PipelineFactoryTest.php index c755729b22..1c25b1cfad 100644 --- a/tests/unit/phpDocumentor/Pipeline/PipelineFactoryTest.php +++ b/tests/unit/phpDocumentor/Pipeline/PipelineFactoryTest.php @@ -14,9 +14,11 @@ namespace phpDocumentor\Pipeline; use PHPUnit\Framework\TestCase; +use Psr\Log\Test\TestLogger; /** * @coversDefaultClass \phpDocumentor\Pipeline\PipelineFactory + * @covers ::__construct * @covers :: */ final class PipelineFactoryTest extends TestCase @@ -26,7 +28,8 @@ final class PipelineFactoryTest extends TestCase */ public function test_creates_a_pipeline_with_the_given_series_of_stages(): void { - $pipeline = PipelineFactory::create( + $pipelineFactory = new PipelineFactory(new TestLogger()); + $pipeline = $pipelineFactory->create( [ static function ($value) { return $value + 1;