Skip to content

Commit 08ed589

Browse files
committed
Remove deprecated Analysis::process()
1 parent 4669fc0 commit 08ed589

25 files changed

Lines changed: 178 additions & 146 deletions

src/Analysis.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -401,23 +401,6 @@ public function split(): \stdClass
401401
return $result;
402402
}
403403

404-
/**
405-
* Apply the processor(s).
406-
*
407-
* @param callable|array<callable> $processors One or more processors
408-
* @deprecated use Generator::withProcessorPipeline() instead
409-
*/
410-
public function process($processors = null): void
411-
{
412-
if (false === is_array($processors) && is_callable($processors)) {
413-
$processors = [$processors];
414-
}
415-
416-
foreach ($processors as $processor) {
417-
$processor($this);
418-
}
419-
}
420-
421404
public function validate(): bool
422405
{
423406
if ($this->openapi instanceof OA\OpenApi) {

src/Pipeline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function remove($pipe = null, ?callable $matcher = null): Pipeline
3434
throw new OpenApiException('pipe or callable must not be empty');
3535
}
3636

37-
// allow matching on class name in $pipe in a string
37+
// allow matching on class name if $pipe in a string
3838
if (is_string($pipe) && !$matcher) {
3939
$pipeClass = $pipe;
4040
$matcher = (fn ($pipe): bool => !$pipe instanceof $pipeClass);

tests/Analysers/ReflectionAnalyserTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public function testPhp8PromotedProperties(): void
8585
$schemas = $analysis->getAnnotationsOfType(OA\Schema::class, true);
8686

8787
$this->assertCount(1, $schemas);
88-
$analysis->process($this->processors([CleanUnusedComponents::class]));
88+
$this->processorPipeline(strip: [CleanUnusedComponents::class])->process($analysis);
89+
;
8990

9091
/** @var OA\Property[] $properties */
9192
$properties = $analysis->getAnnotationsOfType(OA\Property::class);

tests/Annotations/AbstractAnnotationTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace OpenApi\Tests\Annotations;
88

99
use OpenApi\Annotations as OA;
10-
use OpenApi\Generator;
1110
use OpenApi\Tests\OpenApiTestCase;
1211

1312
class AbstractAnnotationTest extends OpenApiTestCase
@@ -120,8 +119,9 @@ public function testMatchNested(string $class, $expected): void
120119

121120
public function testDuplicateOperationIdValidation(): void
122121
{
123-
$analysis = $this->analysisFromFixtures(['DuplicateOperationId.php']);
124-
(new Generator())->getProcessorPipeline()->process($analysis);
122+
$analysis = $this->analysisFromFixtures([
123+
'DuplicateOperationId.php',
124+
], $this->processorPipeline());
125125

126126
$this->assertOpenApiLogEntryContains('operationId must be unique. Duplicate value found: "getItem"');
127127
$this->assertFalse($analysis->validate());
@@ -136,8 +136,9 @@ public function testIsRoot(): void
136136

137137
public function testValidateExamples(): void
138138
{
139-
$analysis = $this->analysisFromFixtures(['BadExampleParameter.php']);
140-
(new Generator())->getProcessorPipeline()->process($analysis);
139+
$analysis = $this->analysisFromFixtures([
140+
'BadExampleParameter.php',
141+
], $this->processorPipeline());
141142

142143
$this->assertOpenApiLogEntryContains('Required @OA\PathItem() not found');
143144
$this->assertOpenApiLogEntryContains('Required @OA\Info() not found');

tests/Annotations/ItemsTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public function testParentTypeArray(): void
3333

3434
public function testRefDefinitionInProperty(): void
3535
{
36-
$analysis = $this->analysisFromFixtures(['UsingVar.php'], $this->processors([CleanUnusedComponents::class]));
36+
$analysis = $this->analysisFromFixtures([
37+
'UsingVar.php',
38+
], $this->processorPipeline(strip: [CleanUnusedComponents::class]));
3739

3840
$this->assertCount(2, $analysis->openapi->components->schemas);
3941
$this->assertEquals('UsingVar', $analysis->openapi->components->schemas[0]->schema);

tests/Annotations/NestedPropertyTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ class NestedPropertyTest extends OpenApiTestCase
1717
{
1818
public function testNestedProperties(): void
1919
{
20-
$analysis = $this->analysisFromFixtures(['NestedProperty.php']);
21-
$analysis->process([
20+
$analysis = $this->analysisFromFixtures([
21+
'NestedProperty.php',
22+
], $this->processorPipeline([
2223
new MergeIntoOpenApi(),
2324
new MergeIntoComponents(),
2425
new AugmentSchemas(),
2526
new AugmentProperties(),
26-
]);
27+
]));
2728

2829
$this->assertCount(1, $analysis->openapi->components->schemas);
2930
$schema = $analysis->openapi->components->schemas[0];

tests/OpenApiTestCase.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -209,29 +209,24 @@ public static function fixtures(array $files): array
209209
}, $files);
210210
}
211211

212-
public static function processors(array $strip = []): array
212+
public function processorPipeline(?array $processors = null, array $strip = []): Pipeline
213213
{
214-
$processors = [];
214+
$pipeline = null === $processors
215+
? (new Generator())->getProcessorPipeline()
216+
: new Pipeline($processors);
215217

216-
(new Generator())
217-
->getProcessorPipeline()
218-
->walk(function ($processor) use (&$processors, $strip) {
219-
if (!is_object($processor) || !in_array(get_class($processor), $strip)) {
220-
$processors[] = $processor;
221-
}
222-
});
223-
224-
return $processors;
218+
return $pipeline
219+
->remove(fn ($processor) => is_object($processor) && in_array(get_class($processor), $strip));
225220
}
226221

227-
public function analysisFromFixtures(array $files, array $processors = [], ?AnalyserInterface $analyzer = null, array $config = []): Analysis
222+
public function analysisFromFixtures(array $files, ?Pipeline $pipeline = null, ?AnalyserInterface $analyzer = null, array $config = []): Analysis
228223
{
229224
$analysis = new Analysis([], $this->getContext());
230225

231226
(new Generator($this->getTrackingLogger()))
232227
->setConfig($config)
233228
->setAnalyser($analyzer ?: $this->getAnalyzer())
234-
->setProcessorPipeline(new Pipeline($processors))
229+
->setProcessorPipeline($pipeline ?? new Pipeline())
235230
->generate($this->fixtures($files), $analysis, false);
236231

237232
return $analysis;

tests/Processors/AugmentParametersTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ public function testParseTags(string $params, array $expected): void
6969
*/
7070
public function testParameterNativeType(): void
7171
{
72-
$analysis = $this->analysisFromFixtures(['RequestUsingAttribute.php']);
73-
$analysis->process([
72+
$analysis = $this->analysisFromFixtures([
73+
'RequestUsingAttribute.php',
74+
], $this->processorPipeline([
7475
new MergeIntoOpenApi(),
7576
new MergeIntoComponents(),
7677
new BuildPaths(),
7778
new AugmentParameters(),
78-
]);
79+
]));
7980

8081
$findPathItemByPath = function (string $path) use ($analysis): PathItem {
8182
foreach ($analysis->openapi->paths as $pathItem) {

tests/Processors/AugmentPropertiesTest.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ class AugmentPropertiesTest extends OpenApiTestCase
2121
{
2222
public function testAugmentProperties(): void
2323
{
24-
$analysis = $this->analysisFromFixtures(['Customer.php']);
25-
$analysis->process([
24+
$analysis = $this->analysisFromFixtures([
25+
'Customer.php',
26+
], $this->processorPipeline([
2627
new MergeIntoOpenApi(),
2728
new MergeIntoComponents(),
2829
new AugmentSchemas(),
29-
]);
30+
]));
3031

3132
$customer = $analysis->openapi->components->schemas[0];
3233
$firstName = $customer->properties[0];
@@ -67,7 +68,8 @@ public function testAugmentProperties(): void
6768
$this->assertSame(Generator::UNDEFINED, $endorsedFriends->nullable);
6869
$this->assertSame(Generator::UNDEFINED, $endorsedFriends->allOf);
6970

70-
$analysis->process(new AugmentProperties());
71+
$this->processorPipeline([new AugmentProperties()])->process($analysis);
72+
;
7173

7274
$expectedValues = [
7375
'property' => 'firstname',
@@ -135,12 +137,14 @@ public function testAugmentProperties(): void
135137

136138
public function testTypedProperties(): void
137139
{
138-
$analysis = $this->analysisFromFixtures(['TypedProperties.php']);
139-
$analysis->process([
140+
$analysis = $this->analysisFromFixtures([
141+
'TypedProperties.php',
142+
], $this->processorPipeline([
140143
new MergeIntoOpenApi(),
141144
new MergeIntoComponents(),
142145
new AugmentSchemas(),
143-
]);
146+
]));
147+
144148
[
145149
$stringType,
146150
$intType,
@@ -235,7 +239,7 @@ public function testTypedProperties(): void
235239
'type' => Generator::UNDEFINED,
236240
]);
237241

238-
$analysis->process([new AugmentProperties()]);
242+
$this->processorPipeline([new AugmentProperties()])->process($analysis);
239243

240244
$this->assertName($stringType, [
241245
'property' => 'stringType',

tests/Processors/AugmentRefsTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,22 @@ class AugmentRefsTest extends OpenApiTestCase
2020

2121
public function testAugmentRefsForRequestBody(): void
2222
{
23-
$analysis = $this->analysisFromFixtures(['Request.php']);
24-
$analysis->process([
23+
$analysis = $this->analysisFromFixtures([
24+
'Request.php',
25+
], $this->processorPipeline([
2526
// create openapi->components
2627
new MergeIntoOpenApi(),
2728
// Merge standalone Scheme's into openapi->components
2829
new MergeIntoComponents(),
2930
new BuildPaths(),
3031
new AugmentRequestBody(),
31-
]);
32+
]));
3233

3334
$this->assertSame($analysis->openapi->paths[0]->post->requestBody->ref, 'OpenApi\Tests\Fixtures\Request');
3435

35-
$analysis->process([
36+
$this->processorPipeline([
3637
new AugmentRefs(),
37-
]);
38+
])->process($analysis);
3839

3940
$this->assertSame($analysis->openapi->paths[0]->post->requestBody->ref, '#/components/requestBodies/Request');
4041
}

0 commit comments

Comments
 (0)