Skip to content

Commit f4e9feb

Browse files
fixes
1 parent 014a282 commit f4e9feb

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ lint:
111111
--exclude tests/PHPStan/Rules/Classes/data/class-attributes.php \
112112
--exclude tests/PHPStan/Rules/Classes/data/enum-attributes.php \
113113
--exclude tests/PHPStan/Rules/Cast/data/void-cast.php \
114-
--exclude tests/PHPStan/Rules/Properties/data/property-hook-attributes.php \
114+
--exclude tests/PHPStan/Rules/Properties/data/property-hook-attributes-nodiscard.php \
115115
src tests
116116

117117
install-paratest:

build/collision-detector.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"../tests/PHPStan/Rules/Functions/data/function-call-statement-result-discarded.php",
2020
"../tests/PHPStan/Rules/Methods/data/method-call-statement-result-discarded.php",
2121
"../tests/PHPStan/Rules/Methods/data/static-method-call-statement-result-discarded.php",
22-
"../tests/PHPStan/Rules/Properties/data/property-hook-attributes.php"
22+
"../tests/PHPStan/Rules/Properties/data/property-hook-attributes-nodiscard.php",
23+
"../tests/PHPStan/Rules/Cast/data/void-cast.php"
2324
]
2425
}

src/Rules/AttributesCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function check(
8282
->identifier('attribute.target')
8383
->line($attribute->getStartLine())
8484
->build();
85-
} elseif ($isPropertyHook && strtolower($name) === "nodiscard") {
85+
} elseif ($isPropertyHook && strtolower($name) === 'nodiscard') {
8686
// #[\NoDiscard] cannot be used on property hooks
8787
$errors[] = RuleErrorBuilder::message(sprintf('Attribute class %s cannot be used on property hooks.', $name))
8888
->identifier('attribute.target')

tests/PHPStan/Rules/Properties/PropertyHookAttributesRuleTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,16 @@ public function testRule(): void
5555
'Attribute class PropertyHookAttributes\Foo does not have the method target.',
5656
27,
5757
],
58+
]);
59+
}
60+
61+
#[RequiresPhp('>= 8.5')]
62+
public function testNoDiscard(): void
63+
{
64+
$this->analyse([__DIR__ . '/data/property-hook-attributes-nodiscard.php'], [
5865
[
5966
'Attribute class NoDiscard cannot be used on property hooks.',
60-
63,
67+
9,
6168
],
6269
]);
6370
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php // lint >= 8.5
2+
3+
namespace PropertyHookAttributes;
4+
5+
class Sit
6+
{
7+
8+
public int $i {
9+
#[\NoDiscard]
10+
get {
11+
12+
}
13+
}
14+
}

tests/PHPStan/Rules/Properties/data/property-hook-attributes.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,3 @@ class Dolor
5555
}
5656

5757
}
58-
59-
class Sit
60-
{
61-
62-
public int $i {
63-
#[\NoDiscard]
64-
get {
65-
66-
}
67-
}
68-
}

0 commit comments

Comments
 (0)