Skip to content
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
14 changes: 8 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
php-version:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
dependencies:
- "lowest"
- "highest"
Expand Down Expand Up @@ -53,7 +55,7 @@ jobs:
operating-system:
- "ubuntu-latest"
php-version:
- "8.2"
- "8.4"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
Expand Down Expand Up @@ -81,7 +83,7 @@ jobs:
operating-system:
- "ubuntu-latest"
php-version:
- "8.2"
- "8.4"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
Expand Down Expand Up @@ -109,7 +111,7 @@ jobs:
operating-system:
- "ubuntu-latest"
php-version:
- "8.2"
- "8.4"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
Expand Down Expand Up @@ -137,7 +139,7 @@ jobs:
operating-system:
- "ubuntu-latest"
php-version:
- "8.2"
- "8.4"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
Expand Down Expand Up @@ -170,7 +172,7 @@ jobs:
operating-system:
- "ubuntu-latest"
php-version:
- "8.2"
- "8.4"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
Expand Down Expand Up @@ -201,7 +203,7 @@ jobs:
operating-system:
- "ubuntu-latest"
php-version:
- "8.2"
- "8.4"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
Expand Down
24 changes: 9 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@
"email": "dk@csgo.com"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/onmoon/php-openapi"
}
],
"require": {
"php": "^8.1",
"ext-json": "*",
"cebe/php-openapi": "1.6.99",
"devizzent/cebe-php-openapi": "1.1.4",
"league/openapi-psr7-validator": "^0.22.0",
"lukasoppermann/http-status": "^4.0",
"nikic/php-parser": "^4.19",
"nikic/php-parser": "^v5.4",
"nyholm/psr7": "^1.5",
"phpdocumentor/reflection-docblock": "^5.3",
"sspat/reserved-words": "^3.0",
Expand All @@ -47,23 +41,23 @@
"symfony/psr-http-message-bridge": "^6.4|^7.0",
"symfony/routing": "^6.4|^7.0",
"symfony/yaml": "^6.4|^7.0",
"thecodingmachine/safe": "^1.3|^2"
"thecodingmachine/safe": "^3.1"
},
"require-dev": {
"doctrine/coding-standard": "^12.0",
"matthiasnoback/symfony-config-test": "^5.1",
"matthiasnoback/symfony-dependency-injection-test": "^5.1",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan-strict-rules": "^1.6",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^10.5",
"roave/infection-static-analysis-plugin": "^1.35",
"roave/infection-static-analysis-plugin": "^1.37",
"squizlabs/php_codesniffer": "^3.10",
"symfony/browser-kit": "^6.4|^7.0",
"symfony/dom-crawler": "^6.4|^7.0",
"symfony/framework-bundle": "^6.4|^7.0",
"thecodingmachine/phpstan-safe-rule": "^1.2",
"vimeo/psalm": "^5.24"
"thecodingmachine/phpstan-safe-rule": "v1.4",
"vimeo/psalm": "^6.10"
},
"minimum-stability": "stable",
"prefer-stable": true,
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGenerator/ApiServerCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use const DIRECTORY_SEPARATOR;

class ApiServerCodeGenerator
final class ApiServerCodeGenerator
{
private GraphGenerator $graphGenerator;
private NameGenerator $nameGenerator;
Expand Down
1 change: 1 addition & 0 deletions src/CodeGenerator/AttributeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OnMoon\OpenApiServerBundle\CodeGenerator\Definitions\PropertyDefinition;
use OnMoon\OpenApiServerBundle\Specification\Definitions\Property;

/** @psalm-suppress ClassMustBeFinal */
class AttributeGenerator
{
public function setAllAttributes(GraphDefinition $graph): void
Expand Down
7 changes: 6 additions & 1 deletion src/CodeGenerator/Definitions/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

namespace OnMoon\OpenApiServerBundle\CodeGenerator\Definitions;

use function Safe\substr;
use Override;

use function strrpos;
use function substr;

class ClassDefinition implements ClassReference
{
private string $className;
private string $namespace;

#[Override]
final public function getClassName(): string
{
return $this->className;
Expand All @@ -24,6 +27,7 @@ final public function setClassName(string $className): self
return $this;
}

#[Override]
final public function getNamespace(): string
{
return $this->namespace;
Expand All @@ -36,6 +40,7 @@ final public function setNamespace(string $namespace): self
return $this;
}

#[Override]
final public function getFQCN(): string
{
return $this->namespace . '\\' . $this->className;
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGenerator/Definitions/ComponentDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace OnMoon\OpenApiServerBundle\CodeGenerator\Definitions;

class ComponentDefinition
final class ComponentDefinition
{
private DtoDefinition $dto;

Expand Down
8 changes: 7 additions & 1 deletion src/CodeGenerator/Definitions/ComponentReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,33 @@

namespace OnMoon\OpenApiServerBundle\CodeGenerator\Definitions;

class ComponentReference implements DtoReference
use Override;

final class ComponentReference implements DtoReference
{
public function __construct(private ComponentDefinition $referencedComponent)
{
}

#[Override]
public function getClassName(): string
{
return $this->referencedComponent->getDto()->getClassName();
}

#[Override]
public function getNamespace(): string
{
return $this->referencedComponent->getDto()->getNamespace();
}

#[Override]
public function getFQCN(): string
{
return $this->referencedComponent->getDto()->getFQCN();
}

#[Override]
public function isEmpty(): bool
{
return $this->referencedComponent->getDto()->isEmpty();
Expand Down
4 changes: 3 additions & 1 deletion src/CodeGenerator/Definitions/DtoDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
namespace OnMoon\OpenApiServerBundle\CodeGenerator\Definitions;

use OnMoon\OpenApiServerBundle\Interfaces\Dto;
use Override;

use function count;

class DtoDefinition extends GeneratedClassDefinition implements DtoReference
final class DtoDefinition extends GeneratedClassDefinition implements DtoReference
{
/** @var PropertyDefinition[] $properties; */
private array $properties;
Expand All @@ -21,6 +22,7 @@ public function __construct(array $properties)
$this->properties = $properties;
}

#[Override]
final public function isEmpty(): bool
{
return count($this->properties) === 0;
Expand Down
1 change: 1 addition & 0 deletions src/CodeGenerator/FileGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use function array_push;

/** @psalm-suppress ClassMustBeFinal */
class FileGenerator
{
private DtoCodeGenerator $dtoGenerator;
Expand Down
3 changes: 3 additions & 0 deletions src/CodeGenerator/Filesystem/FilePutContentsFileWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace OnMoon\OpenApiServerBundle\CodeGenerator\Filesystem;

use Override;

use function is_dir;
use function Safe\file_put_contents;
use function Safe\mkdir;
Expand All @@ -19,6 +21,7 @@ public function __construct(int $dirPemissions)
$this->dirPemissions = $dirPemissions;
}

#[Override]
public function write(string $path, string $filename, string $contents): void
{
if (! is_dir($path)) {
Expand Down
1 change: 1 addition & 0 deletions src/CodeGenerator/GraphGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use function array_map;
use function count;

/** @psalm-suppress ClassMustBeFinal */
class GraphGenerator
{
private SpecificationLoader $loader;
Expand Down
1 change: 1 addition & 0 deletions src/CodeGenerator/NameGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use function ucfirst;

/** @psalm-suppress ClassMustBeFinal */
class NameGenerator
{
private const DTO_NAMESPACE = 'Dto';
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGenerator/Naming/CannotCreateNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use OnMoon\OpenApiServerBundle\Exception\OpenApiError;

use function Safe\sprintf;
use function sprintf;

final class CannotCreateNamespace extends OpenApiError
{
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGenerator/Naming/CannotCreatePropertyName.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use OnMoon\OpenApiServerBundle\Exception\OpenApiError;

use function Safe\sprintf;
use function sprintf;

final class CannotCreatePropertyName extends OpenApiError
{
Expand Down
7 changes: 7 additions & 0 deletions src/CodeGenerator/Naming/DefaultNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OnMoon\OpenApiServerBundle\CodeGenerator\NameGenerator;
// phpcs:ignore SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse
use OnMoon\OpenApiServerBundle\Interfaces\RequestHandler;
use Override;
use sspat\ReservedWords\ReservedWords;

use function array_map;
Expand Down Expand Up @@ -37,11 +38,13 @@ public function __construct(
$this->languageLevel = $languageLevel;
}

#[Override]
public function isAllowedPhpPropertyName(string $name): bool
{
return preg_match('/^\d/', $name) === 0 && preg_match('/^[A-Za-z0-9_]+$/', $name) === 1;
}

#[Override]
public function getInterfaceFQCN(string $apiNameSpace, string $operationId): string
{
/** @psalm-var class-string<RequestHandler> $interfaceNamespace */
Expand All @@ -56,6 +59,7 @@ public function getInterfaceFQCN(string $apiNameSpace, string $operationId): str
return $interfaceNamespace;
}

#[Override]
public function stringToNamespace(string $text): string
{
$namespace = $this->padStringThatIsReservedNamespaceName(
Expand All @@ -71,6 +75,7 @@ public function stringToNamespace(string $text): string
return $namespace;
}

#[Override]
public function stringToMethodName(string $text): string
{
$propertyName = $this->padStringThatIsReservedMethodName(
Expand All @@ -88,11 +93,13 @@ public function stringToMethodName(string $text): string
return $propertyName;
}

#[Override]
public function buildNamespace(string ...$parts): string
{
return implode('\\', array_map(static fn (string $part): string => trim($part, '\\'), $parts));
}

#[Override]
public function buildPath(string ...$parts): string
{
return implode(
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGenerator/PhpParserGenerators/CodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use function array_map;
use function count;
use function implode;
use function Safe\sprintf;
use function sprintf;
use function trim;

use const PHP_EOL;
Expand Down
10 changes: 5 additions & 5 deletions src/CodeGenerator/PhpParserGenerators/DtoCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@

use function array_map;
use function count;
use function Safe\sprintf;
use function sprintf;

class DtoCodeGenerator extends CodeGenerator
final class DtoCodeGenerator extends CodeGenerator
{
public function generate(DtoDefinition $definition): GeneratedFileDefinition
{
Expand Down Expand Up @@ -162,7 +162,7 @@
$docCommentLines = [];

if ($definition->getDescription() !== null) {
$docCommentLines[] = sprintf('%s', $definition->getDescription());

Check failure on line 165 in src/CodeGenerator/PhpParserGenerators/DtoCodeGenerator.php

View workflow job for this annotation

GitHub Actions / Psalm (ubuntu-latest, 8.4)

PossiblyNullArgument

src/CodeGenerator/PhpParserGenerators/DtoCodeGenerator.php:165:48: PossiblyNullArgument: Argument 2 of sprintf cannot be null, possibly null value provided (see https://psalm.dev/078)
$docCommentLines[] = '';
}

Expand Down Expand Up @@ -302,7 +302,7 @@

$statements = [];
if (count($setters) > 0) {
$statements[] = new Assign($dto, $new);
$statements[] = new Expression(new Assign($dto, $new));
foreach ($setters as $setter) {
$statements[] = $setter;
}
Expand All @@ -317,8 +317,8 @@
->method('fromArray')
->makePublic()
->makeStatic()
->setReturnType('self')
->addParam(new Param_($source, null, 'array'))
->setReturnType(new Name('self'))
->addParam(new Param_($source, null, new Name('array')))
->setDocComment($this->getDocComment(['@inheritDoc']))
->addStmts($statements);
}
Expand Down
3 changes: 2 additions & 1 deletion src/CodeGenerator/PhpParserGenerators/FileBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
use function in_array;
use function Safe\preg_match;
use function Safe\preg_replace;
use function Safe\substr;
use function substr;

/** @psalm-suppress ClassMustBeFinal */
class FileBuilder
{
private ClassDefinition $definition;
Expand Down
Loading
Loading