Skip to content

Commit cecc0ca

Browse files
committed
Remove deprecated Analysis::process()
1 parent ca797e0 commit cecc0ca

25 files changed

Lines changed: 178 additions & 153 deletions

src/Analysis.php

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

406-
/**
407-
* Apply the processor(s).
408-
*
409-
* @param callable|array<callable> $processors One or more processors
410-
* @deprecated use Generator::withProcessorPipeline() instead
411-
*/
412-
public function process($processors = null): void
413-
{
414-
if (false === is_array($processors) && is_callable($processors)) {
415-
$processors = [$processors];
416-
}
417-
418-
foreach ($processors as $processor) {
419-
$processor($this);
420-
}
421-
}
422-
423406
public function validate(): bool
424407
{
425408
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 & 11 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,11 +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())
125-
->setTypeResolver($this->getTypeResolver())
126-
->getProcessorPipeline()
127-
->process($analysis);
122+
$analysis = $this->analysisFromFixtures([
123+
'DuplicateOperationId.php',
124+
], $this->processorPipeline());
128125

129126
$this->assertOpenApiLogEntryContains('operationId must be unique. Duplicate value found: "getItem"');
130127
$this->assertFalse($analysis->validate());
@@ -139,11 +136,9 @@ public function testIsRoot(): void
139136

140137
public function testValidateExamples(): void
141138
{
142-
$analysis = $this->analysisFromFixtures(['BadExampleParameter.php']);
143-
(new Generator())
144-
->setTypeResolver($this->getTypeResolver())
145-
->getProcessorPipeline()
146-
->process($analysis);
139+
$analysis = $this->analysisFromFixtures([
140+
'BadExampleParameter.php',
141+
], $this->processorPipeline());
147142

148143
$this->assertOpenApiLogEntryContains('Required @OA\PathItem() not found');
149144
$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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ class NestedPropertyTest extends OpenApiTestCase
1717
{
1818
public function testNestedProperties(): void
1919
{
20-
$analysis = $this->analysisFromFixtures(['NestedProperty.php']);
21-
$analysis->process($this->initializeProcessors([
20+
$analysis = $this->analysisFromFixtures([
21+
'NestedProperty.php',
22+
], $this->processorPipeline([
2223
new MergeIntoOpenApi(),
2324
new MergeIntoComponents(),
2425
new AugmentSchemas(),

tests/OpenApiTestCase.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,30 +235,28 @@ public static function fixtures(array $files): array
235235
}, $files);
236236
}
237237

238-
public static function processors(array $strip = []): array
238+
public function processorPipeline(?array $processors = null, array $strip = []): Pipeline
239239
{
240-
$processors = [];
240+
$generator = (new Generator())
241+
->setTypeResolver($this->getTypeResolver());
241242

242-
(new Generator())
243-
->getProcessorPipeline()
244-
->walk(function ($processor) use (&$processors, $strip) {
245-
if (!is_object($processor) || !in_array(get_class($processor), $strip)) {
246-
$processors[] = $processor;
247-
}
248-
});
243+
if ($processors) {
244+
$generator->setProcessorPipeline(new Pipeline($processors));
245+
}
249246

250-
return $processors;
247+
return $generator->getProcessorPipeline()
248+
->remove(fn ($processor) => is_object($processor) && in_array(get_class($processor), $strip));
251249
}
252250

253-
public function analysisFromFixtures(array $files, array $processors = [], ?AnalyserInterface $analyzer = null, array $config = []): Analysis
251+
public function analysisFromFixtures(array $files, ?Pipeline $pipeline = null, ?AnalyserInterface $analyzer = null, array $config = []): Analysis
254252
{
255253
$analysis = new Analysis([], $this->getContext());
256254

257255
(new Generator($this->getTrackingLogger()))
258256
->setConfig($config)
259257
->setAnalyser($analyzer ?: $this->getAnalyzer())
260258
->setTypeResolver($this->getTypeResolver())
261-
->setProcessorPipeline(new Pipeline($processors))
259+
->setProcessorPipeline($pipeline ?? new Pipeline())
262260
->generate($this->fixtures($files), $analysis, false);
263261

264262
return $analysis;

tests/Processors/AugmentParametersTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ public function testParseTags(string $params, array $expected): void
7070
*/
7171
public function testParameterNativeType(): void
7272
{
73-
$analysis = $this->analysisFromFixtures(['RequestUsingAttribute.php']);
74-
$analysis->process($this->initializeProcessors([
73+
$analysis = $this->analysisFromFixtures([
74+
'RequestUsingAttribute.php',
75+
], $this->processorPipeline([
7576
new MergeIntoOpenApi(),
7677
new MergeIntoComponents(),
7778
new BuildPaths(),

tests/Processors/AugmentPropertiesTest.php

Lines changed: 12 additions & 9 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

@@ -71,7 +72,7 @@ public function testAugmentProperties(): void
7172
$this->assertSame(Generator::UNDEFINED, $endorsedFriends->nullable);
7273
$this->assertSame(Generator::UNDEFINED, $endorsedFriends->allOf);
7374

74-
$analysis->process($this->initializeProcessors([new AugmentProperties()]));
75+
$this->processorPipeline([new AugmentProperties()])->process($analysis);
7576

7677
$expectedValues = [
7778
'property' => 'firstname',
@@ -149,12 +150,14 @@ public function testAugmentProperties(): void
149150

150151
public function testTypedProperties(): void
151152
{
152-
$analysis = $this->analysisFromFixtures(['TypedProperties.php']);
153-
$analysis->process([
153+
$analysis = $this->analysisFromFixtures([
154+
'TypedProperties.php',
155+
], $this->processorPipeline([
154156
new MergeIntoOpenApi(),
155157
new MergeIntoComponents(),
156158
new AugmentSchemas(),
157-
]);
159+
]));
160+
158161
[
159162
$stringType,
160163
$intType,
@@ -254,7 +257,7 @@ public function testTypedProperties(): void
254257
'type' => Generator::UNDEFINED,
255258
]);
256259

257-
$analysis->process($this->initializeProcessors([new AugmentProperties()]));
260+
$this->processorPipeline([new AugmentProperties()])->process($analysis);
258261

259262
$this->assertName($stringType, [
260263
'property' => 'stringType',
@@ -351,7 +354,7 @@ public function testTypedProperties(): void
351354
protected function assertName(OA\Property $property, array $expectedValues): void
352355
{
353356
foreach ($expectedValues as $key => $val) {
354-
$this->assertSame($val, $property->$key, '@OA\Property()->' . $key);
357+
$this->assertSame($val, $property->$key, '@OA\Property()->property based on propertyname');
355358
}
356359
}
357360
}

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)