Skip to content

[Question] mark private properties as readonly in Constructor Property Promotion #1519

Open
@mimmi20

Description

@mimmi20

There is the rule SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion.RequiredConstructorPropertyPromotion which enforces Constructor Property Promotion.

Is there an other (additional) rule that marks private properties as readonly?

For example:

    private array $config;

    public function __construct(array $config) {
        $this->config = $config;
    }

actually is converted to

    public function __construct(private array $config)
    {
        // nothing to do
    }

but also may be converted to

    public function __construct(private readonly array $config)
    {
        // nothing to do
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions