Skip to content

Commit f9b7756

Browse files
committed
better error message
1 parent a50bbdc commit f9b7756

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

src/Rules/Properties/PropertyInClassRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function processNode(Node $node, Scope $scope): array
3737
&& !$this->phpVersion->supportsFinalProperties()
3838
) {
3939
return [
40-
RuleErrorBuilder::message('Property cannot be final.')
40+
RuleErrorBuilder::message('Final Properties are supported only on PHP 8.4 and later.')
4141
->nonIgnorable()
4242
->identifier('property.final')
4343
->build(),

tests/PHPStan/Rules/Properties/PropertyInClassRuleTest.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,20 @@ public function testPhp84AndAbstractFinalHookedProperties(): void
242242
'Property cannot be both abstract and final.',
243243
7,
244244
],
245+
]);
246+
}
247+
248+
public function testPhp84AndAbstractFinalHookedPropertiesParseError(): void
249+
{
250+
if (PHP_VERSION_ID < 80400) {
251+
$this->markTestSkipped('Test requires PHP 8.4 or later.');
252+
}
253+
254+
// errors when parsing with php-parser, see https://github.com/nikic/PHP-Parser/issues/1071
255+
$this->analyse([__DIR__ . '/data/abstract-final-property-hook-parse-error.php'], [
245256
[
246-
'Property cannot be both abstract and final.',
247-
11,
257+
'Cannot use the final modifier on an abstract class member on line 7',
258+
7,
248259
],
249260
]);
250261
}
@@ -271,15 +282,15 @@ public function testBeforePhp84FinalProperties(): void
271282

272283
$this->analyse([__DIR__ . '/data/final-properties.php'], [
273284
[
274-
'Property cannot be final.',
285+
'Final Properties are supported only on PHP 8.4 and later.',
275286
7,
276287
],
277288
[
278-
'Property cannot be final.',
289+
'Final Properties are supported only on PHP 8.4 and later.',
279290
8,
280291
],
281292
[
282-
'Property cannot be final.',
293+
'Final Properties are supported only on PHP 8.4 and later.',
283294
9,
284295
],
285296
]);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php // lint >= 8.4
2+
3+
namespace AbstractFinalHookParseError;
4+
5+
abstract class User
6+
{
7+
final abstract public string $bar {
8+
get;
9+
}
10+
}

tests/PHPStan/Rules/Properties/data/abstract-final-property-hook.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@ abstract class User
77
abstract public string $foo {
88
final get;
99
}
10-
11-
final abstract public string $bar {
12-
get;
13-
}
1410
}

0 commit comments

Comments
 (0)