Skip to content

Fix/tests correction & rector upgrade to php 8.3 #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-beberlei-assert": "^1.1",
"thecodingmachine/phpstan-strict-rules": "^1.0"
"thecodingmachine/phpstan-strict-rules": "^1.0",
"rector/rector": "^1.0"
},
"autoload": {
"psr-4": {
Expand Down
61 changes: 60 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPhpSets(true)
->withRules([
]);
24 changes: 1 addition & 23 deletions src/Bridge/OpenApi/Model/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@

class Api implements Contract\Api
{
/** @var string */
private $title;

/** @var string */
private $version;

/** @var string */
private $description;

/** @var null|string */
private $email;

/** @var Endpoint[] */
private $endpoints = [];

Expand All @@ -34,17 +22,7 @@ class Api implements Contract\Api
private $schemas = [];

/** @todo add support for security schemas */
public function __construct(
string $title,
string $version,
string $description,
?string $email = null
) {
$this->title = $title;
$this->version = $version;
$this->description = $description;
$this->email = $email;
}
public function __construct(private string $title, private string $version, private string $description, private ?string $email = null) {}

public function addEndpoint(Endpoint $endpoint): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,18 @@

class CreateResourceEndpoint implements Endpoint
{
/** @var ReadSchema */
private $readSchema;

/** @var CreateSchema */
private $createSchema;

/** @var string */
private $path;

/** @var Response[] */
private $responses;
private array $responses;

/**
* @param Response[] $errorResponses
*/
public function __construct(
ReadSchema $readSchema,
CreateSchema $createSchema,
string $path,
private ReadSchema $readSchema,
private CreateSchema $createSchema,
private string $path,
array $errorResponses = []
) {
$this->createSchema = $createSchema;
$this->readSchema = $readSchema;
$this->path = $path;

$this->responses = array_merge(
[
new ResourceCreatedResponse($this->readSchema),
Expand Down
22 changes: 5 additions & 17 deletions src/Bridge/OpenApi/Model/JsonApi/Endpoint/GetResourceEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,25 @@

class GetResourceEndpoint implements Endpoint
{
/** @var ReadSchema */
private $readSchema;

/** @var string */
private $path;

/** @var Response[] */
private $responses;
private array $responses;

/** @var ReadSchema[] */
private $includes;

/** @var null|mixed[] */
private $fields;
private array $includes;

/**
* @param ReadSchema[] $includes
* @param null|mixed[] $fields
* @param mixed[] $errorResponses
*/
public function __construct(
ReadSchema $readSchema,
string $path,
private ReadSchema $readSchema,
private string $path,
array $includes,
?array $fields,
private ?array $fields,
array $errorResponses = []
) {
Assertion::allIsInstanceOf($includes, ReadSchema::class);
$this->readSchema = $readSchema;
$this->path = $path;
$this->includes = $includes;

/** @var Response[] $mergedResponses */
Expand All @@ -53,7 +42,6 @@ public function __construct(
], $errorResponses);

$this->responses = $mergedResponses;
$this->fields = $fields;
}

public function getMethod(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,29 @@

class ResourceCollectionEndpoint implements Endpoint
{
/** @var ReadSchema */
private $schema;

/** @var string */
private $path;

/** @var Response[] */
private $responses;

/** @var mixed[] */
private $filters;

/** @var array<string, ReadSchema> */
private $includes;

/** @var mixed[] */
private $fields;

/**
* @var mixed[]
*
* @psalm-suppress UnusedProperty
*/
private $sorts;

/** @var null|Schema */
private $pagination;
private array $responses;

/**
* @param Filter[] $filters
* @param array<string, ReadSchema> $includes
*/
public function __construct(
ReadSchema $schema,
string $path,
array $filters = [],
array $sorts = [],
array $includes = [],
array $fields = [],
?Schema $pagination = null,
private ReadSchema $schema,
private string $path,
private array $filters = [],
/**
* @var mixed[]
*
* @psalm-suppress UnusedProperty
*/
private array $sorts = [],
private array $includes = [],
/** @var mixed[] */
private array $fields = [],
private ?Schema $pagination = null,
array $errorResponses = []
) {
$this->schema = $schema;
$this->path = $path;
$this->includes = $includes;

Assertion::allIsInstanceOf($this->includes, ReadSchema::class);

/** @var Response[] $responses */
Expand All @@ -73,10 +50,6 @@ public function __construct(
);

$this->responses = $responses;
$this->filters = $filters;
$this->sorts = $sorts;
$this->fields = $fields;
$this->pagination = $pagination;
}

public function getMethod(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,18 @@

class UpdateResourceEndpoint implements Endpoint
{
/** @var UpdateSchema */
private $resourceUpdateSchema;

/** @var string */
private $path;

/** @var Response[] */
private $responses;
private array $responses;

/**
* @param Response[] $errorResponses
*/
public function __construct(
ReadSchema $resourceReadSchema,
UpdateSchema $resourceUpdateSchema,
string $path,
private UpdateSchema $resourceUpdateSchema,
private string $path,
array $errorResponses = []
) {
$this->resourceUpdateSchema = $resourceUpdateSchema;
$this->path = $path;

$this->responses = array_merge(
[new ResourceUpdatedResponse($resourceReadSchema)],
$errorResponses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@

class CreateResourceRequest implements Request
{
/** @var string */
private $resourceType;

/** @var ResourceSchema */
private $schema;

public function __construct(string $resourceType, ResourceSchema $schema)
{
$this->resourceType = $resourceType;
$this->schema = $schema;
}
public function __construct(private string $resourceType, private ResourceSchema $schema) {}

public function getContentType(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@

class UpdateResourceRequest implements Request
{
/** @var string */
private $resourceType;

/** @var UpdateSchema */
private $schema;

public function __construct(string $resourceType, UpdateSchema $schema)
{
$this->resourceType = $resourceType;
$this->schema = $schema;
}
public function __construct(private string $resourceType, private UpdateSchema $schema) {}

public function getContentType(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@

class CollectionResponse implements Response
{
/** @var ReadSchema */
private $schema;

/** @var array<string, ReadSchema> */
private $includes;
private array $includes;

/**
* @param array<string, ReadSchema> $includes
*/
public function __construct(ReadSchema $schema, array $includes)
public function __construct(private ReadSchema $schema, array $includes)
{
$this->schema = $schema;
Assertion::allIsInstanceOf($includes, ReadSchema::class);
$this->includes = $includes;
}
Expand Down
Loading