Skip to content

Commit

Permalink
Clarify processor pipeline naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann committed Jun 5, 2024
1 parent f8b62a1 commit 6b355b1
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 32 deletions.
2 changes: 1 addition & 1 deletion bin/openapi
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
36 changes: 18 additions & 18 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class Generator
/** @var array<string,mixed> */
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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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;
}
Expand All @@ -300,7 +300,7 @@ public function setProcessor(Pipeline $processor): Generator
*/
public function withProcessor(callable $with): Generator
{
$with($this->getProcessor());
$with($this->getProcessorPipeline());

return $this;
}
Expand All @@ -312,7 +312,7 @@ public function withProcessor(callable $with): Generator
*/
public function getProcessors(): array
{
return $this->getProcessor()->pipes();
return $this->getProcessorPipeline()->pipes();
}

/**
Expand All @@ -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;
}
Expand All @@ -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 {
Expand All @@ -351,7 +351,7 @@ public function addProcessor($processor, ?string $before = null): Generator
$processors->insert($processor, $matcher);
}

$this->processor = $processors;
$this->processorPipeline = $processors;

return $this;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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']);
}

Expand Down Expand Up @@ -487,7 +487,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
Expand Down
5 changes: 5 additions & 0 deletions src/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public function walk(callable $walker): Pipeline
return $this;
}

/**
* @param mixed $payload
*
* @return mixed
*/
public function process($payload)
{
foreach ($this->pipes as $pipe) {
Expand Down
6 changes: 3 additions & 3 deletions tests/Analysers/ReflectionAnalyserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -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;
});
Expand Down
4 changes: 2 additions & 2 deletions tests/Analysers/TokenAnalyserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
4 changes: 2 additions & 2 deletions tests/Annotations/AbstractAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion tests/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/OpenApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/RefTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tools/src/Docs/ProcGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6b355b1

Please sign in to comment.