Skip to content

assign.readOnlyProperty #12253

@sebastiansulinski

Description

@sebastiansulinski

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions