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
22 changes: 8 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@
"email": "[email protected]"
}
],
"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": "^4.19|^v5.0",
"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": "^1.3|^2|^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": "^1.11|^2.1",
"phpstan/phpstan-phpunit": "^1.4|^2.0",
"phpstan/phpstan-strict-rules": "^1.6|^2.0",
"phpunit/phpunit": "^10.5",
"roave/infection-static-analysis-plugin": "^1.35",
"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": "^1.2|v1.4",
"vimeo/psalm": "^5.24|^6.10"
},
"minimum-stability": "stable",
"prefer-stable": true,
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ parameters:
message: '#Method OnMoon\\OpenApiServerBundle\\Specification\\SpecificationParser::getResponseDtoDefinitions\(\) has parameter \$responses with no value type specified in iterable type array\.#'
paths:
- %currentWorkingDirectory%/src/Specification/SpecificationParser.php
-
message: '#Parameter \#1 \$json of function Safe\\json_decode expects string, resource\|string given\.#'
paths:
- %currentWorkingDirectory%/src/Serializer/ArrayDtoSerializer.php
includes:
- vendor/thecodingmachine/phpstan-safe-rule/phpstan-safe-rule.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
Expand Down
18 changes: 1 addition & 17 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
findUnusedVariablesAndParams="true"
ensureArrayStringOffsetsExist="true"
findUnusedBaselineEntry="true"
ensureOverrideAttribute="false"
findUnusedCode="false"
phpVersion="8.1"
>
Expand All @@ -19,25 +20,8 @@
<file name="src/DependencyInjection/Configuration.php" />
</errorLevel>
</MixedMethodCall>
<PossiblyUndefinedMethod>
<errorLevel type="suppress">
<file name="src/DependencyInjection/Configuration.php" />
</errorLevel>
</PossiblyUndefinedMethod>
<PropertyNotSetInConstructor errorLevel="suppress"/>
<InternalClass errorLevel="suppress"/>
<InternalMethod errorLevel="suppress"/>
<DeprecatedFunction>
<errorLevel type="suppress">
<referencedFunction name="Safe\substr" />
<referencedFunction name="Safe\sprintf" />
</errorLevel>
</DeprecatedFunction>
<ReservedWord>
<errorLevel type="suppress">
<file name="src/Controller/ApiController.php" />
<file name="src/Serializer/ArrayDtoSerializer.php" />
</errorLevel>
</ReservedWord>
</issueHandlers>
</psalm>
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
2 changes: 1 addition & 1 deletion src/CodeGenerator/Definitions/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace OnMoon\OpenApiServerBundle\CodeGenerator\Definitions;

use function Safe\substr;
use function strrpos;
use function substr;

class ClassDefinition implements ClassReference
{
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
2 changes: 1 addition & 1 deletion src/CodeGenerator/Definitions/ComponentReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace OnMoon\OpenApiServerBundle\CodeGenerator\Definitions;

class ComponentReference implements DtoReference
final class ComponentReference implements DtoReference
{
public function __construct(private ComponentDefinition $referencedComponent)
{
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGenerator/Definitions/DtoDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use function count;

class DtoDefinition extends GeneratedClassDefinition implements DtoReference
final class DtoDefinition extends GeneratedClassDefinition implements DtoReference
{
/** @var PropertyDefinition[] $properties; */
private array $properties;
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
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
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
15 changes: 8 additions & 7 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 @@ -160,9 +160,10 @@ private function generateClassProperty(FileBuilder $builder, PropertyDefinition
$property->setType($this->getTypePhp($builder, $definition));

$docCommentLines = [];
$description = $definition->getDescription();

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

Expand Down Expand Up @@ -302,7 +303,7 @@ private function generateFromArray(FileBuilder $builder, DtoDefinition $definiti

$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 +318,8 @@ private function generateFromArray(FileBuilder $builder, DtoDefinition $definiti
->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
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
use function array_map;
use function count;
use function implode;
use function Safe\sprintf;
use function sprintf;

class InterfaceCodeGenerator extends CodeGenerator
final class InterfaceCodeGenerator extends CodeGenerator
{
public function generate(RequestHandlerInterfaceDefinition $definition): GeneratedFileDefinition
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
use PhpParser\Node\Stmt\Return_;
use Psr\Container\ContainerInterface;

use function Safe\sprintf;
use function sprintf;

class ServiceSubscriberCodeGenerator extends CodeGenerator
final class ServiceSubscriberCodeGenerator extends CodeGenerator
{
public function generate(GraphDefinition $graphDefinition): GeneratedFileDefinition
{
Expand Down Expand Up @@ -69,7 +69,9 @@ public function generate(GraphDefinition $graphDefinition): GeneratedFileDefinit
} else {
foreach ($operation->getResponses() as $response) {
$responseTypes[] = new ArrayItem(
// @codeCoverageIgnoreStart
new Array_([new ArrayItem(new String_($response->getStatusCode()))], ['kind' => Array_::KIND_SHORT]),
// @codeCoverageIgnoreEnd
new ClassConstFetch(
new Name($fileBuilder->getReference($response->getResponseBody())),
'class'
Expand All @@ -79,7 +81,9 @@ public function generate(GraphDefinition $graphDefinition): GeneratedFileDefinit
}

$responseCodeMapper[] = new ArrayItem(
// @codeCoverageIgnoreStart
new Array_($responseTypes, ['kind' => Array_::KIND_SHORT]),
// @codeCoverageIgnoreEnd
new ClassConstFetch(
new Name($fileBuilder->getReference($operation->getRequestHandlerInterface())),
'class'
Expand All @@ -90,7 +94,9 @@ public function generate(GraphDefinition $graphDefinition): GeneratedFileDefinit

$httpCodeMapper = $this
->factory
// @codeCoverageIgnoreStart
->classConst('HTTP_CODES', new Array_($responseCodeMapper, ['kind' => Array_::KIND_SHORT]))
// @codeCoverageIgnoreEnd
->makePrivate();

$property = $this
Expand Down Expand Up @@ -125,6 +131,7 @@ public function generate(GraphDefinition $graphDefinition): GeneratedFileDefinit
->setDocComment('/**
* @inheritDoc
*/')
// @codeCoverageIgnoreStart
->addStmt(
new Return_(
new Array_(
Expand All @@ -133,6 +140,7 @@ public function generate(GraphDefinition $graphDefinition): GeneratedFileDefinit
)
)
);
// @codeCoverageIgnoreEnd

$getRequestHandler = $this
->factory
Expand Down
Loading