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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The preferred way to install this extension is through [composer](http://getcomp
Run

```
composer require cebe/php-openapi:dev-php-81-compat onmoon/openapi-server-bundle
composer require onmoon/openapi-server-bundle
```

Then add the bundle class to your `config/bundles.php`:
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"require": {
"php": "^8.1",
"ext-json": "*",
"devizzent/cebe-php-openapi": "1.1.4",
"devizzent/cebe-php-openapi": "^1.1.4",
"league/openapi-psr7-validator": "^0.22.0",
"lukasoppermann/http-status": "^4.0",
"nikic/php-parser": "^v5.4",
"nikic/php-parser": "^4.19|^v5.0",
"nyholm/psr7": "^1.5",
"phpdocumentor/reflection-docblock": "^5.3",
"sspat/reserved-words": "^3.0",
Expand All @@ -41,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": "^3.1"
"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": "^2.1",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"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.37",
"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": "v1.4",
"vimeo/psalm": "^6.10"
"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>
5 changes: 0 additions & 5 deletions src/CodeGenerator/Definitions/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace OnMoon\OpenApiServerBundle\CodeGenerator\Definitions;

use Override;

use function strrpos;
use function substr;

Expand All @@ -14,7 +12,6 @@ class ClassDefinition implements ClassReference
private string $className;
private string $namespace;

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

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

#[Override]
final public function getFQCN(): string
{
return $this->namespace . '\\' . $this->className;
Expand Down
6 changes: 0 additions & 6 deletions src/CodeGenerator/Definitions/ComponentReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,27 @@

namespace OnMoon\OpenApiServerBundle\CodeGenerator\Definitions;

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
2 changes: 0 additions & 2 deletions src/CodeGenerator/Definitions/DtoDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace OnMoon\OpenApiServerBundle\CodeGenerator\Definitions;

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

use function count;

Expand All @@ -22,7 +21,6 @@ public function __construct(array $properties)
$this->properties = $properties;
}

#[Override]
final public function isEmpty(): bool
{
return count($this->properties) === 0;
Expand Down
3 changes: 0 additions & 3 deletions src/CodeGenerator/Filesystem/FilePutContentsFileWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace OnMoon\OpenApiServerBundle\CodeGenerator\Filesystem;

use Override;

use function is_dir;
use function Safe\file_put_contents;
use function Safe\mkdir;
Expand All @@ -21,7 +19,6 @@ 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
7 changes: 0 additions & 7 deletions src/CodeGenerator/Naming/DefaultNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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 @@ -38,13 +37,11 @@ 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 @@ -59,7 +56,6 @@ public function getInterfaceFQCN(string $apiNameSpace, string $operationId): str
return $interfaceNamespace;
}

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

#[Override]
public function stringToMethodName(string $text): string
{
$propertyName = $this->padStringThatIsReservedMethodName(
Expand All @@ -93,13 +88,11 @@ 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
5 changes: 3 additions & 2 deletions src/CodeGenerator/PhpParserGenerators/DtoCodeGenerator.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
8 changes: 3 additions & 5 deletions src/Command/DeleteGeneratedCodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace OnMoon\OpenApiServerBundle\Command;

use Override;
use FilesystemIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;
Expand Down Expand Up @@ -43,7 +43,6 @@ public function __construct(string $rootPath, ?string $name = null)
*/
protected static $defaultName = self::COMMAND;

#[Override]
protected function configure(): void
{
$this
Expand All @@ -55,7 +54,6 @@ protected function configure(): void
);
}

#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
if (! (bool) $input->getOption('yes')) {
Expand Down Expand Up @@ -86,15 +84,15 @@ private function recursiveDelete(string $directoryPath): void
return;
}

/** @var SplFileInfo[] $iterator */
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
$directoryPath,
RecursiveDirectoryIterator::SKIP_DOTS
FilesystemIterator::SKIP_DOTS
),
RecursiveIteratorIterator::CHILD_FIRST
);

/** @var SplFileInfo $directoryOrFile */
foreach ($iterator as $directoryOrFile) {
if ($directoryOrFile->isDir()) {
rmdir($directoryOrFile->getPathname());
Expand Down
5 changes: 1 addition & 4 deletions src/Command/GenerateApiCodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use FilesystemIterator;
use OnMoon\OpenApiServerBundle\CodeGenerator\ApiServerCodeGenerator;
use OnMoon\OpenApiServerBundle\Specification\SpecificationLoader;
use Override;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;
Expand Down Expand Up @@ -47,7 +46,6 @@ public function __construct(
parent::__construct($name);
}

#[Override]
protected function configure(): void
{
$this
Expand All @@ -67,7 +65,6 @@ protected function configure(): void
*/
protected static $defaultName = self::COMMAND;

#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$keep = (bool) $input->getOption('keep');
Expand Down Expand Up @@ -100,7 +97,7 @@ private function removeExtraFiles(string $root, array $generatedFiles): void
RecursiveIteratorIterator::CHILD_FIRST
);

/** @var SplFileInfo[] $iterator */
/** @var SplFileInfo $directoryOrFile */
foreach ($iterator as $directoryOrFile) {
if ($directoryOrFile->isDir() || in_array($directoryOrFile->getPathname(), $generatedFiles, true)) {
continue;
Expand Down
Loading