Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX: Fix PHPStan errors #6504

Merged
merged 1 commit into from Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions phpstan.neon
Expand Up @@ -23,10 +23,6 @@ parameters:
-
message: '#^.+no value type specified in iterable type.+\.$#'
path: *
count: 561
-
message: '#^Property .+ has no type specified\.$#'
path: *
count: 7
count: 542
tipsOfTheDay: false
tmpDir: dev-tools/phpstan/cache
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
julienfalque marked this conversation as resolved.
Show resolved Hide resolved
*/
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>
julienfalque marked this conversation as resolved.
Show resolved Hide resolved
*/
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>
julienfalque marked this conversation as resolved.
Show resolved Hide resolved
*/
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