Bug report
The following class
<?php
namespace App;
use Illuminate\Support\Str;
use stdClass;
class Payload
{
private(set) readonly array $validation;
private array $ids = [];
public function __construct(private readonly stdClass $payload)
{
$this->parseValidation();
}
private function parseValidation(): void
{
$validations = [];
foreach ($this->payload->validation as $validation) {
$validations[] = [
'id' => Str::orderedUuid()->toString(),
'field_id' => $this->ids[$validation->field_id],
'rule' => $validation->rule,
'value' => $this->validationValue($validation->value),
'message' => $validation->message,
];
}
$this->validation = $validations;
}
private function validationValue(mixed $value): mixed
{
if (is_null($value)) {
return null;
}
return $this->ids[$value] ?? $value;
}
}
when analysed returns
$ phpstan analyse app/Payload.php
1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
------ -----------------------------------------------------------------
Line Payload.php
------ -----------------------------------------------------------------
35 Readonly property App\Payload::$validation is already assigned.
🪪 assign.readOnlyProperty
------ -----------------------------------------------------------------
It appears the issue is with the call to validationValue method, but cannot figure out what and why read only association error?
Code snippet that reproduces the problem
No response
Example
Try it
Bug report
The following class
when analysed returns
It appears the issue is with the call to
validationValuemethod, but cannot figure out what and why read only association error?Code snippet that reproduces the problem
No response
Example
Try it