Skip to content

Commit fa70fad

Browse files
author
Matej Grgić
committed
refactor: Rector - LevelSetList::UP_TO_PHP_83 rule
1 parent db1ff46 commit fa70fad

Some content is hidden

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

53 files changed

+109
-619
lines changed

rector.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
declare(strict_types=1);
44

55
use Rector\Config\RectorConfig;
6-
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
6+
use Rector\Set\ValueObject\LevelSetList;
77

8-
return RectorConfig::configure()
9-
->withRules([
10-
TypedPropertyFromStrictConstructorRector::class,
8+
return static function (RectorConfig $rectorConfig): void {
9+
$rectorConfig->paths([
10+
__DIR__ . '/src',
11+
__DIR__ . '/tests',
1112
]);
13+
14+
$rectorConfig->sets([
15+
LevelSetList::UP_TO_PHP_83,
16+
]);
17+
};

src/Bridge/OpenApi/Model/Api.php

+1-19
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212

1313
class Api implements Contract\Api
1414
{
15-
private string $title;
16-
17-
private string $version;
18-
19-
private string $description;
20-
21-
private ?string $email;
22-
2315
/** @var Endpoint[] */
2416
private $endpoints = [];
2517

@@ -30,17 +22,7 @@ class Api implements Contract\Api
3022
private $schemas = [];
3123

3224
/** @todo add support for security schemas */
33-
public function __construct(
34-
string $title,
35-
string $version,
36-
string $description,
37-
?string $email = null
38-
) {
39-
$this->title = $title;
40-
$this->version = $version;
41-
$this->description = $description;
42-
$this->email = $email;
43-
}
25+
public function __construct(private string $title, private string $version, private string $description, private ?string $email = null) {}
4426

4527
public function addEndpoint(Endpoint $endpoint): void
4628
{

src/Bridge/OpenApi/Model/JsonApi/Endpoint/CreateResourceEndpoint.php

+3-13
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,18 @@
1414

1515
class CreateResourceEndpoint implements Endpoint
1616
{
17-
private ReadSchema $readSchema;
18-
19-
private CreateSchema $createSchema;
20-
21-
private string $path;
22-
2317
/** @var Response[] */
2418
private array $responses;
2519

2620
/**
2721
* @param Response[] $errorResponses
2822
*/
2923
public function __construct(
30-
ReadSchema $readSchema,
31-
CreateSchema $createSchema,
32-
string $path,
24+
private ReadSchema $readSchema,
25+
private CreateSchema $createSchema,
26+
private string $path,
3327
array $errorResponses = []
3428
) {
35-
$this->createSchema = $createSchema;
36-
$this->readSchema = $readSchema;
37-
$this->path = $path;
38-
3929
$this->responses = array_merge(
4030
[
4131
new ResourceCreatedResponse($this->readSchema),

src/Bridge/OpenApi/Model/JsonApi/Endpoint/GetResourceEndpoint.php

+3-13
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,25 @@
1515

1616
class GetResourceEndpoint implements Endpoint
1717
{
18-
private ReadSchema $readSchema;
19-
20-
private string $path;
21-
2218
/** @var Response[] */
2319
private array $responses;
2420

2521
/** @var ReadSchema[] */
2622
private array $includes;
2723

28-
/** @var null|mixed[] */
29-
private ?array $fields;
30-
3124
/**
3225
* @param ReadSchema[] $includes
3326
* @param null|mixed[] $fields
3427
* @param mixed[] $errorResponses
3528
*/
3629
public function __construct(
37-
ReadSchema $readSchema,
38-
string $path,
30+
private ReadSchema $readSchema,
31+
private string $path,
3932
array $includes,
40-
?array $fields,
33+
private ?array $fields,
4134
array $errorResponses = []
4235
) {
4336
Assertion::allIsInstanceOf($includes, ReadSchema::class);
44-
$this->readSchema = $readSchema;
45-
$this->path = $path;
4637
$this->includes = $includes;
4738

4839
/** @var Response[] $mergedResponses */
@@ -51,7 +42,6 @@ public function __construct(
5142
], $errorResponses);
5243

5344
$this->responses = $mergedResponses;
54-
$this->fields = $fields;
5545
}
5646

5747
public function getMethod(): string

src/Bridge/OpenApi/Model/JsonApi/Endpoint/ResourceCollectionEndpoint.php

+13-37
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,29 @@
1616

1717
class ResourceCollectionEndpoint implements Endpoint
1818
{
19-
private ReadSchema $schema;
20-
21-
private string $path;
22-
2319
/** @var Response[] */
2420
private array $responses;
2521

26-
/** @var mixed[] */
27-
private array $filters;
28-
29-
/** @var array<string, ReadSchema> */
30-
private array $includes;
31-
32-
/** @var mixed[] */
33-
private array $fields;
34-
35-
/**
36-
* @var mixed[]
37-
*
38-
* @psalm-suppress UnusedProperty
39-
*/
40-
private array $sorts;
41-
42-
private ?Schema $pagination;
43-
4422
/**
4523
* @param Filter[] $filters
4624
* @param array<string, ReadSchema> $includes
4725
*/
4826
public function __construct(
49-
ReadSchema $schema,
50-
string $path,
51-
array $filters = [],
52-
array $sorts = [],
53-
array $includes = [],
54-
array $fields = [],
55-
?Schema $pagination = null,
27+
private ReadSchema $schema,
28+
private string $path,
29+
private array $filters = [],
30+
/**
31+
* @var mixed[]
32+
*
33+
* @psalm-suppress UnusedProperty
34+
*/
35+
private array $sorts = [],
36+
private array $includes = [],
37+
/** @var mixed[] */
38+
private array $fields = [],
39+
private ?Schema $pagination = null,
5640
array $errorResponses = []
5741
) {
58-
$this->schema = $schema;
59-
$this->path = $path;
60-
$this->includes = $includes;
61-
6242
Assertion::allIsInstanceOf($this->includes, ReadSchema::class);
6343

6444
/** @var Response[] $responses */
@@ -70,10 +50,6 @@ public function __construct(
7050
);
7151

7252
$this->responses = $responses;
73-
$this->filters = $filters;
74-
$this->sorts = $sorts;
75-
$this->fields = $fields;
76-
$this->pagination = $pagination;
7753
}
7854

7955
public function getMethod(): string

src/Bridge/OpenApi/Model/JsonApi/Endpoint/UpdateResourceEndpoint.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
class UpdateResourceEndpoint implements Endpoint
1616
{
17-
private UpdateSchema $resourceUpdateSchema;
18-
19-
private string $path;
20-
2117
/** @var Response[] */
2218
private array $responses;
2319

@@ -26,13 +22,10 @@ class UpdateResourceEndpoint implements Endpoint
2622
*/
2723
public function __construct(
2824
ReadSchema $resourceReadSchema,
29-
UpdateSchema $resourceUpdateSchema,
30-
string $path,
25+
private UpdateSchema $resourceUpdateSchema,
26+
private string $path,
3127
array $errorResponses = []
3228
) {
33-
$this->resourceUpdateSchema = $resourceUpdateSchema;
34-
$this->path = $path;
35-
3629
$this->responses = array_merge(
3730
[new ResourceUpdatedResponse($resourceReadSchema)],
3831
$errorResponses

src/Bridge/OpenApi/Model/JsonApi/Requests/CreateResourceRequest.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,7 @@
99

1010
class CreateResourceRequest implements Request
1111
{
12-
private string $resourceType;
13-
14-
private ResourceSchema $schema;
15-
16-
public function __construct(string $resourceType, ResourceSchema $schema)
17-
{
18-
$this->resourceType = $resourceType;
19-
$this->schema = $schema;
20-
}
12+
public function __construct(private string $resourceType, private ResourceSchema $schema) {}
2113

2214
public function getContentType(): string
2315
{

src/Bridge/OpenApi/Model/JsonApi/Requests/UpdateResourceRequest.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,7 @@
99

1010
class UpdateResourceRequest implements Request
1111
{
12-
private string $resourceType;
13-
14-
private UpdateSchema $schema;
15-
16-
public function __construct(string $resourceType, UpdateSchema $schema)
17-
{
18-
$this->resourceType = $resourceType;
19-
$this->schema = $schema;
20-
}
12+
public function __construct(private string $resourceType, private UpdateSchema $schema) {}
2113

2214
public function getContentType(): string
2315
{

src/Bridge/OpenApi/Model/JsonApi/Response/CollectionResponse.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@
1111

1212
class CollectionResponse implements Response
1313
{
14-
private ReadSchema $schema;
15-
1614
/** @var array<string, ReadSchema> */
1715
private array $includes;
1816

1917
/**
2018
* @param array<string, ReadSchema> $includes
2119
*/
22-
public function __construct(ReadSchema $schema, array $includes)
20+
public function __construct(private ReadSchema $schema, array $includes)
2321
{
24-
$this->schema = $schema;
2522
Assertion::allIsInstanceOf($includes, ReadSchema::class);
2623
$this->includes = $includes;
2724
}

src/Bridge/OpenApi/Model/JsonApi/Response/ResourceResponse.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@
1111

1212
class ResourceResponse implements Response
1313
{
14-
private ReadSchema $readSchema;
15-
1614
/** @var array<string, ReadSchema> */
1715
private array $includes;
1816

1917
/**
2018
* @param array<string, ReadSchema> $includes
2119
*/
22-
public function __construct(ReadSchema $readSchema, array $includes = [])
20+
public function __construct(private ReadSchema $readSchema, array $includes = [])
2321
{
2422
Assertion::allIsInstanceOf($includes, ReadSchema::class);
25-
$this->readSchema = $readSchema;
2623
$this->includes = $includes;
2724
}
2825

src/Bridge/OpenApi/Model/JsonApi/Schema/AttributeSchema.php

+1-27
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,7 @@
99

1010
class AttributeSchema implements Schema
1111
{
12-
private string $name;
13-
14-
private string $type;
15-
16-
private bool $nullable;
17-
18-
private ?string $description;
19-
20-
private ?string $format;
21-
22-
private ?string $example;
23-
24-
public function __construct(
25-
string $name,
26-
string $type,
27-
bool $nullable,
28-
?string $description,
29-
?string $format,
30-
?string $example
31-
) {
32-
$this->name = $name;
33-
$this->type = $type;
34-
$this->nullable = $nullable;
35-
$this->description = $description;
36-
$this->format = $format;
37-
$this->example = $example;
38-
}
12+
public function __construct(private string $name, private string $type, private bool $nullable, private ?string $description, private ?string $format, private ?string $example) {}
3913

4014
public function toOpenApi(): array
4115
{

src/Bridge/OpenApi/Model/JsonApi/Schema/Filter/Filter.php

+1-12
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,7 @@
1010

1111
final class Filter
1212
{
13-
private string $name;
14-
15-
private Schema $schema;
16-
17-
private bool $required;
18-
19-
public function __construct(string $name, Schema $schema, bool $required = false)
20-
{
21-
$this->name = $name;
22-
$this->schema = $schema;
23-
$this->required = $required;
24-
}
13+
public function __construct(private string $name, private Schema $schema, private bool $required = false) {}
2514

2615
public static function integer(
2716
string $name,

src/Bridge/OpenApi/Model/JsonApi/Schema/Filter/FilterSetQueryParam.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,10 @@
88

99
class FilterSetQueryParam implements Schema
1010
{
11-
private string $name;
12-
13-
/** @var Filter[] */
14-
private array $filters;
15-
1611
/**
1712
* @param Filter[] $filters
1813
*/
19-
public function __construct(string $name, array $filters)
20-
{
21-
$this->name = $name;
22-
$this->filters = $filters;
23-
}
14+
public function __construct(private string $name, private array $filters) {}
2415

2516
public function toOpenApi(): array
2617
{

src/Bridge/OpenApi/Model/JsonApi/Schema/IntegerSchema.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@
88

99
class IntegerSchema implements Schema
1010
{
11-
private ?int $example;
12-
13-
private ?string $description;
14-
15-
public function __construct(?int $example, ?string $description)
16-
{
17-
$this->example = $example;
18-
$this->description = $description;
19-
}
11+
public function __construct(private ?int $example, private ?string $description) {}
2012

2113
public function toOpenApi(): array
2214
{

0 commit comments

Comments
 (0)