Skip to content
Merged
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ lint:
--exclude tests/PHPStan/Rules/Classes/data/invalid-hooked-properties.php \
--exclude tests/PHPStan/Parser/data/cleaning-property-hooks-before.php \
--exclude tests/PHPStan/Parser/data/cleaning-property-hooks-after.php \
--exclude tests/PHPStan/Rules/Properties/data/abstract-private-property-hook.php \
--exclude tests/PHPStan/Rules/Properties/data/existing-classes-property-hooks.php \
--exclude tests/PHPStan/Rules/Properties/data/set-property-hook-parameter.php \
--exclude tests/PHPStan/Rules/Properties/data/overriding-final-property.php \
Expand Down
9 changes: 9 additions & 0 deletions src/Rules/Properties/PropertyInClassRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ public function processNode(Node $node, Scope $scope): array
}

if ($node->isPrivate()) {
if ($node->isAbstract()) {
return [
RuleErrorBuilder::message('Property cannot be both abstract and private.')
->nonIgnorable()
->identifier('property.abstractPrivate')
->build(),
];
}

if ($node->isFinal()) {
return [
RuleErrorBuilder::message('Property cannot be both final and private.')
Expand Down
14 changes: 14 additions & 0 deletions tests/PHPStan/Rules/Properties/PropertyInClassRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ public function testPhp84AndAbstractFinalHookedProperties(): void
]);
}

public function testPhp84AndAbstractPrivateHookedProperties(): void
{
if (PHP_VERSION_ID < 80400) {
$this->markTestSkipped('Test requires PHP 8.4 or later.');
}

$this->analyse([__DIR__ . '/data/abstract-private-property-hook.php'], [
[
'Property cannot be both abstract and private.',
7,
],
]);
}

public function testPhp84AndAbstractFinalHookedPropertiesParseError(): void
{
if (PHP_VERSION_ID < 80400) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php // lint >= 8.4

namespace AbstractPrivateHook;

abstract class Foo
{
abstract private int $i { get; }
abstract protected int $ii { get; }
abstract public int $iii { get; }
}
Loading