Skip to content

Commit

Permalink
PHP-CS-Fixer#7968 fix phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-ciszewski committed May 9, 2024
1 parent ae5c56f commit e9c4087
Showing 1 changed file with 147 additions and 6 deletions.
153 changes: 147 additions & 6 deletions src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,79 @@
final class PhpUnitDedicateAssertFixer extends AbstractPhpUnitFixer implements ConfigurableFixerInterface
{
/**
* @var array|array<string, array{positive: string, negative: false|string, argument_count?: int, swap_arguments?: true}|true>
* @var array{
* array_key_exists: array{
* positive: string,
* negative: string,
* argument_count: int
* },
* empty: array{
* positive: string,
* negative: string
* },
* file_exists: array{
* positive: string,
* negative: string
* },
* is_array: bool,
* is_bool: bool,
* is_callable: bool,
* is_dir: array{
* positive: string,
* negative: string
* },
* is_double: bool,
* is_float: bool,
* is_infinite: array{
* positive: string,
* negative: string
* },
* is_int: bool,
* is_integer: bool,
* is_long: bool,
* is_nan: array{
* positive: string,
* negative: bool
* },
* is_null: array{
* positive: string,
* negative: string
* },
* is_numeric: bool,
* is_object: bool,
* is_readable: array{
* positive: string,
* negative: string
* },
* is_real: bool,
* is_resource: bool,
* is_scalar: bool,
* is_string: bool,
* is_writable: array{
* positive: string,
* negative: string
* },
* str_contains: array{
* positive: string,
* negative: string,
* argument_count: int,
* swap_arguments: bool
* },
* str_ends_with: array{
* positive: string,
* negative: string,
* argument_count: int,
* swap_arguments: bool
* },
* str_starts_with: array{
* positive: string,
* negative: string,
* argument_count: int,
* swap_arguments: bool
* }
* }
*/
private array $fixMap = [];
private array $fixMap;

/**
* @var list<string>
Expand Down Expand Up @@ -283,11 +353,12 @@ private function fixAssertTrueFalse(Tokens $tokens, ArgumentsAnalyzer $arguments

$isPositive = $isPositive ? 'positive' : 'negative';

if (false === $this->fixMap[$content][$isPositive]) {
$replace = $this->fixMap[$content][$isPositive];
if (false === $replace) {
return;
}

$tokens[$assertCall['index']] = new Token([T_STRING, $this->fixMap[$content][$isPositive]]);
$tokens[$assertCall['index']] = new Token([T_STRING, (string) $replace]);
$this->removeFunctionCall($tokens, $testDefaultNamespaceTokenIndex, $testIndex, $testOpenIndex, $testCloseIndex);

if ($this->fixMap[$content]['swap_arguments'] ?? false) {
Expand Down Expand Up @@ -444,7 +515,7 @@ private function fixAssertSameEquals(Tokens $tokens, array $assertCall): void

$lowerContent = strtolower($tokens[$countCallIndex]->getContent());

if ('count' !== $lowerContent && 'sizeof' !== $lowerContent) {
if (!\in_array($lowerContent, ['count', 'sizeof'], true)) {
return; // not a call to "count" or "sizeOf"
}

Expand Down Expand Up @@ -587,7 +658,77 @@ private function cloneAndClearTokens(Tokens $tokens, int $start, int $end): arra
}

/**
* @return array|array<string, array{positive: string, negative: false|string, argument_count?: int, swap_arguments?: true}|true>
* @return array{
* array_key_exists: array{
* positive: string,
* negative: string,
* argument_count: int
* },
* empty: array{
* positive: string,
* negative: string
* },
* file_exists: array{
* positive: string,
* negative: string
* },
* is_array: bool,
* is_bool: bool,
* is_callable: bool,
* is_dir: array{
* positive: string,
* negative: string
* },
* is_double: bool,
* is_float: bool,
* is_infinite: array{
* positive: string,
* negative: string
* },
* is_int: bool,
* is_integer: bool,
* is_long: bool,
* is_nan: array{
* positive: string,
* negative: bool
* },
* is_null: array{
* positive: string,
* negative: string
* },
* is_numeric: bool,
* is_object: bool,
* is_readable: array{
* positive: string,
* negative: string
* },
* is_real: bool,
* is_resource: bool,
* is_scalar: bool,
* is_string: bool,
* is_writable: array{
* positive: string,
* negative: string
* },
* str_contains: array{
* positive: string,
* negative: string,
* argument_count: int,
* swap_arguments: bool
* },
* str_ends_with: array{
* positive: string,
* negative: string,
* argument_count: int,
* swap_arguments: bool
* },
* str_starts_with: array{
* positive: string,
* negative: string,
* argument_count: int,
* swap_arguments: bool
* }
* }
*/
private function getFixMap(): array
{
Expand Down

0 comments on commit e9c4087

Please sign in to comment.