Skip to content
Open
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
8 changes: 1 addition & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,9 @@ jobs:
with:
php: "8.2"

test81:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
with:
php: "8.1"

testlower:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester.yml@master
with:
php: "8.1"
php: "8.2"
composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest"
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"require": {
"php": ">=8.1",
"php": ">=8.2",
"ext-json": "*",
"nette/di": "^3.1.8",
"contributte/psr7-http-message": "^0.9.0 || ^0.10.0",
Expand All @@ -33,16 +33,16 @@
"contributte/qa": "^0.4",
"contributte/dev": "^0.4",
"contributte/tester": "^0.3",
"contributte/phpstan": "^0.1",
"contributte/phpstan": "^0.2",
"mockery/mockery": "^1.6.6",
"nette/application": "^3.1.4",
"nette/di": "^3.1.8",
"nette/http": "^3.2.3",
"psr/log": "^2.0.0 || ^3.0.0",
"symfony/console": "^6.4.0 || ^7.0.0",
"symfony/translation": "^6.4.0 | ^7.0.0",
"symfony/validator": "^6.4.0 || ^7.0.0",
"symfony/yaml": "^6.4.0 || ^7.0.0",
"symfony/console": "^6.4.0 || ^7.0.0 || ^8.0.0",
"symfony/translation": "^6.4.0 | ^7.0.0 || ^8.0.0",
"symfony/validator": "^6.4.0 || ^7.0.0 || ^8.0.0",
"symfony/yaml": "^6.4.0 || ^7.0.0 || ^8.0.0",
"tracy/tracy": "^2.10.5"
},
"provide": {
Expand Down
20 changes: 4 additions & 16 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,8 @@ parameters:
- .docs

reportMaybesInPropertyPhpDocTypes: false
checkGenericClassInNonGenericObjectType: false

ignoreErrors:
# Intended property access - required for reflection
- '#^Variable property access on (\$this|static)\(Apitte\\Core\\Mapping\\(Request|Response)\\BasicEntity\)\.$#'
- '#^Variable property access on Apitte\\Core\\Mapping\\Request\\BasicEntity\.$#'

# Phpstan bug
- message: '#^Parameter \#1 \$argument of class ReflectionClass constructor expects class-string<T of object>|T of object, string given\.$#'
path: %currentWorkingDirectory%/src/Core/DI/Loader/DoctrineAnnotationLoader.php

# Missing strict comparison
- '#^Only booleans are allowed in#'

Expand Down Expand Up @@ -48,13 +39,6 @@ parameters:
# This should not happen because null is returned on error
- '#Method Apitte\\Core\\Utils\\Helpers::slashless\(\) should return string but returns string\|null\.#'

# To pass php8.0 tests where library doesn't have isSingle()
- message: """
#^Call to deprecated method isSingle\\(\\) of class Nette\\\\Utils\\\\Type\\:
use isSimple\\(\\)$#
"""
path: %currentWorkingDirectory%/src/OpenApi/SchemaDefinition/Entity/EntityAdapter.php

# Nette changed return typehint
- message: "#^Method Apitte\\\\OpenApi\\\\SchemaDefinition\\\\Entity\\\\EntityAdapter\\:\\:getNativePropertyType\\(\\) should return string but returns array\\<string\\>\\|string\\.$#"
path: %currentWorkingDirectory%/src/OpenApi/SchemaDefinition/Entity/EntityAdapter.php
Expand All @@ -66,3 +50,7 @@ parameters:
# Support for doctrine/annotations ^1
- message: "#^Call to function method_exists\\(\\) with 'Doctrine\\\\\\\\Common\\\\\\\\Annotations\\\\\\\\AnnotationRegistry' and 'registerUniqueLoader' will always evaluate to false\\.$#"
path: src/Core/DI/LoaderFactory/DualReaderFactory.php

- message: "#^Dead catch - TypeError is never thrown in the try block.$#"
path: src/Core/Mapping/Parameter/DateTimeTypeMapper.php
count: 1
4 changes: 2 additions & 2 deletions ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<description>Contributte</description>

<!-- Extending rulesets -->
<rule ref="./vendor/contributte/qa/ruleset-8.0.xml"/>
<rule ref="./vendor/contributte/qa/ruleset-8.2.xml"/>

<!-- Specific rules -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
Expand All @@ -26,7 +26,7 @@
</rule>

<rule ref="SlevomatCodingStandard.PHP.DisallowReference">
<exclude-pattern>src/Core/Schema/Serialization/ArraySerializator.php</exclude-pattern>
<exclude-pattern>src/Core/Schema/Serialization/ArraySerializer.php</exclude-pattern>
<exclude-pattern>tests/Cases/OpenApi/Schema/ExamplesTest.php</exclude-pattern>
</rule>

Expand Down
10 changes: 5 additions & 5 deletions src/Console/Command/RouteDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ class RouteDumpCommand extends Command

private const TABLE_HEADER = ['Method', 'Path', 'Handler', ' ', 'Parameters'];

private Schema $schema;

public function __construct(Schema $schema)
public function __construct(
private readonly Schema $schema,
)
{
parent::__construct();

$this->schema = $schema;
}

protected function configure(): void
Expand Down Expand Up @@ -59,6 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

/** @var Endpoint[][] $endpointsByHandler */
$endpointsByHandler = [];

foreach ($endpoints as $endpoint) {
$endpointsByHandler[$endpoint->getHandler()->getClass()][] = $endpoint;
}
Expand Down Expand Up @@ -115,6 +114,7 @@ private function formatParameters(array $parameters): string

foreach ($paramsByIn as $in => $params) {
$result .= sprintf('<fg=cyan>%s</>', $in) . ': ' . implode(', ', $params);

if ($params !== end($paramsByIn)) {
$result .= ' | ';
}
Expand Down
8 changes: 3 additions & 5 deletions src/Core/Annotation/Controller/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
class Id
{

private string $name;

public function __construct(string $name)
public function __construct(
private readonly string $name,
)
{
if ($name === '') {
throw new AnnotationException('Empty @Id given');
}

$this->name = $name;
}

public function getName(): string
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Annotation/Controller/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Method
{

/** @var string[] */
private array $methods = [];
private readonly array $methods;

/**
* @param string[]|string $methods
Expand All @@ -29,7 +29,7 @@ public function __construct(array|string $methods)
}

// Wrap single given method into array
if (! is_array($methods)) {
if (!is_array($methods)) {
$methods = [$methods];
}

Expand Down
15 changes: 5 additions & 10 deletions src/Core/Annotation/Controller/Negotiation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@
class Negotiation
{

private string $suffix;

private bool $default;

private ?string $renderer;

public function __construct(string $suffix, bool $default = false, ?string $renderer = null)
public function __construct(
private readonly string $suffix,
private readonly bool $default = false,
private readonly ?string $renderer = null,
)
{
$this->suffix = $suffix;
$this->default = $default;
$this->renderer = $renderer;
}

public function getSuffix(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Annotation/Controller/Negotiations.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Negotiations
{

/** @var Negotiation[] */
private array $negotiations = [];
private readonly array $negotiations;

/**
* @param Negotiation[]|Negotiation $negotiations
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Annotation/Controller/OpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class OpenApi
{

private string $data;
private readonly string $data;

public function __construct(string $data)
{
Expand Down
8 changes: 3 additions & 5 deletions src/Core/Annotation/Controller/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
class Path
{

private string $path;

public function __construct(string $path)
public function __construct(
private readonly string $path,
)
{
if ($path === '') {
throw new AnnotationException('Empty @Path given');
}

$this->path = $path;
}

public function getPath(): string
Expand Down
19 changes: 6 additions & 13 deletions src/Core/Annotation/Controller/RequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,13 @@
class RequestBody
{

private ?string $description;

private ?string $entity;

private bool $required;

private bool $validation;

public function __construct(?string $description = null, ?string $entity = null, bool $required = false, bool $validation = true)
public function __construct(
private readonly ?string $description = null,
private readonly ?string $entity = null,
private readonly bool $required = false,
private readonly bool $validation = true,
)
{
$this->description = $description;
$this->entity = $entity;
$this->required = $required;
$this->validation = $validation;
}

public function getEntity(): ?string
Expand Down
42 changes: 8 additions & 34 deletions src/Core/Annotation/Controller/RequestParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,18 @@
class RequestParameter
{

private string $name;

private string $type;

private ?string $description;

private string $in;

private bool $required;

private bool $deprecated;

private bool $allowEmpty;

/** @var list<string|int>|null */
private ?array $enum;

/**
* @param list<string|int>|null $enum
*/
public function __construct(
string $name,
string $type,
string $in = EndpointParameter::IN_PATH,
bool $required = true,
bool $allowEmpty = false,
bool $deprecated = false,
?string $description = null,
?array $enum = null
private readonly string $name,
private readonly string $type,
private readonly string $in = EndpointParameter::IN_PATH,
private readonly bool $required = true,
private readonly bool $allowEmpty = false,
private readonly bool $deprecated = false,
private readonly ?string $description = null,
private readonly ?array $enum = null
)
{
if ($name === '') {
Expand All @@ -59,15 +42,6 @@ public function __construct(
if (!in_array($in, EndpointParameter::IN, true)) {
throw new AnnotationException('Invalid @RequestParameter in given');
}

$this->name = $name;
$this->type = $type;
$this->required = $required;
$this->allowEmpty = $allowEmpty;
$this->deprecated = $deprecated;
$this->description = $description;
$this->in = $in;
$this->enum = $enum;
}

public function getName(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Annotation/Controller/RequestParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RequestParameters
{

/** @var RequestParameter[] */
private array $parameters = [];
private readonly array $parameters;

/**
* @param RequestParameter[]|RequestParameter $parameters
Expand Down
16 changes: 5 additions & 11 deletions src/Core/Annotation/Controller/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,15 @@
class Response
{

private string $code;

private string $description;

private ?string $entity;

public function __construct(string $description, string $code = 'default', ?string $entity = null)
public function __construct(
private readonly string $description,
private readonly string $code = 'default',
private readonly ?string $entity = null,
)
{
if (empty($description)) {
throw new AnnotationException('Empty @Response description given');
}

$this->code = $code;
$this->entity = $entity;
$this->description = $description;
}

public function getDescription(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Annotation/Controller/Responses.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Responses
{

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

/**
* @param Response[]|Response $responses
Expand Down
12 changes: 4 additions & 8 deletions src/Core/Annotation/Controller/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@
class Tag
{

private string $name;

private ?string $value;

public function __construct(string $name, ?string $value = null)
public function __construct(
private readonly string $name,
private readonly ?string $value = null,
)
{
if ($name === '') {
throw new AnnotationException('Empty @Tag name given');
}

$this->name = $name;
$this->value = $value;
}

public function getName(): string
Expand Down
Loading