From 5cf09ce4d48273298c5f9bb720b4b34bba662136 Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Fri, 29 Nov 2024 13:09:09 +1300 Subject: [PATCH] Switch CS to @PSR12 --- .php-cs-fixer.dist.php | 13 ++++++++++--- src/OpenApiException.php | 1 - src/Processors/AugmentTags.php | 1 - tests/Analysers/ReflectionAnalyserTest.php | 2 +- .../AnnotationPropertiesDefinedTest.php | 1 - tests/Fixtures/BadExampleParameter.php | 1 - tests/Fixtures/PHP/AnonymousFunctions.php | 2 +- tests/Fixtures/PHP/php7.php | 16 ++++++++-------- tests/GeneratorTest.php | 2 +- tests/OpenApiTestCase.php | 2 +- tests/PipelineTest.php | 2 +- 11 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 2affc46dd..932913646 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -6,9 +6,15 @@ $finder = PhpCsFixer\Finder::create() ->path('src')->name('*.php') ->path('tests')->name('*.php') - // ContextTest::testFullyQualifiedName relies on the 'use Exception' statement... ->filter(function (\SplFileInfo $file) { - return !strpos($file->getPathname(), 'tests/Fixtures/Customer.php'); + return + // ContextTest::testFullyQualifiedName relies on the 'use Exception' statement... + !strpos($file->getPathname(), 'tests/Fixtures/Customer.php') + // multi arg use; 'use a, b;` + && !strpos($file->getPathname(), 'tests/Fixtures/Parser/HelloTrait.php') + // FQDN in docblock + && !strpos($file->getPathname(), 'tests/Fixtures/TypedProperties.php') + ; }) ->path('Examples')->name('*.php') ->filter(function (\SplFileInfo $file) { @@ -24,10 +30,11 @@ (new ScopedDeclareStrictTypesFixer())->scope(['/src/', '/tests/']), ]) ->setRules([ - '@PSR2' => true, + '@PSR12' => true, '@DoctrineAnnotation' => true, 'OpenApi/license' => true, 'OpenApi/declare_strict_types' => true, + 'blank_line_after_opening_tag' => false, 'array_syntax' => ['syntax' => 'short'], 'no_unused_imports' => true, 'blank_line_before_statement' => ['statements' => ['return']], diff --git a/src/OpenApiException.php b/src/OpenApiException.php index c3320da32..1198d3681 100644 --- a/src/OpenApiException.php +++ b/src/OpenApiException.php @@ -8,5 +8,4 @@ class OpenApiException extends \Exception { - } diff --git a/src/Processors/AugmentTags.php b/src/Processors/AugmentTags.php index 460065999..4a450b9c2 100644 --- a/src/Processors/AugmentTags.php +++ b/src/Processors/AugmentTags.php @@ -15,7 +15,6 @@ */ class AugmentTags implements ProcessorInterface { - /** @var array */ protected array $whitelist = []; diff --git a/tests/Analysers/ReflectionAnalyserTest.php b/tests/Analysers/ReflectionAnalyserTest.php index d4b676c6f..64cb85248 100644 --- a/tests/Analysers/ReflectionAnalyserTest.php +++ b/tests/Analysers/ReflectionAnalyserTest.php @@ -24,7 +24,7 @@ class ReflectionAnalyserTest extends OpenApiTestCase { protected function collectingAnnotationFactory(): AnnotationFactoryInterface { - return new class() implements AnnotationFactoryInterface { + return new class () implements AnnotationFactoryInterface { public $reflectors = []; public function build(\Reflector $reflector, Context $context): array diff --git a/tests/Annotations/AnnotationPropertiesDefinedTest.php b/tests/Annotations/AnnotationPropertiesDefinedTest.php index 38bc7b91e..08e9eca3f 100644 --- a/tests/Annotations/AnnotationPropertiesDefinedTest.php +++ b/tests/Annotations/AnnotationPropertiesDefinedTest.php @@ -6,7 +6,6 @@ namespace OpenApi\Tests\Annotations; -use function \get_class_vars; use OpenApi\Annotations as OA; use OpenApi\Tests\OpenApiTestCase; diff --git a/tests/Fixtures/BadExampleParameter.php b/tests/Fixtures/BadExampleParameter.php index c8a4763b8..a176c9872 100644 --- a/tests/Fixtures/BadExampleParameter.php +++ b/tests/Fixtures/BadExampleParameter.php @@ -15,5 +15,4 @@ )] class BadExampleParameter { - } diff --git a/tests/Fixtures/PHP/AnonymousFunctions.php b/tests/Fixtures/PHP/AnonymousFunctions.php index c5a8ac867..3b5d24311 100644 --- a/tests/Fixtures/PHP/AnonymousFunctions.php +++ b/tests/Fixtures/PHP/AnonymousFunctions.php @@ -22,7 +22,7 @@ public function index($ding) protected function query() { - return new class() { + return new class () { public function leftJoin(string $foo, callable $callback) { return $this; diff --git a/tests/Fixtures/PHP/php7.php b/tests/Fixtures/PHP/php7.php index 074d1172d..8e2eb2d9f 100644 --- a/tests/Fixtures/PHP/php7.php +++ b/tests/Fixtures/PHP/php7.php @@ -8,49 +8,49 @@ use PHPUnit\Framework\TestCase; -$a = new class { +$a = new class () { public function foo() { } }; -$b = new class() { +$b = new class () { public function bar() { } }; -$c = new class extends \stdClass { +$c = new class () extends \stdClass { public function baz() { } }; -$d = new class() extends \stdClass { +$d = new class () extends \stdClass { public function boz() { } }; -new class implements i1 { +new class () implements i1 { public function biz() { } }; -new class() implements i1 { +new class () implements i1 { public function buz() { } }; -$e = new class() extends \stdClass { +$e = new class () extends \stdClass { public function fuz() { } }; -$f = new class() implements i2 { +$f = new class () implements i2 { public function fuu() { } diff --git a/tests/GeneratorTest.php b/tests/GeneratorTest.php index 1f721c1ad..7c4583708 100644 --- a/tests/GeneratorTest.php +++ b/tests/GeneratorTest.php @@ -63,7 +63,7 @@ public static function processorCases(): iterable { return [ [new OperationId(), true], - [new class(false) extends OperationId { + [new class (false) extends OperationId { }, false], ]; } diff --git a/tests/OpenApiTestCase.php b/tests/OpenApiTestCase.php index 9980ba0aa..985f5ad5d 100644 --- a/tests/OpenApiTestCase.php +++ b/tests/OpenApiTestCase.php @@ -55,7 +55,7 @@ protected function tearDown(): void public function getTrackingLogger(bool $debug = false): ?LoggerInterface { - return new class($this, $debug) extends AbstractLogger { + return new class ($this, $debug) extends AbstractLogger { /** @var OpenApiTestCase */ protected $testCase; diff --git a/tests/PipelineTest.php b/tests/PipelineTest.php index 76ca929df..a0f1b9dda 100644 --- a/tests/PipelineTest.php +++ b/tests/PipelineTest.php @@ -17,7 +17,7 @@ public function __invoke($payload) protected function pipe(string $add) { - return new class($add) { + return new class ($add) { protected $add; public function __construct(string $add)