Skip to content

Commit b7e6d0f

Browse files
committed
fix
1 parent 9e0f58a commit b7e6d0f

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

src/Rules/Properties/PropertyInClassRule.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public function processNode(Node $node, Scope $scope): array
8181
];
8282
}
8383

84+
if (
8485
$node->isFinal()
8586
&& !$node->hasHooks()
8687
&& (!$this->phpVersion->supportsNonPrivateFinalProperties() || $node->isPrivate())
@@ -94,28 +95,26 @@ public function processNode(Node $node, Scope $scope): array
9495
}
9596

9697
if ($node->isPrivate()) {
97-
if ($node->hasHooks()) {
98-
if ($node->isFinal()) {
99-
return [
100-
RuleErrorBuilder::message('Hooked properties cannot be both final and private.')
101-
->nonIgnorable()
102-
->identifier('property.abstractPrivate')
103-
->build(),
104-
];
105-
}
98+
if ($node->isFinal()) {
99+
return [
100+
RuleErrorBuilder::message('Properties cannot be both final and private.')
101+
->nonIgnorable()
102+
->identifier('property.finalPrivate')
103+
->build(),
104+
];
105+
}
106106

107-
foreach ($node->getHooks() as $hook) {
108-
if (!$hook->isFinal()) {
109-
continue;
110-
}
111-
112-
return [
113-
RuleErrorBuilder::message('Hooked properties cannot be both final and private.')
114-
->nonIgnorable()
115-
->identifier('property.abstractPrivate')
116-
->build(),
117-
];
107+
foreach ($node->getHooks() as $hook) {
108+
if (!$hook->isFinal()) {
109+
continue;
118110
}
111+
112+
return [
113+
RuleErrorBuilder::message('Properties cannot be both final and private.')
114+
->nonIgnorable()
115+
->identifier('property.finalPrivate')
116+
->build(),
117+
];
119118
}
120119
}
121120

tests/PHPStan/Rules/Properties/data/private-final-property-hooks.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ final class User
88
get => 'private:' . $this->privatePropGet;
99
}
1010

11-
private string $privateSet = 'mailto: example.org' {
12-
final set => 'private:' . $this->privateSet;
11+
private string $private = 'mailto: example.org' {
12+
final set => 'private:' . $this->private;
13+
get => 'private:' . $this->private;
1314
}
1415

1516
protected string $protected = 'mailto: example.org' {

0 commit comments

Comments
 (0)