Skip to content

Commit

Permalink
Apply fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Aug 8, 2023
1 parent f265e12 commit 1295ac8
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Cache/CacheKeyAndTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ interface CacheKeyAndTags
/**
* Generate the cache key.
*
* @param array<string, mixed> $args
* @param array<int, string|int> $path
* @param array<string, mixed> $args
* @param array<int, string|int> $path
*/
public function key(?Authenticatable $user, bool $isPrivate, string $parentName, int|string|null $id, string $fieldName, array $args, array $path): string;

Expand Down
2 changes: 1 addition & 1 deletion src/Cache/CacheKeyAndTagsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CacheKeyAndTagsGenerator implements CacheKeyAndTags

/**
* @param array<string, mixed> $args
* @param array<int, string|int> $path
* @param array<int, string|int> $path
*/
public function key(
?Authenticatable $user,
Expand Down
2 changes: 1 addition & 1 deletion src/Console/FieldGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function getOptions(): array
];
}

/** @param string $path */
/** @param string $path */
protected function handleTestCreation($path): bool
{
if (! $testFramework = $this->testFramework()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Execution/TransactionalMutations.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(
/**
* @template TResult
*
* @param \Closure(): TResult $mutation
* @param \Closure(): TResult $mutation
*
* @return TResult
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/AST/ASTHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/Directives/BaseDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Scout/ScoutEnhancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
72 changes: 72 additions & 0 deletions tests/LaravelPhpdocAlignmentFixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php declare(strict_types=1);
/* @see https://github.com/laravel/pint/blob/main/app/Fixers/LaravelPhpdocAlignmentFixer.php */

namespace Tests;

use PhpCsFixer\DocBlock\TypeExpression;
use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;

class LaravelPhpdocAlignmentFixer implements FixerInterface
{
/** {@inheritdoc} */
public function getName(): string
{
return 'Laravel/laravel_phpdoc_alignment';
}

/** {@inheritdoc} */
public function isCandidate(Tokens $tokens): bool
{
return $tokens->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])) {

Check failure on line 37 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.0 with Laravel ^9 and lowest dependencies

Cannot call method isGivenKind() on PhpCsFixer\Tokenizer\Token|null.

Check failure on line 37 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^9 and lowest dependencies

Cannot call method isGivenKind() on PhpCsFixer\Tokenizer\Token|null.

Check failure on line 37 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^10 and lowest dependencies

Cannot call method isGivenKind() on PhpCsFixer\Tokenizer\Token|null.

Check failure on line 37 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^9 and lowest dependencies

Cannot call method isGivenKind() on PhpCsFixer\Tokenizer\Token|null.

Check failure on line 37 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^10 and lowest dependencies

Cannot call method isGivenKind() on PhpCsFixer\Tokenizer\Token|null.
continue;
}

$newContent = preg_replace_callback(
'/(?P<tag>@param)\s+(?P<hint>(?:' . TypeExpression::REGEX_TYPES . ')?)\s+(?P<var>(?:&|\.{3})?\$\S+)/ux',
fn ($matches) => $matches['tag'] . ' ' . $matches['hint'] . ' ' . $matches['var'],
$tokens[$index]->getContent(),

Check failure on line 44 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.0 with Laravel ^9 and lowest dependencies

Cannot call method getContent() on PhpCsFixer\Tokenizer\Token|null.

Check failure on line 44 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^9 and lowest dependencies

Cannot call method getContent() on PhpCsFixer\Tokenizer\Token|null.

Check failure on line 44 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^10 and lowest dependencies

Cannot call method getContent() on PhpCsFixer\Tokenizer\Token|null.

Check failure on line 44 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^9 and lowest dependencies

Cannot call method getContent() on PhpCsFixer\Tokenizer\Token|null.

Check failure on line 44 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^10 and lowest dependencies

Cannot call method getContent() on PhpCsFixer\Tokenizer\Token|null.
);

if ($newContent == $tokens[$index]->getContent()) {

Check failure on line 47 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.0 with Laravel ^9 and lowest dependencies

Cannot call method getContent() on PhpCsFixer\Tokenizer\Token|null.

Check failure on line 47 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^9 and lowest dependencies

Cannot call method getContent() on PhpCsFixer\Tokenizer\Token|null.

Check failure on line 47 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^10 and lowest dependencies

Cannot call method getContent() on PhpCsFixer\Tokenizer\Token|null.

Check failure on line 47 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^9 and lowest dependencies

Cannot call method getContent() on PhpCsFixer\Tokenizer\Token|null.

Check failure on line 47 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^10 and lowest dependencies

Cannot call method getContent() on PhpCsFixer\Tokenizer\Token|null.
continue;
}

$tokens[$index] = new Token([T_DOC_COMMENT, $newContent]);

Check failure on line 51 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.0 with Laravel ^9 and highest dependencies

Parameter #1 $token of class PhpCsFixer\Tokenizer\Token constructor expects array{int, string}|string, array{389, string|null} given.

Check failure on line 51 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^9 and highest dependencies

Parameter #1 $token of class PhpCsFixer\Tokenizer\Token constructor expects array{int, string}|string, array{388, string|null} given.

Check failure on line 51 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^10 and highest dependencies

Parameter #1 $token of class PhpCsFixer\Tokenizer\Token constructor expects array{int, string}|string, array{388, string|null} given.

Check failure on line 51 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^9 and highest dependencies

Parameter #1 $token of class PhpCsFixer\Tokenizer\Token constructor expects array{int, string}|string, array{388, string|null} given.

Check failure on line 51 in tests/LaravelPhpdocAlignmentFixer.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^10 and highest dependencies

Parameter #1 $token of class PhpCsFixer\Tokenizer\Token constructor expects array{int, string}|string, array{388, string|null} given.
}
}

/** {@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;
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Pagination/PaginateDirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
4 changes: 2 additions & 2 deletions tests/Utils/Models/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function scopeCompleted(EloquentBuilder $query): EloquentBuilder

/**
* @param \Illuminate\Database\Eloquent\Builder<self> $query
* @param array<string, int> $args
* @param array<string, int> $args
*
* @return \Illuminate\Database\Eloquent\Builder<self>
*/
Expand All @@ -119,7 +119,7 @@ public function scopeFoo(EloquentBuilder $query, array $args): EloquentBuilder

/**
* @param \Illuminate\Database\Eloquent\Builder<self> $query
* @param iterable<string> $tags
* @param iterable<string> $tags
*
* @return \Illuminate\Database\Eloquent\Builder<self>
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/Models/User/UserBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/Mutations/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

final class Upload
{
/** @param array<string, mixed> $args */
/** @param array<string, mixed> $args */
public function __invoke(mixed $root, array $args): bool
{
return isset($args['file'])
Expand Down

0 comments on commit 1295ac8

Please sign in to comment.