From 1295ac87264415a6afe3f376dc1222bd162ae73c Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Tue, 8 Aug 2023 20:05:51 +0200 Subject: [PATCH] Apply fixer --- src/Cache/CacheKeyAndTags.php | 4 +- src/Cache/CacheKeyAndTagsGenerator.php | 2 +- src/Console/FieldGeneratorCommand.php | 2 +- src/Execution/TransactionalMutations.php | 2 +- src/Schema/AST/ASTHelper.php | 2 +- src/Schema/Directives/BaseDirective.php | 2 +- src/Scout/ScoutEnhancer.php | 2 +- src/Validation/Validator.php | 2 +- tests/LaravelPhpdocAlignmentFixer.php | 72 +++++++++++++++++++ .../Unit/Pagination/PaginateDirectiveTest.php | 2 +- tests/Utils/Models/Task.php | 4 +- tests/Utils/Models/User/UserBuilder.php | 2 +- tests/Utils/Mutations/Upload.php | 2 +- 13 files changed, 86 insertions(+), 14 deletions(-) create mode 100644 tests/LaravelPhpdocAlignmentFixer.php diff --git a/src/Cache/CacheKeyAndTags.php b/src/Cache/CacheKeyAndTags.php index 322dcb7e46..f05db0fae6 100644 --- a/src/Cache/CacheKeyAndTags.php +++ b/src/Cache/CacheKeyAndTags.php @@ -9,8 +9,8 @@ interface CacheKeyAndTags /** * Generate the cache key. * - * @param array $args - * @param array $path + * @param array $args + * @param array $path */ public function key(?Authenticatable $user, bool $isPrivate, string $parentName, int|string|null $id, string $fieldName, array $args, array $path): string; diff --git a/src/Cache/CacheKeyAndTagsGenerator.php b/src/Cache/CacheKeyAndTagsGenerator.php index 62a09d242a..f415bf0c22 100644 --- a/src/Cache/CacheKeyAndTagsGenerator.php +++ b/src/Cache/CacheKeyAndTagsGenerator.php @@ -12,7 +12,7 @@ class CacheKeyAndTagsGenerator implements CacheKeyAndTags /** * @param array $args - * @param array $path + * @param array $path */ public function key( ?Authenticatable $user, diff --git a/src/Console/FieldGeneratorCommand.php b/src/Console/FieldGeneratorCommand.php index a283f50941..b1c1b76ba7 100644 --- a/src/Console/FieldGeneratorCommand.php +++ b/src/Console/FieldGeneratorCommand.php @@ -28,7 +28,7 @@ protected function getOptions(): array ]; } - /** @param string $path */ + /** @param string $path */ protected function handleTestCreation($path): bool { if (! $testFramework = $this->testFramework()) { diff --git a/src/Execution/TransactionalMutations.php b/src/Execution/TransactionalMutations.php index 5bf48e0f5f..032f5e8e82 100644 --- a/src/Execution/TransactionalMutations.php +++ b/src/Execution/TransactionalMutations.php @@ -19,7 +19,7 @@ public function __construct( /** * @template TResult * - * @param \Closure(): TResult $mutation + * @param \Closure(): TResult $mutation * * @return TResult */ diff --git a/src/Schema/AST/ASTHelper.php b/src/Schema/AST/ASTHelper.php index 3d4f74d6f9..0a2c5b00ac 100644 --- a/src/Schema/AST/ASTHelper.php +++ b/src/Schema/AST/ASTHelper.php @@ -139,7 +139,7 @@ public static function getUnderlyingNamedTypeNode(Node $node): NamedTypeNode /** * Extract a named argument from a given directive node. * - * @param mixed $default is returned if the directive does not have the argument + * @param mixed $default is returned if the directive does not have the argument */ public static function directiveArgValue(DirectiveNode $directive, string $name, mixed $default = null): mixed { diff --git a/src/Schema/Directives/BaseDirective.php b/src/Schema/Directives/BaseDirective.php index bff9c02707..0e6a146a21 100644 --- a/src/Schema/Directives/BaseDirective.php +++ b/src/Schema/Directives/BaseDirective.php @@ -122,7 +122,7 @@ protected function directiveHasArgument(string $name): bool * * @api * - * @param mixed $default Use this over `??` to preserve explicit `null` + * @param mixed $default Use this over `??` to preserve explicit `null` * * @return mixed The argument value or the default */ diff --git a/src/Scout/ScoutEnhancer.php b/src/Scout/ScoutEnhancer.php index 7c85688c3a..14a3da0a40 100644 --- a/src/Scout/ScoutEnhancer.php +++ b/src/Scout/ScoutEnhancer.php @@ -64,7 +64,7 @@ public function wouldEnhanceBuilder(): bool return $this->hasSearchArguments(); } - /** @param (callable(\Nuwave\Lighthouse\Scout\ScoutBuilderDirective): bool)|null $directiveFilter */ + /** @param (callable(\Nuwave\Lighthouse\Scout\ScoutBuilderDirective): bool)|null $directiveFilter */ public function enhanceBuilder(callable $directiveFilter = null): ScoutBuilder { $scoutBuilder = $this->builder instanceof ScoutBuilder diff --git a/src/Validation/Validator.php b/src/Validation/Validator.php index cc13605e5d..efa239bd86 100644 --- a/src/Validation/Validator.php +++ b/src/Validation/Validator.php @@ -31,7 +31,7 @@ public function setArgs(ArgumentSet $args): void * Retrieve the value of an argument or the default. * * @param string $key the key of the argument, may use dot notation to get nested values - * @param mixed $default returned in case the argument is not present + * @param mixed $default returned in case the argument is not present */ protected function arg(string $key, mixed $default = null): mixed { diff --git a/tests/LaravelPhpdocAlignmentFixer.php b/tests/LaravelPhpdocAlignmentFixer.php new file mode 100644 index 0000000000..58b94491fc --- /dev/null +++ b/tests/LaravelPhpdocAlignmentFixer.php @@ -0,0 +1,72 @@ +isAnyTokenKindsFound([T_DOC_COMMENT]); + } + + /** {@inheritdoc} */ + public function isRisky(): bool + { + return false; + } + + /** {@inheritdoc} */ + public function fix(\SplFileInfo $file, Tokens $tokens): void + { + for ($index = $tokens->count() - 1; $index > 0; --$index) { + if (! $tokens[$index]->isGivenKind([\T_DOC_COMMENT])) { + continue; + } + + $newContent = preg_replace_callback( + '/(?P@param)\s+(?P(?:' . TypeExpression::REGEX_TYPES . ')?)\s+(?P(?:&|\.{3})?\$\S+)/ux', + fn ($matches) => $matches['tag'] . ' ' . $matches['hint'] . ' ' . $matches['var'], + $tokens[$index]->getContent(), + ); + + if ($newContent == $tokens[$index]->getContent()) { + continue; + } + + $tokens[$index] = new Token([T_DOC_COMMENT, $newContent]); + } + } + + /** {@inheritdoc} */ + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition('@param and type definition must be followed by two spaces.', []); + } + + /** {@inheritdoc} */ + public function getPriority(): int + { + return -42; + } + + /** {@inheritdoc} */ + public function supports(\SplFileInfo $file): bool + { + return true; + } +} diff --git a/tests/Unit/Pagination/PaginateDirectiveTest.php b/tests/Unit/Pagination/PaginateDirectiveTest.php index b27006daef..12356f2147 100644 --- a/tests/Unit/Pagination/PaginateDirectiveTest.php +++ b/tests/Unit/Pagination/PaginateDirectiveTest.php @@ -777,7 +777,7 @@ public function testCustomizeQueryComplexityResolver(): void ])->assertGraphQLErrorMessage(QueryComplexity::maxQueryComplexityErrorMessage($max, $complexity)); } - /** @param array{complexity: int} $args */ + /** @param array{complexity: int} $args */ public static function complexityResolver(int $childrenComplexity, array $args): int { return $args['complexity']; diff --git a/tests/Utils/Models/Task.php b/tests/Utils/Models/Task.php index 2bab3da234..ed0fd7dbca 100644 --- a/tests/Utils/Models/Task.php +++ b/tests/Utils/Models/Task.php @@ -108,7 +108,7 @@ public function scopeCompleted(EloquentBuilder $query): EloquentBuilder /** * @param \Illuminate\Database\Eloquent\Builder $query - * @param array $args + * @param array $args * * @return \Illuminate\Database\Eloquent\Builder */ @@ -119,7 +119,7 @@ public function scopeFoo(EloquentBuilder $query, array $args): EloquentBuilder /** * @param \Illuminate\Database\Eloquent\Builder $query - * @param iterable $tags + * @param iterable $tags * * @return \Illuminate\Database\Eloquent\Builder */ diff --git a/tests/Utils/Models/User/UserBuilder.php b/tests/Utils/Models/User/UserBuilder.php index 0d80dd8c39..852845c5b0 100644 --- a/tests/Utils/Models/User/UserBuilder.php +++ b/tests/Utils/Models/User/UserBuilder.php @@ -8,7 +8,7 @@ /** @extends \Illuminate\Database\Eloquent\Builder<\Tests\Utils\Models\User> */ final class UserBuilder extends Builder { - /** @param array{company: string} $args */ + /** @param array{company: string} $args */ public function companyName(array $args): self { return $this->where(fn (self $builder) => $builder diff --git a/tests/Utils/Mutations/Upload.php b/tests/Utils/Mutations/Upload.php index 4cd0a9c79d..d9b45c6c1b 100644 --- a/tests/Utils/Mutations/Upload.php +++ b/tests/Utils/Mutations/Upload.php @@ -6,7 +6,7 @@ final class Upload { - /** @param array $args */ + /** @param array $args */ public function __invoke(mixed $root, array $args): bool { return isset($args['file'])