Skip to content

Commit 09b3543

Browse files
authored
Subject examples and tests to rector rules (#1942)
1 parent 650fb4a commit 09b3543

73 files changed

Lines changed: 919 additions & 1184 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
},
9999
"scripts": {
100100
"cs": "export XDEBUG_MODE=off && php-cs-fixer fix --allow-risky=yes",
101-
"rector": "rector process src",
101+
"rector": "rector process src tests docs/examples",
102102
"lint": [
103103
"@cs --dry-run",
104104
"@rector --dry-run"

docs/examples/processors/schema-query-parameter/scan.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// and our custom processor
1313
$classLoader->addPsr4('SchemaQueryParameterProcessor\\', __DIR__);
1414

15-
$insertMatch = function (array $pipes) {
15+
$insertMatch = function (array $pipes): int|string|null {
1616
foreach ($pipes as $ii => $pipe) {
1717
if ($pipe instanceof BuildPaths) {
1818
return $ii;
@@ -23,7 +23,7 @@
2323
};
2424

2525
$openapi = (new Generator())
26-
->withProcessorPipeline(fn (Pipeline $pipeline) => $pipeline->insert(new SchemaQueryParameter(), $insertMatch))
26+
->withProcessorPipeline(fn (Pipeline $pipeline): Pipeline => $pipeline->insert(new SchemaQueryParameter(), $insertMatch))
2727
->generate([__DIR__ . '/app']);
2828
// file_put_contents(__DIR__ . '/schema-query-parameter.yaml', $openapi->toYaml());
2929
echo $openapi->toYaml();

docs/examples/processors/sort-components/SortComponents.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
*/
1414
class SortComponents
1515
{
16-
public function __invoke(Analysis $analysis)
16+
public function __invoke(Analysis $analysis): void
1717
{
1818
if (is_object($analysis->openapi->components) && is_iterable($analysis->openapi->components->schemas)) {
19-
usort($analysis->openapi->components->schemas, function ($a, $b) {
20-
return strcmp($a->schema, $b->schema);
21-
});
19+
usort($analysis->openapi->components->schemas, fn ($a, $b): int => strcmp((string) $a->schema, (string) $b->schema));
2220
}
2321
}
2422
}

docs/examples/specs/api/attributes/OpenApiSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)]
2020
#[OAT\License(name: 'MIT', identifier: 'MIT')]
2121
#[OAT\Server(url: 'https://localhost/api', description: 'API server')]
22-
#[OAT\SecurityScheme(securityScheme: 'bearerAuth', type: 'http', scheme: 'bearer', description: 'Basic Auth')]
22+
#[OAT\SecurityScheme(securityScheme: 'bearerAuth', type: 'http', description: 'Basic Auth', scheme: 'bearer')]
2323
#[OAT\Tag(name: 'products', description: 'All about products')]
2424
#[OAT\Tag(name: 'catalog', description: 'Catalog API')]
2525
class OpenApiSpec

docs/examples/specs/api/attributes/ProductController.php

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@ class ProductController
1919
*
2020
* @param ?int $product_id the product id
2121
*/
22-
#[OAT\Get(path: '/products/{product_id}', tags: ['products'], operationId: 'getProducts')]
23-
#[OAT\Response(
24-
response: 200,
25-
description: 'successful operation',
26-
content: [new OAT\MediaType(mediaType: 'application/json', schema: new OAT\Schema(ref: Product::class))],
27-
headers: [
28-
new OAT\Header(header: 'X-Rate-Limit', description: 'calls per hour allowed by the user', schema: new OAT\Schema(type: 'integer', format: 'int32')),
29-
]
30-
)]
22+
#[OAT\Get(path: '/products/{product_id}', operationId: 'getProducts', tags: ['products'])]
23+
#[OAT\Response(response: 200, description: 'successful operation', headers: [
24+
new OAT\Header(header: 'X-Rate-Limit', description: 'calls per hour allowed by the user', schema: new OAT\Schema(type: 'integer', format: 'int32')),
25+
], content: [new OAT\MediaType(mediaType: 'application/json', schema: new OAT\Schema(ref: Product::class))])]
3126
#[OAT\Response(response: 401, description: 'oops')]
3227
#[OAF\CustomAttachable(value: 'operation')]
3328
public function getProduct(
@@ -36,43 +31,39 @@ public function getProduct(
3631
) {
3732
}
3833

39-
#[OAT\Post(path: '/products', tags: ['products'], operationId: 'addProducts', summary: 'Add products')]
34+
#[OAT\Post(path: '/products', operationId: 'addProducts', summary: 'Add products', tags: ['products'])]
4035
#[OAT\Response(
4136
response: 200,
4237
description: 'successful operation',
4338
content: new OAT\JsonContent(ref: Product::class)
4439
)]
45-
#[OAT\RequestBody(
46-
required: true,
47-
description: 'New product',
48-
content: [new OAT\MediaType(
49-
mediaType: 'application/json',
50-
schema: new OAT\Schema(
51-
items: new OAT\Items(type: Product::class)
52-
)
53-
)]
54-
)]
40+
#[OAT\RequestBody(description: 'New product', required: true, content: [new OAT\MediaType(
41+
mediaType: 'application/json',
42+
schema: new OAT\Schema(
43+
items: new OAT\Items(type: Product::class)
44+
)
45+
)])]
5546
/**
5647
* Add a product.
5748
*/
5849
public function addProduct()
5950
{
6051
}
6152

62-
#[OAT\Get(path: '/products', tags: ['products', 'catalog'], operationId: 'getAll')]
53+
#[OAT\Get(path: '/products', operationId: 'getAll', tags: ['products', 'catalog'])]
6354
#[OAT\Response(
6455
response: 200,
6556
description: 'successful operation',
6657
content: new OAT\JsonContent(
67-
type: 'object',
6858
required: ['data'],
6959
properties: [
7060
new OAT\Property(
7161
property: 'data',
7262
type: 'array',
7363
items: new OAT\Items(ref: Product::class)
7464
),
75-
]
65+
],
66+
type: 'object'
7667
)
7768
)]
7869
/**

docs/examples/specs/api/mixed/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function getQuantity(): int
4040
return 1;
4141
}
4242

43-
#[OAT\Property(nullable: true, default: null, example: null)]
43+
#[OAT\Property(default: null, example: null, nullable: true)]
4444
public string $brand;
4545

4646
/** @OA\Property(description="The colour") */

docs/examples/specs/api/mixed/ProductController.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,17 @@ class ProductController
1919
*
2020
* @param ?int $product_id ignored product id docblock typehint
2121
*/
22-
#[OAT\Get(
23-
path: '/products/{product_id}',
24-
tags: ['products'],
25-
operationId: 'getProducts',
26-
responses: [
27-
new OAT\Response(
28-
response: 200,
29-
description: 'successful operation',
30-
content: new OAT\JsonContent(ref: Product::class),
31-
headers: [
32-
new OAT\Header(header: 'X-Rate-Limit', description: 'calls per hour allowed by the user', schema: new OAT\Schema(type: 'integer', format: 'int32')),
33-
]
34-
),
35-
new OAT\Response(response: 401, description: 'oops'),
36-
],
37-
)]
22+
#[OAT\Get(path: '/products/{product_id}', operationId: 'getProducts', tags: ['products'], responses: [
23+
new OAT\Response(
24+
response: 200,
25+
description: 'successful operation',
26+
headers: [
27+
new OAT\Header(header: 'X-Rate-Limit', description: 'calls per hour allowed by the user', schema: new OAT\Schema(type: 'integer', format: 'int32')),
28+
],
29+
content: new OAT\JsonContent(ref: Product::class)
30+
),
31+
new OAT\Response(response: 401, description: 'oops'),
32+
])]
3833
#[OAT\PathParameter(name: 'product_id', description: 'the product id', schema: new OAT\Schema(type: 'integer'))]
3934
public function getProduct(?int $product_id)
4035
{
@@ -69,20 +64,20 @@ public function addProduct()
6964
/**
7065
* Get all.
7166
*/
72-
#[OAT\Get(path: '/products', tags: ['products', 'catalog'], operationId: 'getAll')]
67+
#[OAT\Get(path: '/products', operationId: 'getAll', tags: ['products', 'catalog'])]
7368
#[OAT\Response(
7469
response: 200,
7570
description: 'successful operation',
7671
content: new OAT\JsonContent(
77-
type: 'object',
7872
required: ['data'],
7973
properties: [
8074
new OAT\Property(
8175
property: 'data',
8276
type: 'array',
8377
items: new OAT\Items(ref: Product::class)
8478
),
85-
]
79+
],
80+
type: 'object'
8681
)
8782
)]
8883
#[OAT\Response(response: 401, description: 'oops')]

0 commit comments

Comments
 (0)