Skip to content

Commit 6d4a2d0

Browse files
phpstan-botclaude
andcommitted
Add test for bug-12253 with additionalConstructors configured
Adds a PayloadWithAdditionalConstructor test class that reproduces the same readonly property false positive scenario but with setUp() configured as an additional constructor via ConstructorsHelper. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7f6add5 commit 6d4a2d0

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protected function getRule(): Rule
2626
'Bug10523\\Controller::init',
2727
'Bug10523\\MultipleWrites::init',
2828
'Bug10523\\SingleWriteInConstructorCalledMethod::init',
29+
'Bug12253\\PayloadWithAdditionalConstructor::setUp',
2930
],
3031
),
3132
);

tests/PHPStan/Rules/Properties/data/bug-12253.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,50 @@ private function validationValue(mixed $value): mixed
4646
}
4747
}
4848

49+
class PayloadWithAdditionalConstructor
50+
{
51+
/** @var array<array<string, mixed>> */
52+
private(set) readonly array $validation;
53+
54+
/** @var array<string, string> */
55+
private array $ids = [];
56+
57+
public function __construct(private readonly stdClass $payload)
58+
{
59+
}
60+
61+
public function setUp(): void
62+
{
63+
$this->parseValidation();
64+
}
65+
66+
private function parseValidation(): void
67+
{
68+
$validations = [];
69+
70+
foreach ($this->payload->validation as $key => $validation) {
71+
$validations[] = [
72+
'id' => $key,
73+
'field_id' => $this->ids[$validation->field_id],
74+
'rule' => $validation->rule,
75+
'value' => $this->validationValue($validation->value),
76+
'message' => $validation->message,
77+
];
78+
}
79+
80+
$this->validation = $validations;
81+
}
82+
83+
private function validationValue(mixed $value): mixed
84+
{
85+
if (is_null($value)) {
86+
return null;
87+
}
88+
89+
return $this->ids[$value] ?? $value;
90+
}
91+
}
92+
4993
class PayloadWithoutAsymmetricVisibility
5094
{
5195
/** @var array<array<string, mixed>> */

0 commit comments

Comments
 (0)