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
16 changes: 14 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,25 @@ jobs:
${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction
run: |
if [ "${{ matrix.php-version }}" = "8.0" ]; then
rm -f composer.lock
composer clear-cache
composer update --no-cache --prefer-dist --no-progress --no-interaction
else
composer install --prefer-dist --no-progress --no-interaction
fi

- name: Run Linter & Static Analysis
run: composer run-script lint

- name: Run Test Suite
run: vendor/bin/phpunit --coverage-clover=coverage.xml
run: |
if [ "${{ matrix.php-version }}" = "8.0" ]; then
vendor/bin/phpunit -c phpunit9.xml --coverage-clover=coverage.xml
else
vendor/bin/phpunit --coverage-clover=coverage.xml
fi

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
Expand Down
24 changes: 12 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
"require": {
"php": ">=8.1",
"nikic/php-parser": "^4.15 || ^5.0",
"phpstan/phpdoc-parser": "^1.24",
"symfony/console": "^6.0",
"symfony/finder": "^6.0",
"symfony/yaml": "^6.0"
"phpstan/phpdoc-parser": "^1.24 || ^2.0",
"symfony/console": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/finder": "^5.4 || ^6.0 || ^7.0 || ^8.0",
"symfony/yaml": "^5.4 || ^6.0 || ^7.0 || ^8.0"
},
"require-dev": {
"illuminate/console": "^10.0",
"illuminate/routing": "^10.0",
"illuminate/support": "^10.0",
"illuminate/console": "^9.0 || ^10.0",
"illuminate/routing": "^9.0 || ^10.0",
"illuminate/support": "^9.0 || ^10.0",
"phpstan/phpstan": "^2.2",
"phpunit/phpunit": "^10.0",
"phpunit/phpunit": "^9.5 || ^10.0",
"squizlabs/php_codesniffer": "^4.0",
"symfony/config": "^6.0",
"symfony/dependency-injection": "^6.0",
"symfony/http-kernel": "^6.0"
"symfony/config": "^5.4 || ^6.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
"symfony/http-kernel": "^5.4 || ^6.0"
},
"config": {
"sort-packages": true
Expand All @@ -42,6 +42,6 @@
"phpstan analyse --memory-limit=512M"
],
"format": "phpcbf",
"test": "phpunit"
"test": "php -r \"require 'vendor/autoload.php'; passthru(str_starts_with(PHPUnit\\Runner\\Version::id(), '9.') ? 'vendor/bin/phpunit -c phpunit9.xml' : 'vendor/bin/phpunit', $err); exit($err);\""
}
}
16 changes: 16 additions & 0 deletions phpunit9.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="Unit">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
3 changes: 2 additions & 1 deletion src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ traits: $traits,
private function analyzeClass(string $fqcn, Class_|Trait_|Enum_|Interface_ $stmt, NameResolver $nameResolver): void
{
$schema = $this->schemaRegistry->get($fqcn);
if (function_exists('enum_exists') && enum_exists($fqcn)) {
// @phpstan-ignore-next-line
if (PHP_VERSION_ID >= 80100 && function_exists('enum_exists') && enum_exists($fqcn)) {
$reflection = new \ReflectionEnum($fqcn);
$isBacked = $reflection->isBacked();
$cases = $reflection->getCases();
Expand Down
32 changes: 28 additions & 4 deletions src/DocBlockParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,34 @@ class DocBlockParser

public function __construct()
{
$this->lexer = new Lexer();
$constExprParser = new ConstExprParser();
$typeParser = new TypeParser($constExprParser);
$this->parser = new PhpDocParser($typeParser, $constExprParser);
if (class_exists('PHPStan\PhpDocParser\ParserConfig')) {
$configRef = new \ReflectionClass('PHPStan\PhpDocParser\ParserConfig');
$config = $configRef->newInstance([]);

$lexerRef = new \ReflectionClass(Lexer::class);
$this->lexer = $lexerRef->newInstance($config);

$constExprRef = new \ReflectionClass(ConstExprParser::class);
$constExprParser = $constExprRef->newInstance($config);

$typeRef = new \ReflectionClass(TypeParser::class);
$typeParser = $typeRef->newInstance($config, $constExprParser);

$phpDocRef = new \ReflectionClass(PhpDocParser::class);
$this->parser = $phpDocRef->newInstance($config, $typeParser, $constExprParser);
} else {
$lexerRef = new \ReflectionClass(Lexer::class);
$this->lexer = $lexerRef->newInstance();

$constExprRef = new \ReflectionClass(ConstExprParser::class);
$constExprParser = $constExprRef->newInstance();

$typeRef = new \ReflectionClass(TypeParser::class);
$typeParser = $typeRef->newInstance($constExprParser);

$phpDocRef = new \ReflectionClass(PhpDocParser::class);
$this->parser = $phpDocRef->newInstance($typeParser, $constExprParser);
}
}

public function parse(string $docBlock): PhpDocNode
Expand Down
5 changes: 4 additions & 1 deletion src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ public function getSpecArray(): array

public function generateYaml(): string
{
$yaml = Yaml::dump($this->generateSpec(), 10, 2, Yaml::DUMP_NUMERIC_KEY_AS_STRING);
$flags = defined('Symfony\Component\Yaml\Yaml::DUMP_NUMERIC_KEY_AS_STRING')
? \Symfony\Component\Yaml\Yaml::DUMP_NUMERIC_KEY_AS_STRING
: 0;
$yaml = Yaml::dump($this->generateSpec(), 10, 2, $flags);
return preg_replace(
'/(?<=\n)(\s+)(?!(?:schema|properties|paths|schemas|responses|headers|examples|' .
'requestBodies|securitySchemes|additionalProperties|items|components|info|contact|' .
Expand Down
3 changes: 3 additions & 0 deletions tests/NativeEnumSupportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use PhpSwag\Core;
use Symfony\Component\Yaml\Yaml;

/**
* @requires PHP 8.1
*/
class NativeEnumSupportTest extends TestCase
{
public function testBackedStringEnumSupport()
Expand Down
Loading