Skip to content

Commit 3175c81

Browse files
committed
Bleeding edge - add missing MissingTypehintCheck calls
1 parent 5a2d441 commit 3175c81

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

conf/config.level2.neon

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ services:
7171
class: PHPStan\Rules\Classes\MixinRule
7272
arguments:
7373
checkClassCaseSensitivity: %checkClassCaseSensitivity%
74+
absentTypeChecks: %featureToggles.absentTypeChecks%
7475
tags:
7576
- phpstan.rules.rule
7677

src/Rules/Classes/MixinRule.php

+25
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function __construct(
3131
private MissingTypehintCheck $missingTypehintCheck,
3232
private UnresolvableTypeHelper $unresolvableTypeHelper,
3333
private bool $checkClassCaseSensitivity,
34+
private bool $absentTypeChecks,
3435
)
3536
{
3637
}
@@ -83,6 +84,30 @@ public function processNode(Node $node, Scope $scope): array
8384
->build();
8485
}
8586

87+
if ($this->absentTypeChecks) {
88+
foreach ($this->missingTypehintCheck->getIterableTypesWithMissingValueTypehint($type) as $iterableType) {
89+
$iterableTypeDescription = $iterableType->describe(VerbosityLevel::typeOnly());
90+
$errors[] = RuleErrorBuilder::message(sprintf(
91+
'%s %s has PHPDoc tag @mixin with no value type specified in iterable type %s.',
92+
$classReflection->getClassTypeDescription(),
93+
$classReflection->getDisplayName(),
94+
$iterableTypeDescription,
95+
))
96+
->tip(MissingTypehintCheck::MISSING_ITERABLE_VALUE_TYPE_TIP)
97+
->identifier('missingType.iterableValue')
98+
->build();
99+
}
100+
101+
foreach ($this->missingTypehintCheck->getCallablesWithMissingSignature($type) as $callableType) {
102+
$errors[] = RuleErrorBuilder::message(sprintf(
103+
'%s %s has PHPDoc tag @mixin with no signature specified for %s.',
104+
$classReflection->getClassTypeDescription(),
105+
$classReflection->getDisplayName(),
106+
$callableType->describe(VerbosityLevel::typeOnly()),
107+
))->identifier('missingType.callable')->build();
108+
}
109+
}
110+
86111
foreach ($type->getReferencedClasses() as $class) {
87112
if (!$this->reflectionProvider->hasClass($class)) {
88113
$errors[] = RuleErrorBuilder::message(sprintf('PHPDoc tag @mixin contains unknown class %s.', $class))

tests/PHPStan/Rules/Classes/MixinRuleTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ protected function getRule(): Rule
3232
new MissingTypehintCheck(true, true, true, true, []),
3333
new UnresolvableTypeHelper(),
3434
true,
35+
true,
3536
);
3637
}
3738

@@ -97,6 +98,15 @@ public function testRule(): void
9798
116,
9899
'You can safely remove the call-site variance annotation.',
99100
],
101+
[
102+
'Class MixinRule\NoIterableValue has PHPDoc tag @mixin with no value type specified in iterable type array.',
103+
124,
104+
MissingTypehintCheck::MISSING_ITERABLE_VALUE_TYPE_TIP,
105+
],
106+
[
107+
'Class MixinRule\NoCallableSignature has PHPDoc tag @mixin with no signature specified for callable.',
108+
132,
109+
],
100110
]);
101111
}
102112

tests/PHPStan/Rules/Classes/data/mixin.php

+16
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,19 @@ class Elit2
117117
{
118118

119119
}
120+
121+
/**
122+
* @mixin Dolor<array>
123+
*/
124+
class NoIterableValue
125+
{
126+
127+
}
128+
129+
/**
130+
* @mixin Dolor<callable>
131+
*/
132+
class NoCallableSignature
133+
{
134+
135+
}

0 commit comments

Comments
 (0)