From 9ac69a3b8789d23c0e406c0bc0ef99be5e707afa Mon Sep 17 00:00:00 2001 From: spawnia Date: Wed, 6 Sep 2023 13:11:18 +0200 Subject: [PATCH] Apply rector and php-cs-fixer --- rector.php | 5 +++++ src/Console/FieldGeneratorCommand.php | 2 +- src/Http/Responses/ResponseStream.php | 2 ++ tests/Integration/Pennant/FeatureDirectiveTest.php | 12 ++++++------ tests/TestCase.php | 1 - tests/Utils/Models/User/UserBuilder.php | 2 +- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/rector.php b/rector.php index 2221e92c9b..9d7eedacf8 100644 --- a/rector.php +++ b/rector.php @@ -9,6 +9,7 @@ use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector; use Rector\CodingStyle\Rector\Class_\AddArrayDefaultToArrayPropertyRector; use Rector\CodingStyle\Rector\ClassConst\VarConstantCommentRector; +use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; use Rector\CodingStyle\Rector\ClassMethod\UnSpreadOperatorRector; use Rector\CodingStyle\Rector\Closure\StaticClosureRector; use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector; @@ -39,6 +40,7 @@ ]); $rectorConfig->skip([ __DIR__ . '/tests/database/migrations', // Does not fit autoloading standards + __DIR__ . '/tests/LaravelPhpdocAlignmentFixer.php', // Copied from Laravel CallableThisArrayToAnonymousFunctionRector::class, // Callable in array form is shorter and more efficient IssetOnPropertyObjectToPropertyExistsRector::class, // isset() is nice when moving towards typed properties FlipTypeControlToUseExclusiveTypeRector::class, // Unnecessarily complex with PHPStan @@ -54,6 +56,9 @@ GetClassToInstanceOfRector::class => [ __DIR__ . '/src/Schema/Types/Scalars/DateScalar.php', // We need to compare exact classes, not subclasses ], + MakeInheritedMethodVisibilitySameAsParentRector::class => [ + __DIR__ . '/tests/Unit/Execution/ResolveInfoTest.php', // Makes method public on purpose + ], ExplicitBoolCompareRector::class, // if($truthy) is fine and very readable EncapsedStringsToSprintfRector::class, // unreadable, slow, error prone VarConstantCommentRector::class, // Noisy diff --git a/src/Console/FieldGeneratorCommand.php b/src/Console/FieldGeneratorCommand.php index 99823c6e17..1b474aed8d 100644 --- a/src/Console/FieldGeneratorCommand.php +++ b/src/Console/FieldGeneratorCommand.php @@ -13,7 +13,7 @@ abstract class FieldGeneratorCommand extends LighthouseGeneratorCommand protected function getStub(): string { - if (version_compare(PHP_VERSION, '8.2.0', '>=')) { + if (PHP_VERSION_ID >= 80200) { return $this->option('full') ? __DIR__ . '/stubs/field_full.php82.stub' : __DIR__ . '/stubs/field_simple.php82.stub'; diff --git a/src/Http/Responses/ResponseStream.php b/src/Http/Responses/ResponseStream.php index 85939dee9a..5582f00e81 100644 --- a/src/Http/Responses/ResponseStream.php +++ b/src/Http/Responses/ResponseStream.php @@ -9,7 +9,9 @@ class ResponseStream extends Stream implements CanStreamResponse { protected const EOL = "\r\n"; + protected const BOUNDARY = self::EOL . '---' . self::EOL; + protected const TERMINATING_BOUNDARY = self::EOL . '-----' . self::EOL; public function stream(array $data, array $paths, bool $isFinalChunk): void diff --git a/tests/Integration/Pennant/FeatureDirectiveTest.php b/tests/Integration/Pennant/FeatureDirectiveTest.php index 05f767c610..1b862d6de1 100644 --- a/tests/Integration/Pennant/FeatureDirectiveTest.php +++ b/tests/Integration/Pennant/FeatureDirectiveTest.php @@ -82,7 +82,7 @@ public function testUnavailableWhenFeatureIsInactiveWithDefaultFeatureState(): v public function testUnavailableWhenFeatureIsActive(): void { - Feature::define('new-api', fn (): bool => true); + Feature::define('new-api', static fn (): bool => true); $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' type Query { fieldWhenInactive: String! @@ -103,9 +103,9 @@ public function testUnavailableWhenFeatureIsActive(): void public function testAvailableWhenFeatureIsActive(): void { - Feature::define('new-api', fn (): bool => true); + Feature::define('new-api', static fn (): bool => true); $fieldValue = 'active'; - $this->mockResolver(fn (): string => $fieldValue); + $this->mockResolver(static fn (): string => $fieldValue); $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' type Query { fieldWhenActive: String! @@ -131,9 +131,9 @@ public function testAvailableWhenFeatureIsActive(): void public function testAvailableWhenFeatureIsActiveWithDefaultFeatureState(): void { - Feature::define('new-api', fn (): bool => true); + Feature::define('new-api', static fn (): bool => true); $fieldValue = 'active'; - $this->mockResolver(fn (): string => $fieldValue); + $this->mockResolver(static fn (): string => $fieldValue); $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' type Query { fieldWhenActive: String! @@ -160,7 +160,7 @@ public function testAvailableWhenFeatureIsActiveWithDefaultFeatureState(): void public function testAvailableWhenFeatureIsInactive(): void { $fieldValue = 'inactive'; - $this->mockResolver(fn (): string => $fieldValue); + $this->mockResolver(static fn (): string => $fieldValue); $this->schema = /* @lang GraphQL */ <<<'GRAPHQL' type Query { fieldWhenInactive: String! diff --git a/tests/TestCase.php b/tests/TestCase.php index a643483a2c..cf19f49fd5 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -18,7 +18,6 @@ use Nuwave\Lighthouse\LighthouseServiceProvider; use Nuwave\Lighthouse\OrderBy\OrderByServiceProvider; use Nuwave\Lighthouse\Pagination\PaginationServiceProvider; -use Nuwave\Lighthouse\Pennant\PennantServiceProvider as LighthousePennantServiceProvider; use Nuwave\Lighthouse\Schema\SchemaBuilder; use Nuwave\Lighthouse\Scout\ScoutServiceProvider as LighthouseScoutServiceProvider; use Nuwave\Lighthouse\SoftDeletes\SoftDeletesServiceProvider; diff --git a/tests/Utils/Models/User/UserBuilder.php b/tests/Utils/Models/User/UserBuilder.php index 852845c5b0..b4a06e6501 100644 --- a/tests/Utils/Models/User/UserBuilder.php +++ b/tests/Utils/Models/User/UserBuilder.php @@ -11,7 +11,7 @@ final class UserBuilder extends Builder /** @param array{company: string} $args */ public function companyName(array $args): self { - return $this->where(fn (self $builder) => $builder + return $this->where(static fn (self $builder): \Tests\Utils\Models\User\UserBuilder => $builder ->whereHas('company', static fn (EloquentBuilder $q): EloquentBuilder => $q ->where('name', $args['company']))); }