Skip to content

Incorrect behavior of ChangeReadOnlyVariableWithDefaultValueToConstantRector, ChangeReadOnlyPropertyWithDefaultValueToConstantRector, TypedPropertyFromAssignsRector #7944

Description

@samsonasik

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/a4d71e69-0b0b-498c-b3b1-9e9a0665cc10

<?php

declare(strict_types=1);

namespace Rector\Core\Kernel;

final class RectorKernel
{
    /** @var string|null */
    private static $defaultFilesHash;

    /**
     * @param string[] $configFiles
     */
    private function createConfigsHash(array $configFiles): string
    {
        $fileHasher = new FileHasher();

        if (self::$defaultFilesHash === null) {
            self::$defaultFilesHash = 'test';
        }

        return self::$defaultFilesHash . 'test 2';
    }
}

Responsible rules

  • ChangeReadOnlyVariableWithDefaultValueToConstantRector

  • ChangeReadOnlyPropertyWithDefaultValueToConstantRector

  • TypedPropertyFromAssignsRector

Expected Behavior

It should only change type without changing to constant, as it will cause fatal error, see https://3v4l.org/Hk40Y

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions