Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf/bleedingEdge.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ parameters:
internalTag: true
newStaticInAbstractClassStaticMethod: true
checkExtensionsForComparisonOperators: true
checkGenericIterableClasses: true
reportTooWideBool: true
rawMessageInBaseline: true
1 change: 1 addition & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ parameters:
internalTag: false
newStaticInAbstractClassStaticMethod: false
checkExtensionsForComparisonOperators: false
checkGenericIterableClasses: false
reportTooWideBool: false
rawMessageInBaseline: false
fileExtensions:
Expand Down
1 change: 1 addition & 0 deletions conf/parametersSchema.neon
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ parametersSchema:
internalTag: bool()
newStaticInAbstractClassStaticMethod: bool()
checkExtensionsForComparisonOperators: bool()
checkGenericIterableClasses: bool()
reportTooWideBool: bool()
rawMessageInBaseline: bool()
])
Expand Down
7 changes: 6 additions & 1 deletion src/Rules/MissingTypehintCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public function __construct(
private bool $checkMissingCallableSignature,
#[AutowiredParameter(ref: '%featureToggles.skipCheckGenericClasses%')]
private array $skipCheckGenericClasses,
#[AutowiredParameter(ref: '%featureToggles.checkGenericIterableClasses%')]
private bool $checkGenericIterableClasses,
)
{
}
Expand Down Expand Up @@ -118,7 +120,10 @@ public function getNonGenericObjectTypesWithGenericClass(Type $type): array
if ($classReflection === null) {
return $type;
}
if (in_array($classReflection->getName(), self::ITERABLE_GENERIC_CLASS_NAMES, true)) {
if (
$this->checkGenericIterableClasses !== true &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do !$this->checkGenericIterableClasses instead

in_array($classReflection->getName(), self::ITERABLE_GENERIC_CLASS_NAMES, true)
) {
// checked by getIterableTypesWithMissingValueTypehint() already
return $type;
}
Expand Down
2 changes: 1 addition & 1 deletion stubs/PDOStatement.stub
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PDOStatement implements Traversable, IteratorAggregate
public function getColumnMeta(int $column) {}

/**
* @return Iterator
* @return Iterator<mixed, array<int|string, mixed>>
*/
public function getIterator() {}
}
6 changes: 6 additions & 0 deletions stubs/runtime/ReflectionAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ public function isRepeated(): bool
{
}

/**
* @return array<array-key, mixed>;
*/
public function getArguments(): array
{
}

/**
* @return self
*/
public function newInstance(): object
{
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/bug-8886.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ function testPDOStatementGetIterator(): void {
$pdo = new PDO('sqlite::memory:');
$stmt = $pdo->query('SELECT 1');

assertType('Iterator', $stmt->getIterator());
assertType('Iterator<mixed, array<int|string, mixed>>', $stmt->getIterator());
}
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Classes/LocalTypeAliasesRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function getRule(): Rule
['GlobalTypeAlias' => 'int|string'],
self::createReflectionProvider(),
self::getContainer()->getByType(TypeNodeResolver::class),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new ClassNameCheck(
new ClassCaseSensitivityCheck($reflectionProvider, true),
new ClassForbiddenNameCheck(self::getContainer()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function getRule(): Rule
['GlobalTypeAlias' => 'int|string'],
self::createReflectionProvider(),
self::getContainer()->getByType(TypeNodeResolver::class),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new ClassNameCheck(
new ClassCaseSensitivityCheck($reflectionProvider, true),
new ClassForbiddenNameCheck(self::getContainer()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function getRule(): Rule
['GlobalTypeAlias' => 'int|string'],
self::createReflectionProvider(),
self::getContainer()->getByType(TypeNodeResolver::class),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new ClassNameCheck(
new ClassCaseSensitivityCheck($reflectionProvider, true),
new ClassForbiddenNameCheck(self::getContainer()),
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Classes/MethodTagRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function getRule(): TRule
self::getContainer(),
),
new GenericObjectTypeCheck(),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new UnresolvableTypeHelper(),
true,
true,
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Classes/MethodTagTraitRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function getRule(): TRule
self::getContainer(),
),
new GenericObjectTypeCheck(),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new UnresolvableTypeHelper(),
true,
true,
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Classes/MethodTagTraitUseRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function getRule(): TRule
self::getContainer(),
),
new GenericObjectTypeCheck(),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new UnresolvableTypeHelper(),
true,
true,
Expand Down
6 changes: 5 additions & 1 deletion tests/PHPStan/Rules/Classes/MixinRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function getRule(): Rule
self::getContainer(),
),
new GenericObjectTypeCheck(),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new UnresolvableTypeHelper(),
true,
true,
Expand Down Expand Up @@ -68,6 +68,10 @@ public function testRule(): void
'PHPDoc tag @mixin contains generic class ReflectionClass but does not specify its types: T',
50,
],
[
'PHPDoc tag @mixin contains generic interface Iterator but does not specify its types: TKey, TValue',
50,
],
[
'PHPDoc tag @mixin contains unknown class MixinRule\UnknownestClass.',
50,
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Classes/MixinTraitRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function getRule(): Rule
self::getContainer(),
),
new GenericObjectTypeCheck(),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new UnresolvableTypeHelper(),
true,
true,
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Classes/MixinTraitUseRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function getRule(): Rule
self::getContainer(),
),
new GenericObjectTypeCheck(),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new UnresolvableTypeHelper(),
true,
true,
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Classes/PropertyTagRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function getRule(): TRule
self::getContainer(),
),
new GenericObjectTypeCheck(),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new UnresolvableTypeHelper(),
true,
true,
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Classes/PropertyTagTraitRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function getRule(): TRule
self::getContainer(),
),
new GenericObjectTypeCheck(),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new UnresolvableTypeHelper(),
true,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function getRule(): TRule
self::getContainer(),
),
new GenericObjectTypeCheck(),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new UnresolvableTypeHelper(),
true,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MissingClassConstantTypehintRuleTest extends RuleTestCase

protected function getRule(): Rule
{
return new MissingClassConstantTypehintRule(new MissingTypehintCheck(true, []));
return new MissingClassConstantTypehintRule(new MissingTypehintCheck(true, [], true));
}

public function testRule(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MissingFunctionParameterTypehintRuleTest extends RuleTestCase

protected function getRule(): Rule
{
return new MissingFunctionParameterTypehintRule(new MissingTypehintCheck(true, []));
return new MissingFunctionParameterTypehintRule(new MissingTypehintCheck(true, [], true));
}

public function testRule(): void
Expand Down Expand Up @@ -71,6 +71,11 @@ public function testRule(): void
148,
MissingTypehintCheck::MISSING_ITERABLE_VALUE_TYPE_TIP,
],
[
'Function MissingFunctionParameterTypehint\missingTraversableTypehint() has parameter $traversable with generic interface Traversable but does not specify its types: TKey, TValu',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure this will fail with a typo - TValu vs. TValue

148,
MissingTypehintCheck::MISSING_ITERABLE_VALUE_TYPE_TIP,
],
[
'Function MissingFunctionParameterTypehint\missingTraversableTypehintPhpDoc() has parameter $traversable with no value type specified in iterable type Traversable.',
156,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MissingFunctionReturnTypehintRuleTest extends RuleTestCase

protected function getRule(): Rule
{
return new MissingFunctionReturnTypehintRule(new MissingTypehintCheck(true, []));
return new MissingFunctionReturnTypehintRule(new MissingTypehintCheck(true, [], true));
}

public function testRule(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ function unionTypeWithUnknownArrayValueTypehint($a)
}

/**
* @param iterable<int>&\Traversable $a
* @param iterable<int>&\Traversable<array-key,int> $a
*/
function iterableIntersectionTypehint($a)
{

}

/**
* @param iterable<mixed>&\Traversable $a
* @param iterable<mixed>&\Traversable<array-key,mixed> $a
*/
function iterableIntersectionTypehint2($a)
{
Expand Down Expand Up @@ -151,7 +151,7 @@ function missingTraversableTypehint(\Traversable $traversable)
}

/**
* @param \Traversable $traversable
* @param \Traversable<array-key, mixed> $traversable
*/
function missingTraversableTypehintPhpDoc($traversable)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MissingMethodParameterTypehintRuleTest extends RuleTestCase

protected function getRule(): Rule
{
return new MissingMethodParameterTypehintRule(new MissingTypehintCheck(true, []));
return new MissingMethodParameterTypehintRule(new MissingTypehintCheck(true, [], true));
}

public function testRule(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MissingMethodReturnTypehintRuleTest extends RuleTestCase

protected function getRule(): Rule
{
return new MissingMethodReturnTypehintRule(new MissingTypehintCheck(true, []));
return new MissingMethodReturnTypehintRule(new MissingTypehintCheck(true, [], true));
}

public function testRule(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MissingMethodSelfOutTypeRuleTest extends RuleTestCase

protected function getRule(): TRule
{
return new MissingMethodSelfOutTypeRule(new MissingTypehintCheck(true, []));
return new MissingMethodSelfOutTypeRule(new MissingTypehintCheck(true, [], true));
}

public function testRule(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function doFoo(): callable
class IterableIntersection
{

/** @return FooInterface[]|\Traversable */
/** @return FooInterface[]|\Traversable<array-key, FooInterface> */
public function doFoo(): \Traversable
{

Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/PhpDoc/FunctionAssertRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function getRule(): Rule
$reflectionProvider,
self::getContainer(),
),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new GenericObjectTypeCheck(),
true,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function getRule(): Rule
self::getContainer(),
),
new GenericObjectTypeCheck(),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new UnresolvableTypeHelper(),
true,
true,
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/PhpDoc/MethodAssertRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function getRule(): Rule
$reflectionProvider,
self::getContainer(),
),
new MissingTypehintCheck(true, []),
new MissingTypehintCheck(true, [], true),
new GenericObjectTypeCheck(),
true,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MissingPropertyTypehintRuleTest extends RuleTestCase

protected function getRule(): Rule
{
return new MissingPropertyTypehintRule(new MissingTypehintCheck(true, []));
return new MissingPropertyTypehintRule(new MissingTypehintCheck(true, [], true));
}

public function testRule(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SetPropertyHookParameterRuleTest extends RuleTestCase

protected function getRule(): TRule
{
return new SetPropertyHookParameterRule(new MissingTypehintCheck(true, []), true, true);
return new SetPropertyHookParameterRule(new MissingTypehintCheck(true, [], true), true, true);
}

#[RequiresPhp('>= 8.4')]
Expand Down
Loading