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
2 changes: 1 addition & 1 deletion src/Rules/Properties/OverridingPropertyRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private function processPrototype(
}
} elseif ($node->isReadOnly()) {
if (
!$this->phpVersion->supportsPropertyHooks()
!$prototype->isAbstract()->yes()
|| $prototype->isWritable()
) {
$errors[] = RuleErrorBuilder::message(sprintf(
Expand Down
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Properties/OverridingPropertyRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,14 @@ public function testHooks(): void
'Get hook for property OverridingPropertyHooks\OverrideChild::$notInParent has #[\Override] attribute but does not override any get hook.',
227,
],
[
'Readonly property OverridingPropertyHooks\ReadonlyOverridesVirtualGet::$prop overrides readwrite property OverridingPropertyHooks\VirtualGetParent::$prop.',
245,
],
[
'Readonly property OverridingPropertyHooks\ReadonlyOverridesVirtualGetInAbstractClass::$prop overrides readwrite property OverridingPropertyHooks\AbstractClassVirtualGetParent::$prop.',
261,
],
]);
}

Expand Down
46 changes: 46 additions & 0 deletions tests/PHPStan/Rules/Properties/data/overriding-property-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,49 @@ class OverrideChild extends OverrideParent
}

}

class VirtualGetParent
{

public string $prop {
get => 'parent';
}

}

class ReadonlyOverridesVirtualGet extends VirtualGetParent
{

public readonly string $prop;

}

abstract class AbstractClassVirtualGetParent
{

public string $prop {
get => 'parent';
}

}

class ReadonlyOverridesVirtualGetInAbstractClass extends AbstractClassVirtualGetParent
{

public readonly string $prop;

}

abstract class AbstractGetParent
{

abstract public string $prop { get; }

}

class ReadonlyImplementsAbstractGet extends AbstractGetParent
{

public readonly string $prop;

}
Loading