Skip to content

Commit

Permalink
Fix PHPStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
julienfalque committed Jul 19, 2022
1 parent fab645b commit 1491256
Show file tree
Hide file tree
Showing 18 changed files with 255 additions and 221 deletions.
12 changes: 0 additions & 12 deletions phpstan.neon
Expand Up @@ -24,22 +24,10 @@ parameters:
message: '#^Method .+ has parameter .+ with no value type specified in iterable type array\.$#'
path: *
count: 363
-
message: '#^Method .+ has parameter .+ with no value type specified in iterable type iterable\.$#'
path: *
count: 4
-
message: '#^Method .+ return type has no value type specified in iterable type array\.$#'
path: *
count: 153
-
message: '#^Method .+ return type has no value type specified in iterable type iterable\.$#'
path: *
count: 15
-
message: '#^Property .+ has no type specified\.$#'
path: *
count: 7
-
message: '#^Property .+ type has no value type specified in iterable type array\.$#'
path: *
Expand Down
6 changes: 5 additions & 1 deletion src/ConfigInterface.php
Expand Up @@ -15,6 +15,7 @@
namespace PhpCsFixer;

use PhpCsFixer\Fixer\FixerInterface;
use SplFileInfo;

/**
* @author Fabien Potencier <fabien@symfony.com>
Expand All @@ -39,7 +40,7 @@ public function getCustomFixers(): array;
/**
* Returns files to scan.
*
* @return iterable|\Traversable
* @return iterable<SplFileInfo>
*/
public function getFinder(): iterable;

Expand Down Expand Up @@ -99,6 +100,9 @@ public function registerCustomFixers(iterable $fixers): self;
*/
public function setCacheFile(string $cacheFile): self;

/**
* @param iterable<SplFileInfo> $finder
*/
public function setFinder(iterable $finder): self;

public function setFormat(string $format): self;
Expand Down
12 changes: 10 additions & 2 deletions src/Console/ConfigurationResolver.php
Expand Up @@ -147,14 +147,17 @@ final class ConfigurationResolver
*/
private ?iterable $finder = null;

private $format;
private ?string $format = null;

/**
* @var null|Linter
*/
private $linter;

private $path;
/**
* @var null|list<string>
*/
private ?array $path = null;

/**
* @var null|string
Expand Down Expand Up @@ -480,6 +483,9 @@ public function getUsingCache(): bool
return $this->usingCache;
}

/**
* @return iterable<\SplFileInfo>
*/
public function getFinder(): iterable
{
if (null === $this->finder) {
Expand Down Expand Up @@ -803,6 +809,8 @@ private function validateRules(array $rules): void

/**
* Apply path on config instance.
*
* @return iterable<\SplFileInfo>
*/
private function resolveFinder(): iterable
{
Expand Down
3 changes: 3 additions & 0 deletions src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php
Expand Up @@ -116,6 +116,9 @@ private function clearOverCompleteBraces(Tokens $tokens, int $openIndex, int $cl
$tokens->clearTokenAndMergeSurroundingWhitespace($openIndex);
}

/**
* @return iterable<int>
*/
private function findCurlyBraceOpen(Tokens $tokens): iterable
{
for ($i = \count($tokens) - 1; $i > 0; --$i) {
Expand Down
3 changes: 3 additions & 0 deletions src/Fixer/Import/FullyQualifiedStrictTypesFixer.php
Expand Up @@ -180,6 +180,9 @@ private function replaceByShortType(Tokens $tokens, TypeAnalysis $type, array $u
}
}

/**
* @return iterable<string, array{int, int}>
*/
private function getTypes(Tokens $tokens, int $index, int $endIndex): iterable
{
$index = $typeStartIndex = $typeEndIndex = $tokens->getNextMeaningfulToken($index - 1);
Expand Down
3 changes: 3 additions & 0 deletions src/Fixer/Import/GlobalNamespaceImportFixer.php
Expand Up @@ -652,6 +652,9 @@ private function filterUseDeclarations(array $declarations, callable $callback,
return [$global, $other];
}

/**
* @return iterable<string>
*/
private function findFunctionDeclarations(Tokens $tokens, int $start, int $end): iterable
{
for ($index = $start; $index <= $end; ++$index) {
Expand Down
8 changes: 8 additions & 0 deletions src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php
Expand Up @@ -507,6 +507,14 @@ private function fixAssertSameEquals(Tokens $tokens, array $assertCall): void
]);
}

/**
* @return iterable<array{
* index: int,
* loweredName: string,
* openBraceIndex: int,
* closeBraceIndex: int,
* }>
*/
private function getPreviousAssertCall(Tokens $tokens, int $startIndex, int $endIndex): iterable
{
$functionsAnalyzer = new FunctionsAnalyzer();
Expand Down
22 changes: 4 additions & 18 deletions tests/AbstractFunctionReferenceFixerTest.php
Expand Up @@ -24,22 +24,6 @@
*/
final class AbstractFunctionReferenceFixerTest extends TestCase
{
private $fixer;

protected function setUp(): void
{
$this->fixer = new FunctionReferenceTestFixer();

parent::setUp();
}

protected function tearDown(): void
{
$this->fixer = null;

parent::tearDown();
}

/**
* @param null|int[] $expected
*
Expand All @@ -52,13 +36,15 @@ public function testAbstractFunctionReferenceFixer(
int $start = 0,
?int $end = null
): void {
static::assertTrue($this->fixer->isRisky());
$fixer = new FunctionReferenceTestFixer();

static::assertTrue($fixer->isRisky());

$tokens = Tokens::fromCode($source);

static::assertSame(
$expected,
$this->fixer->findTest(
$fixer->findTest(
$functionNameToSearch,
$tokens,
$start,
Expand Down
7 changes: 7 additions & 0 deletions tests/AutoReview/ProjectCodeTest.php
Expand Up @@ -14,6 +14,7 @@

namespace PhpCsFixer\Tests\AutoReview;

use PhpCsFixer\DocBlock\Annotation;
use PhpCsFixer\DocBlock\DocBlock;
use PhpCsFixer\FixerFactory;
use PhpCsFixer\Preg;
Expand Down Expand Up @@ -726,6 +727,9 @@ public function testConstantsAreInUpperCase(string $className): void
}
}

/**
* @return iterable<string, string>
*/
private function getUsedDataProviderMethodNames(string $testClassName): iterable
{
foreach ($this->getAnnotationsOfTestClass($testClassName, 'dataProvider') as $methodName => $dataProviderAnnotation) {
Expand All @@ -735,6 +739,9 @@ private function getUsedDataProviderMethodNames(string $testClassName): iterable
}
}

/**
* @return iterable<string, Annotation>
*/
private function getAnnotationsOfTestClass(string $testClassName, string $annotation): iterable
{
$tokens = Tokens::fromCode(file_get_contents(
Expand Down
3 changes: 2 additions & 1 deletion tests/ConfigTest.php
Expand Up @@ -193,7 +193,8 @@ public function testThatMutatorHasFluentInterface(): void
}

/**
* @param FixerInterface[] $expected
* @param list<FixerInterface> $expected
* @param iterable<FixerInterface> $suite
*
* @dataProvider provideRegisterCustomFixersCases
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php
Expand Up @@ -330,6 +330,9 @@ private static function assertCandidateTokenType(int $expected, AbstractFixer $f
static::assertSame($expected, $reflectionProperty->getValue($fixer));
}

/**
* @return iterable<non-empty-string>
*/
private static function getCodeSnippetsToConvertBothWays(): iterable
{
yield 'inside of HTML' => '<div><?php %1$s "foo" ?></div>';
Expand Down

0 comments on commit 1491256

Please sign in to comment.