From 5475909a02c8f7cb2d646868a1462d1886288af9 Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Wed, 1 May 2024 15:09:59 +1200 Subject: [PATCH] Clarify processor pipeline naming. --- bin/openapi | 2 +- docs/reference/generator.md | 2 +- src/Generator.php | 36 ++++++++++---------- tests/Analysers/ReflectionAnalyserTest.php | 6 ++-- tests/Analysers/TokenAnalyserTest.php | 4 +-- tests/Annotations/AbstractAnnotationTest.php | 4 +-- tests/GeneratorTest.php | 2 +- tests/OpenApiTestCase.php | 4 +-- tests/RefTest.php | 2 +- tools/src/Docs/ProcGenerator.php | 2 +- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/bin/openapi b/bin/openapi index 498f3de0..a41fa0d7 100755 --- a/bin/openapi +++ b/bin/openapi @@ -219,7 +219,7 @@ foreach ($options["processor"] as $processor) { } elseif (class_exists($processor)) { $processor = new $processor(); } - $generator->getProcessor()->add($processor); + $generator->getProcessorPipeline()->add($processor); } $analyser = $options['legacy'] diff --git a/docs/reference/generator.md b/docs/reference/generator.md index 3e4499fd..6c1cabd8 100644 --- a/docs/reference/generator.md +++ b/docs/reference/generator.md @@ -57,7 +57,7 @@ $processors = [/* my processors */]; $finder = \Symfony\Component\Finder\Finder::create()->files()->name('*.php')->in(__DIR__); $openapi = (new \OpenApi\Generator($logger)) - ->setProcessor(new \OpenApi\Pipeline($processors)) + ->setProcessorPipeline(new \OpenApi\Pipeline($processors)) ->setAliases(['MY' => 'My\Annotations']) ->setNamespaces(['My\\Annotations\\']) ->setAnalyser(new \OpenApi\Analysers\TokenAnalyser()) diff --git a/src/Generator.php b/src/Generator.php index 105cbcbd..3e5712f4 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -53,8 +53,8 @@ class Generator /** @var array */ protected $config = []; - /** @var Pipeline|null List of configured processors. */ - protected $processor = null; + /** @var Pipeline|null */ + protected $processorPipeline = null; /** @var LoggerInterface|null PSR logger. */ protected $logger = null; @@ -243,10 +243,10 @@ public function setConfig(array $config): Generator return $this; } - public function getProcessor(): Pipeline + public function getProcessorPipeline(): Pipeline { - if (null === $this->processor) { - $this->processor = new Pipeline([ + if (null === $this->processorPipeline) { + $this->processorPipeline = new Pipeline([ new Processors\DocBlockDescriptions(), new Processors\MergeIntoOpenApi(), new Processors\MergeIntoComponents(), @@ -283,12 +283,12 @@ public function getProcessor(): Pipeline } }; - return $this->processor->walk($walker); + return $this->processorPipeline->walk($walker); } - public function setProcessor(Pipeline $processor): Generator + public function setProcessorPipeline(Pipeline $processor): Generator { - $this->processor = $processor; + $this->processorPipeline = $processor; return $this; } @@ -300,7 +300,7 @@ public function setProcessor(Pipeline $processor): Generator */ public function withProcessor(callable $with): Generator { - $with($this->getProcessor()); + $with($this->getProcessorPipeline()); return $this; } @@ -312,7 +312,7 @@ public function withProcessor(callable $with): Generator */ public function getProcessors(): array { - return $this->getProcessor()->pipes(); + return $this->getProcessorPipeline()->pipes(); } /** @@ -322,7 +322,7 @@ public function getProcessors(): array */ public function setProcessors(?array $processors): Generator { - $this->processor = null !== $processors ? new Pipeline($processors) : null; + $this->processorPipeline = null !== $processors ? new Pipeline($processors) : null; return $this; } @@ -335,7 +335,7 @@ public function setProcessors(?array $processors): Generator */ public function addProcessor($processor, ?string $before = null): Generator { - $processors = $this->processor ?: $this->getProcessor(); + $processors = $this->processorPipeline ?: $this->getProcessorPipeline(); if (!$before) { $processors->add($processor); } else { @@ -351,7 +351,7 @@ public function addProcessor($processor, ?string $before = null): Generator $processors->insert($processor, $matcher); } - $this->processor = $processors; + $this->processorPipeline = $processors; return $this; } @@ -363,9 +363,9 @@ public function addProcessor($processor, ?string $before = null): Generator */ public function removeProcessor($processor, bool $silent = false): Generator { - $processors = $this->processor ?: $this->getProcessor(); + $processors = $this->processorPipeline ?: $this->getProcessorPipeline(); $processors->remove($processor); - $this->processor = $processors; + $this->processorPipeline = $processors; return $this; } @@ -432,8 +432,8 @@ public static function scan(iterable $sources, array $options = []): ?OA\OpenApi ->setAliases($config['aliases']) ->setNamespaces($config['namespaces']) ->setAnalyser($config['analyser']) - ->setProcessor($config['processor']) - ->setProcessor(new Pipeline($config['processors'])) + ->setProcessorPipeline($config['processor']) + ->setProcessorPipeline(new Pipeline($config['processors'])) ->generate($sources, $config['analysis'], $config['validate']); } @@ -485,7 +485,7 @@ public function generate(iterable $sources, ?Analysis $analysis = null, bool $va $this->scanSources($sources, $analysis, $rootContext); // post-processing - $this->getProcessor()->process($analysis); + $this->getProcessorPipeline()->process($analysis); if ($analysis->openapi) { // overwrite default/annotated version diff --git a/tests/Analysers/ReflectionAnalyserTest.php b/tests/Analysers/ReflectionAnalyserTest.php index 07d3309b..b8fd6d3d 100644 --- a/tests/Analysers/ReflectionAnalyserTest.php +++ b/tests/Analysers/ReflectionAnalyserTest.php @@ -94,7 +94,7 @@ public function testApiDocBlockBasic(AnalyserInterface $analyser): void ->withContext(function (Generator $generator) use ($analyser) { $analyser->setGenerator($generator); $analysis = $analyser->fromFile($this->fixture('Apis/DocBlocks/basic.php'), $this->getContext([], $generator->getVersion())); - $generator->getProcessor()->process($analysis); + $generator->getProcessorPipeline()->process($analysis); return $analysis; }); @@ -125,7 +125,7 @@ public function testApiAttributesBasic(AnalyserInterface $analyser): void ->withContext(function (Generator $generator) use ($analyser) { $analyser->setGenerator($generator); $analysis = $analyser->fromFile($this->fixture('Apis/Attributes/basic.php'), $this->getContext([], $generator->getVersion())); - $generator->getProcessor()->process($analysis); + $generator->getProcessorPipeline()->process($analysis); return $analysis; }); @@ -166,7 +166,7 @@ public function testApiMixedBasic(AnalyserInterface $analyser): void ->withContext(function (Generator $generator) use ($analyser) { $analyser->setGenerator($generator); $analysis = $analyser->fromFile($this->fixture('Apis/Mixed/basic.php'), $this->getContext([], $generator->getVersion())); - $generator->getProcessor()->process($analysis); + $generator->getProcessorPipeline()->process($analysis); return $analysis; }); diff --git a/tests/Analysers/TokenAnalyserTest.php b/tests/Analysers/TokenAnalyserTest.php index b333bec2..dac65837 100644 --- a/tests/Analysers/TokenAnalyserTest.php +++ b/tests/Analysers/TokenAnalyserTest.php @@ -280,7 +280,7 @@ public function testPhp8PromotedProperties(): void public function testAnonymousFunctions(): void { $analysis = $this->analysisFromFixtures(['PHP/AnonymousFunctions.php'], [], new TokenAnalyser()); - (new Generator())->getProcessor()->process($analysis); + (new Generator())->getProcessorPipeline()->process($analysis); $infos = $analysis->getAnnotationsOfType(OA\Info::class, true); $this->assertCount(1, $infos); @@ -295,6 +295,6 @@ public function testPhp8NamedArguments(): void $schemas = $analysis->getAnnotationsOfType(OA\Schema::class, true); $this->assertCount(1, $schemas); - (new Generator())->getProcessor()->process($analysis); + (new Generator())->getProcessorPipeline()->process($analysis); } } diff --git a/tests/Annotations/AbstractAnnotationTest.php b/tests/Annotations/AbstractAnnotationTest.php index 12d5b9f6..7dbc837f 100644 --- a/tests/Annotations/AbstractAnnotationTest.php +++ b/tests/Annotations/AbstractAnnotationTest.php @@ -130,7 +130,7 @@ public function testMatchNested(string $class, $expected): void public function testDuplicateOperationIdValidation(): void { $analysis = $this->analysisFromFixtures(['DuplicateOperationId.php']); - (new Generator())->getProcessor()->process($analysis); + (new Generator())->getProcessorPipeline()->process($analysis); $this->assertOpenApiLogEntryContains('operationId must be unique. Duplicate value found: "getItem"'); $this->assertFalse($analysis->validate()); @@ -151,7 +151,7 @@ public function testValidateExamples(): void $this->skipLegacy(); $analysis = $this->analysisFromFixtures(['BadExampleParameter.php']); - (new Generator())->getProcessor()->process($analysis); + (new Generator())->getProcessorPipeline()->process($analysis); $this->assertOpenApiLogEntryContains('Required @OA\PathItem() not found'); $this->assertOpenApiLogEntryContains('Required @OA\Info() not found'); diff --git a/tests/GeneratorTest.php b/tests/GeneratorTest.php index 6f412bbf..09d1b97f 100644 --- a/tests/GeneratorTest.php +++ b/tests/GeneratorTest.php @@ -109,7 +109,7 @@ public function testRemoveProcessor(): void protected function assertOperationIdHash(Generator $generator, bool $expected): void { - $generator->getProcessor()->walk(function ($processor) use ($expected) { + $generator->getProcessorPipeline()->walk(function ($processor) use ($expected) { if ($processor instanceof OperationId) { $this->assertEquals($expected, $processor->isHash()); } diff --git a/tests/OpenApiTestCase.php b/tests/OpenApiTestCase.php index 1950e8e2..7b75819d 100644 --- a/tests/OpenApiTestCase.php +++ b/tests/OpenApiTestCase.php @@ -231,7 +231,7 @@ public static function processors(array $strip = []): array $processors = []; (new Generator()) - ->getProcessor() + ->getProcessorPipeline() ->walk(function ($processor) use (&$processors, $strip) { if (!is_object($processor) || !in_array(get_class($processor), $strip)) { $processors[] = $processor; @@ -247,7 +247,7 @@ public function analysisFromFixtures(array $files, array $processors = [], ?Anal (new Generator($this->getTrackingLogger())) ->setAnalyser($analyzer ?: $this->getAnalyzer()) - ->setProcessor(new Pipeline($processors)) + ->setProcessorPipeline(new Pipeline($processors)) ->generate($this->fixtures($files), $analysis, false); return $analysis; diff --git a/tests/RefTest.php b/tests/RefTest.php index a14bd1c8..b852341c 100644 --- a/tests/RefTest.php +++ b/tests/RefTest.php @@ -27,7 +27,7 @@ public function testRef(): void $openapi->merge($this->annotationsFromDocBlockParser($comment)); $analysis = new Analysis([], $this->getContext()); $analysis->addAnnotation($openapi, $this->getContext()); - (new Generator())->getProcessor()->process($analysis); + (new Generator())->getProcessorPipeline()->process($analysis); $analysis->validate(); // escape / as ~1 diff --git a/tools/src/Docs/ProcGenerator.php b/tools/src/Docs/ProcGenerator.php index 8e71cb15..b35e3849 100644 --- a/tools/src/Docs/ProcGenerator.php +++ b/tools/src/Docs/ProcGenerator.php @@ -52,7 +52,7 @@ public function getProcessorsDetails(): array $defaultProcessors = []; (new Generator()) - ->getProcessor() + ->getProcessorPipeline() ->walk(function ($processor) use (&$processors, &$defaultProcessors) { $rc = new \ReflectionClass($processor); $class = $rc->getName();