Skip to content

Commit 02e8c5f

Browse files
Fixes
Case insensitive attribute handling, mandatory parameter, enum cases
1 parent f4e9feb commit 02e8c5f

23 files changed

+59
-10
lines changed

src/Reflection/Native/NativeFunctionReflection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPStan\TrinaryLogic;
1111
use PHPStan\Type\Type;
1212
use function count;
13+
use function strtolower;
1314

1415
final class NativeFunctionReflection implements FunctionReflection
1516
{
@@ -153,7 +154,7 @@ public function getAttributes(): array
153154
public function hasNoDiscardAttribute(): TrinaryLogic
154155
{
155156
foreach ($this->attributes as $attrib) {
156-
if ($attrib->getName() === 'NoDiscard') {
157+
if (strtolower($attrib->getName()) === 'nodiscard') {
157158
return TrinaryLogic::createYes();
158159
}
159160
}

src/Reflection/Native/NativeMethodReflection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public function getAttributes(): array
230230
public function hasNoDiscardAttribute(): TrinaryLogic
231231
{
232232
foreach ($this->attributes as $attrib) {
233-
if ($attrib->getName() === 'NoDiscard') {
233+
if (strtolower($attrib->getName()) === 'nodiscard') {
234234
return TrinaryLogic::createYes();
235235
}
236236
}

src/Reflection/Php/EnumCasesMethodReflection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function getAttributes(): array
163163

164164
public function hasNoDiscardAttribute(): TrinaryLogic
165165
{
166-
return TrinaryLogic::createYes();
166+
return TrinaryLogic::createNo();
167167
}
168168

169169
}

src/Reflection/Php/PhpFunctionFromParserNodeReflection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use function array_reverse;
2525
use function is_array;
2626
use function is_string;
27+
use function strtolower;
2728

2829
/**
2930
* @api
@@ -333,7 +334,7 @@ public function getAttributes(): array
333334
public function hasNoDiscardAttribute(): TrinaryLogic
334335
{
335336
foreach ($this->attributes as $attrib) {
336-
if ($attrib->getName() === 'NoDiscard') {
337+
if (strtolower($attrib->getName()) === 'nodiscard') {
337338
return TrinaryLogic::createYes();
338339
}
339340
}

src/Reflection/Php/PhpFunctionReflection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use function count;
3030
use function is_array;
3131
use function is_file;
32+
use function strtolower;
3233

3334
#[GenerateFactory(interface: FunctionReflectionFactory::class)]
3435
final class PhpFunctionReflection implements FunctionReflection
@@ -278,7 +279,7 @@ public function getAttributes(): array
278279
public function hasNoDiscardAttribute(): TrinaryLogic
279280
{
280281
foreach ($this->attributes as $attrib) {
281-
if ($attrib->getName() === 'NoDiscard') {
282+
if (strtolower($attrib->getName()) === 'nodiscard') {
282283
return TrinaryLogic::createYes();
283284
}
284285
}

src/Reflection/Php/PhpMethodReflection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public function getAttributes(): array
523523
public function hasNoDiscardAttribute(): TrinaryLogic
524524
{
525525
foreach ($this->attributes as $attrib) {
526-
if ($attrib->getName() === 'NoDiscard') {
526+
if (strtolower($attrib->getName()) === 'nodiscard') {
527527
return TrinaryLogic::createYes();
528528
}
529529
}

src/Rules/AttributesCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function check(
4040
array $attrGroups,
4141
int $requiredTarget,
4242
string $targetName,
43-
bool $isPropertyHook = false,
43+
bool $isPropertyHook,
4444
): array
4545
{
4646
$errors = [];

src/Rules/Classes/ClassAttributesRule.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function processNode(Node $node, Scope $scope): array
3838
$classLikeNode->attrGroups,
3939
Attribute::TARGET_CLASS,
4040
'class',
41+
false,
4142
);
4243

4344
$classReflection = $node->getClassReflection();

src/Rules/Classes/ClassConstantAttributesRule.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function processNode(Node $node, Scope $scope): array
3232
$node->attrGroups,
3333
Attribute::TARGET_CLASS_CONSTANT,
3434
'class constant',
35+
false,
3536
);
3637
}
3738

src/Rules/EnumCases/EnumCaseAttributesRule.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function processNode(Node $node, Scope $scope): array
3232
$node->attrGroups,
3333
Attribute::TARGET_CLASS_CONSTANT,
3434
'class constant',
35+
false,
3536
);
3637
}
3738

0 commit comments

Comments
 (0)