Skip to content

Commit

Permalink
feat(php8): update project into php 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sidux committed Mar 29, 2023
1 parent a87db90 commit f80d826
Show file tree
Hide file tree
Showing 44 changed files with 110 additions and 278 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.2
coverage: pcov
tools: composer:v2
env:
Expand Down
5 changes: 3 additions & 2 deletions .idea/php.xml

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

11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"sllh/composer-versions-check": true,
"ergebnis/composer-normalize": true,
"pyrech/composer-changelogs": true,
"symfony/flex": true
"symfony/flex": true,
"dereuromark/composer-versions-check": true
}
},
"autoload": {
Expand All @@ -41,7 +42,7 @@
}
},
"require": {
"php": ">=7.4",
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
Expand Down Expand Up @@ -88,8 +89,9 @@
"phpstan/phpstan-strict-rules": "^1.1",
"phpstan/phpstan-symfony": "^1.0",
"pyrech/composer-changelogs": "^1.8",
"rector/rector": "^0.15.23",
"roave/security-advisories": "dev-latest",
"sllh/composer-versions-check": "^2.0",
"dereuromark/composer-versions-check": "^0.1",
"spaze/phpstan-disallowed-calls": "^2.1",
"symfony/var-dumper": "^4.4 || ^5.0",
"symplify/easy-coding-standard": "^9.4",
Expand Down Expand Up @@ -128,6 +130,9 @@
"test": [
"@unit"
],
"rector": [
"vendor/bin/rector process src --ansi --config config/rector.php"
],
"unit": "vendor/bin/phpunit -c config/phpunit.xml --coverage-clover build/coverage/coverage.xml --exclude-group=integration",
"psalm": "vendor/bin/psalm -c config/psalm.xml",
"phpstan": "vendor/bin/phpstan analyse -c config/phpstan.neon --ansi",
Expand Down
19 changes: 19 additions & 0 deletions config/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/config',
__DIR__ . '/lib',
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
]);
};
5 changes: 1 addition & 4 deletions src/Config/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

final class Auth
{
private string $name;

/**
* @var string[]
*/
Expand All @@ -18,9 +16,8 @@ final class Auth
*/
private array $body = [];

public function __construct(string $name)
public function __construct(private readonly string $name)
{
$this->name = $name;
}

public function getName(): string
Expand Down
7 changes: 2 additions & 5 deletions src/Config/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@

final class Definition
{
private string $format;
private readonly string $path;

private string $path;

public function __construct(string $path, string $format)
public function __construct(string $path, private readonly string $format)
{
$path = trim($path, '/');
$fullPath = $path;
if (!str_starts_with($path, 'http://') && !str_starts_with($path, 'https://')) {
$fullPath = Path::getBasePath() . '/' . $path;
}
$this->path = $fullPath;
$this->format = $format;
}

public function getFormat(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function writeBaseline(array $exclude): void
->toArray()
;
if (file_exists($this->baseline)) {
$exclude = array_merge($exclude, $this->getBaseLineExclude());
$exclude = [...$exclude, ...$this->getBaseLineExclude()];
}
file_put_contents(
$this->baseline,
Expand Down
8 changes: 1 addition & 7 deletions src/Config/Plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@ final class Plan
{
private ?string $bootstrap = null;

/**
* @var Suite[]
*/
private array $suites;

/**
* @param Suite[] $suites
*/
public function __construct(array $suites)
public function __construct(private readonly array $suites)
{
$this->suites = $suites;
}

/**
Expand Down
8 changes: 1 addition & 7 deletions src/Config/Suite.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ final class Suite
*/
private array $beforeTestCaseCallbacks = [];

private Definition $definition;

private Filters $filters;

private string $name;

/**
* @var array<string, array<string, mixed>>
*/
Expand All @@ -43,10 +39,8 @@ final class Suite

private string $testCaseClass = TestCase::class;

public function __construct(string $name, Definition $definition)
public function __construct(private readonly string $name, private readonly Definition $definition)
{
$this->name = $name;
$this->definition = $definition;
$this->filters = new Filters();
$this->requester = HttpAsyncRequester::getName();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Definition/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

final class Api
{
private ?string $title;
private ?string $title = null;

private ?string $description;
private ?string $description = null;

private ?string $version;
private ?string $version = null;

private Operations $operations;

Expand Down
9 changes: 3 additions & 6 deletions src/Definition/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ final class Body
{
private Operation $parent;

private string $mediaType;

private Schema $schema;
private readonly Schema $schema;

private bool $required = false;

Expand All @@ -25,18 +23,17 @@ final class Body
*
* @throws TypeErrorException
*/
public function __construct($schema, string $mediaType = 'application/json')
public function __construct($schema, private readonly string $mediaType = 'application/json')
{
$this->schema = $schema instanceof Schema ? $schema : new Schema($schema);
$this->mediaType = $mediaType;
}

/**
* @param Schema|array<mixed> $schema
*
* @throws TypeErrorException
*/
public static function create($schema, string $mediaType = 'application/json'): self
public static function create(\cebe\openapi\spec\Schema|array $schema, string $mediaType = 'application/json'): self
{
return new self($schema, $mediaType);
}
Expand Down
8 changes: 1 addition & 7 deletions src/Definition/Example/BodyExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@ final class BodyExample

private string $mediaType = 'application/json';

/**
* @var mixed[]
*/
private array $content;

/**
* @param mixed[] $content
*/
public function __construct(array $content = [])
public function __construct(private readonly array $content = [])
{
$this->content = $content;
}

/**
Expand Down
7 changes: 2 additions & 5 deletions src/Definition/Example/OperationExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

final class OperationExample
{
private string $name;

private ?Operation $parent = null;

/**
Expand Down Expand Up @@ -50,11 +48,10 @@ final class OperationExample

private ?string $path = null;

private DeepCopy $deepCopy;
private readonly DeepCopy $deepCopy;

public function __construct(string $name, Operation $parent = null)
public function __construct(private string $name, Operation $parent = null)
{
$this->name = $name;
if (null !== $parent) {
$this->parent = $parent;
}
Expand Down
21 changes: 3 additions & 18 deletions src/Definition/Example/ResponseExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,12 @@ final class ResponseExample
*/
private array $headers = [];

/**
* @var mixed
*/
private $content;

/**
* @param mixed $content
*/
public function __construct(?string $statusCode = null, $content = null)
public function __construct(?string $statusCode = null, private mixed $content = null)
{
$this->content = $content;
$this->statusCode = $statusCode ?? $this->statusCode;
}

/**
* @param mixed $content
*/
public static function create(?string $statusCode = null, $content = null): self
public static function create(?string $statusCode = null, mixed $content = null): self
{
return new self($statusCode, $content);
}
Expand Down Expand Up @@ -106,10 +94,7 @@ public function getContent()
return $this->content;
}

/**
* @param mixed $content
*/
public function setContent($content): self
public function setContent(mixed $content): self
{
$this->content = $content;

Expand Down
4 changes: 2 additions & 2 deletions src/Definition/Loader/OpenApiDefinitionLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ private function getExamples(\cebe\openapi\spec\Operation $operation, array $par
$example = $this->extractDeepExamples($mediaType->schema);
$operationExample = $this->getExample('properties', $examples);
$operationExample->setBody(BodyExample::create($example));
} catch (ExampleNotExtractableException $e) {
} catch (ExampleNotExtractableException) {
// @ignoreException
}
}
Expand Down Expand Up @@ -430,7 +430,7 @@ private function getExamples(\cebe\openapi\spec\Operation $operation, array $par
$operationExample->setResponse(
new ResponseExample((string) $statusCode, $example)
);
} catch (ExampleNotExtractableException $e) {
} catch (ExampleNotExtractableException) {
// @ignoreException
}
}
Expand Down
15 changes: 3 additions & 12 deletions src/Definition/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ final class Operation implements Filterable

private Parameters $headers;

private string $id;

private string $method;

private Api $parent;

private string $path;

private Parameters $pathParameters;

private string $preparator;
Expand All @@ -50,13 +44,10 @@ final class Operation implements Filterable
private OperationExamples $examples;

public function __construct(
string $id,
string $path,
string $method
private readonly string $id,
private readonly string $path,
private string $method
) {
$this->id = $id;
$this->path = $path;
$this->method = $method;
$this->pathParameters = new Parameters();
$this->queryParameters = new Parameters();
$this->headers = new Parameters();
Expand Down
Loading

0 comments on commit f80d826

Please sign in to comment.