Skip to content

Commit 6c2522b

Browse files
feature(php-cop#82|php-cop#83|#64): Ready Fusonic PHP extensions for Symfony 7.1
1 parent 176d836 commit 6c2522b

13 files changed

+166
-51
lines changed

.gitignore

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
/var
44
composer.lock
55
/coverage
6-
.php-cs-fixer.cache
6+
7+
###> friendsofphp/php-cs-fixer ###
8+
/.php-cs-fixer.cache
9+
###< friendsofphp/php-cs-fixer ###
710

811
###> phpunit/phpunit ###
912
/phpunit.xml
10-
.phpunit.result.cache
13+
/.phpunit.cache
1114
###< phpunit/phpunit ###

.php-cs-fixer.dist.php renamed to .php-cs-fixer.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
<?php
22

3+
/*
4+
* Copyright (c) Fusonic GmbH. All rights reserved.
5+
* Licensed under the MIT License. See LICENSE file in the project root for license information.
6+
*/
7+
38
declare(strict_types=1);
49

5-
$finder = PhpCsFixer\Finder::create()
10+
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
11+
12+
$finder = (new PhpCsFixer\Finder())
613
->in(__DIR__)
714
->exclude('var');
815

916
return (new PhpCsFixer\Config())
17+
->setParallelConfig(ParallelConfigFactory::detect())
1018
->setRules([
1119
'@PHP82Migration' => true,
1220
'@Symfony' => true,
@@ -19,7 +27,6 @@
1927
],
2028
'no_useless_else' => true,
2129
'no_useless_return' => true,
22-
'nullable_type_declaration_for_default_null_value' => true,
2330
'php_unit_strict' => true,
2431
'single_line_throw' => false,
2532
'strict_comparison' => true,

.phpunit.cache/test-results

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":1,"defects":[],"times":{"Fusonic\\ApiDocumentationBundle\\Tests\\FunctionalTest::testBootKernel":0.109,"Fusonic\\ApiDocumentationBundle\\Tests\\FunctionalTest::testService":0.002,"Fusonic\\ApiDocumentationBundle\\Tests\\NelmioApiDocsTest::testGetJsonDocs":0.025}}

composer.json

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "fusonic/api-documentation-bundle",
33
"license": "MIT",
4-
"version": "0.0.15",
4+
"version": "0.0.16",
55
"description": "Symfony bundle for automated documentation with NelmioApiDocBundle.",
66
"type": "symfony-bundle",
77
"authors": [
@@ -24,17 +24,18 @@
2424
]
2525
},
2626
"require-dev": {
27-
"friendsofphp/php-cs-fixer": "^3.40",
28-
"infection/infection": "^0.27.10",
29-
"phpstan/phpstan": "^1.10.47",
30-
"phpstan/phpstan-phpunit": "^1.3",
31-
"phpstan/phpstan-strict-rules": "^1.5",
32-
"phpstan/phpstan-symfony": "^1.3",
33-
"phpunit/phpunit": "^10.5",
27+
"friendsofphp/php-cs-fixer": "^3.58",
28+
"infection/infection": "^0.29",
29+
"phpstan/phpstan": "^1.11",
30+
"phpstan/phpstan-deprecation-rules": "^1.2",
31+
"phpstan/phpstan-phpunit": "^1.4",
32+
"phpstan/phpstan-strict-rules": "^1.6",
33+
"phpstan/phpstan-symfony": "^1.4",
34+
"phpunit/phpunit": "^11.2",
3435
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
3536
"symfony/test-pack": "^1.0",
3637
"symfony/yaml": "^5.4 || ^6.0 || ^7.0",
37-
"tomasvotruba/type-coverage": "^0.2"
38+
"tomasvotruba/type-coverage": "^0.3"
3839
},
3940
"require": {
4041
"php": ">=8.1",
@@ -48,8 +49,8 @@
4849
},
4950
"scripts": {
5051
"phpstan": "XDEBUG_MODE=off php -d memory_limit=2048M vendor/bin/phpstan analyse",
51-
"phpcs-check": "XDEBUG_MODE=off vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --dry-run --diff --using-cache=yes",
52-
"phpcs-fix": "XDEBUG_MODE=off vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --using-cache=yes",
52+
"phpcs-check": "XDEBUG_MODE=off vendor/bin/php-cs-fixer check -v --diff",
53+
"phpcs-fix": "XDEBUG_MODE=off vendor/bin/php-cs-fixer fix -v",
5354
"infection": "XDEBUG_MODE=coverage vendor/bin/infection",
5455
"test": "XDEBUG_MODE=off vendor/bin/phpunit --testdox",
5556
"test-coverage" : "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text --coverage-cobertura=coverage/phpunit/cobertura.xml --coverage-html=coverage/phpunit/html"

phpstan.neon

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
parameters:
22
level: 8
33
paths:
4-
- src
5-
- tests
6-
checkMissingIterableValueType: false
7-
4+
- src/
5+
- tests/
6+
scanFiles:
7+
- vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php
88
type_coverage:
9-
return_type: 100
10-
param_type: 100
11-
property_type: 100
12-
print_suggestions: false
9+
return: 100
10+
param: 100
11+
property: 100
1312

1413
includes:
14+
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
1515
- vendor/phpstan/phpstan-phpunit/extension.neon
16+
- vendor/phpstan/phpstan-phpunit/rules.neon
1617
- vendor/phpstan/phpstan-strict-rules/rules.neon
1718
- vendor/phpstan/phpstan-symfony/extension.neon
19+
- vendor/phpstan/phpstan-symfony/rules.neon
1820
- vendor/tomasvotruba/type-coverage/config/extension.neon

phpunit.xml.dist

+34-20
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd"
4+
bootstrap="tests/bootstrap.php"
5+
cacheDirectory=".phpunit.cache"
6+
executionOrder="depends,defects"
47
colors="true"
5-
bootstrap="vendor/autoload.php"
8+
beStrictAboutCoverageMetadata="true"
9+
beStrictAboutOutputDuringTests="true"
610
displayDetailsOnTestsThatTriggerDeprecations="true"
11+
displayDetailsOnTestsThatTriggerNotices="true"
712
displayDetailsOnTestsThatTriggerWarnings="true"
813
displayDetailsOnTestsThatTriggerErrors="true"
9-
failOnWarning="true"
10-
failOnRisky="true">
11-
12-
<source ignoreSuppressionOfDeprecations="true"
13-
ignoreSuppressionOfPhpDeprecations="true"
14-
ignoreSuppressionOfErrors="true"
15-
ignoreSuppressionOfNotices="true"
16-
ignoreSuppressionOfPhpNotices="true"
17-
ignoreSuppressionOfWarnings="true"
18-
ignoreSuppressionOfPhpWarnings="true">
19-
<include>
20-
<directory>./src/</directory>
21-
</include>
22-
</source>
23-
14+
failOnRisky="true"
15+
failOnNotice="true"
16+
failOnWarning="true">
2417
<php>
25-
<ini name="error_reporting" value="-1"/>
2618
<ini name="display_errors" value="1"/>
19+
<ini name="error_reporting" value="-1"/>
20+
<ini name="memory_limit" value="512M"/>
2721
<server name="KERNEL_CLASS" value="Fusonic\ApiDocumentationBundle\Tests\App\TestKernel"/>
28-
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
29-
<env name="APP_DEBUG" value="false" />
22+
<server name="APP_ENV" value="test" force="true"/>
23+
<server name="APP_DEBUG" value="0" force="true"/>
24+
<server name="SHELL_VERBOSITY" value="-1"/>
3025
</php>
3126

3227
<testsuites>
3328
<testsuite name="Fusonic ApiDocumentationBundle Test Suite">
3429
<directory>./tests/</directory>
3530
</testsuite>
3631
</testsuites>
32+
33+
<source ignoreIndirectDeprecations="true"
34+
ignoreSuppressionOfDeprecations="true"
35+
ignoreSuppressionOfPhpDeprecations="true"
36+
restrictNotices="true"
37+
ignoreSuppressionOfNotices="true"
38+
ignoreSuppressionOfPhpNotices="true"
39+
restrictWarnings="true"
40+
ignoreSuppressionOfWarnings="true"
41+
ignoreSuppressionOfPhpWarnings="true"
42+
ignoreSuppressionOfErrors="true">
43+
<include>
44+
<directory>src</directory>
45+
</include>
46+
47+
<deprecationTrigger>
48+
<function>trigger_deprecation</function>
49+
</deprecationTrigger>
50+
</source>
3751
</phpunit>

src/AnnotationBuilder/PropertyExtractor.php

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public function __construct()
2828
);
2929
}
3030

31+
/**
32+
* @return string[]|null
33+
*/
3134
public function extractClassProperties(string $className): ?array
3235
{
3336
return $this->propertyInfoExtractor->getProperties($className);

src/Describer/DocumentedRouteDescriber.php

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ private function getMethodsToParse(): \Generator
111111
}
112112
}
113113

114+
/**
115+
* @return string[]
116+
*/
114117
private function getSupportedHttpMethods(Route $route): array
115118
{
116119
$allMethods = Util::OPERATIONS;

src/Extractor/MethodReturnTypePhpDocExtractor.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use phpDocumentor\Reflection\DocBlock;
1313
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
1414
use phpDocumentor\Reflection\DocBlockFactory;
15+
use phpDocumentor\Reflection\DocBlockFactoryInterface;
1516
use phpDocumentor\Reflection\Types\Context;
1617
use phpDocumentor\Reflection\Types\ContextFactory;
1718
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
@@ -37,7 +38,7 @@ final class MethodReturnTypePhpDocExtractor implements PropertyTypeExtractorInte
3738
private array $docBlocks = [];
3839

3940
private ContextFactory $contextFactory;
40-
private DocBlockFactory $docBlockFactory;
41+
private DocBlockFactoryInterface $docBlockFactory;
4142

4243
public function __construct()
4344
{
@@ -46,6 +47,17 @@ public function __construct()
4647
$this->contextFactory = new ContextFactory();
4748
}
4849

50+
/**
51+
* @param array<mixed> $context
52+
*/
53+
public function getType(string $class, string $property, array $context = []): ?Type
54+
{
55+
return $this->getTypes($class, $property, $context)[0] ?? null;
56+
}
57+
58+
/**
59+
* @param array<mixed> $context
60+
*/
4961
public function getTypes(string $class, string $property, array $context = []): ?array
5062
{
5163
$docBlock = $this->getDocBlock($class, $property);

src/Extractor/MethodReturnTypeReflectionExtractor.php

+14
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,25 @@
1818
*/
1919
final class MethodReturnTypeReflectionExtractor implements PropertyTypeExtractorInterface
2020
{
21+
/**
22+
* @param array<mixed> $context
23+
*/
24+
public function getType(string $class, string $property, array $context = []): ?Type
25+
{
26+
return $this->getTypes($class, $property, $context)[0] ?? null;
27+
}
28+
29+
/**
30+
* @param array<mixed> $context
31+
*/
2132
public function getTypes(string $class, string $property, array $context = []): ?array
2233
{
2334
return $this->extractFromAccessor($class, $property);
2435
}
2536

37+
/**
38+
* @return Type[]|null
39+
*/
2640
private function extractFromAccessor(string $class, string $property): ?array
2741
{
2842
$reflectionMethod = new \ReflectionMethod($class, $property);

tests/App/Controller/TestController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ public function testIgnoredReturnType(): Response
5353
return new Response();
5454
}
5555

56-
#[DocumentedRoute(path: '/annotation-builtin-type-array/{id}', methods: ['GET'])]
5756
/**
5857
* @return string[]
5958
*/
59+
#[DocumentedRoute(path: '/annotation-builtin-type-array/{id}', methods: ['GET'])]
6060
public function testAnnotationBuiltinTypeArray(#[FromRequest] TestRequest $query): array
6161
{
6262
return [(string) $query->id];
6363
}
6464

65-
#[DocumentedRoute(path: '/test-annotation-custom-return-type/{id}', methods: ['GET'])]
6665
/**
6766
* @return TestResponse[]
6867
*/
68+
#[DocumentedRoute(path: '/test-annotation-custom-return-type/{id}', methods: ['GET'])]
6969
public function testAnnotationCustomReturnTypeArray(#[FromRequest] TestRequest $query): array
7070
{
7171
return [new TestResponse($query->id)];

0 commit comments

Comments
 (0)