The following class
<?php
namespace App;
use IlluminateSupportStr;
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 AppPayload::$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?
3