Skip to content

Rector does not consistently propose to use promoted properties #9055

Closed
@theofidry

Description

@theofidry

Bug Report

Subject Details
Rector version Rector 2.0.10
PHP version   8.4.2

Issue

Rector is proposing the following change:

1) src/Bridge/Eloquent/Purger/ModelPurger.php:29

    ---------- begin diff ----------
@@ @@
     use IsAServiceTrait;

     private Migrator $migrator;
-    private string $migrationPath;
     private MigrationRepositoryInterface $repository;

-    public function __construct(MigrationRepositoryInterface $repository, string $migrationPath, Migrator $migrator)
+    public function __construct(MigrationRepositoryInterface $repository, private string $migrationPath, Migrator $migrator)
     {
         $this->migrator = $migrator;
-        $this->migrationPath = $migrationPath;
         $this->repository = $repository;
     }
    ----------- end diff -----------

Applied rules:
 * ClassPropertyAssignToConstructorPromotionRector

The rule applied ClassPropertyAssignToConstructorPromotionRector looks correct but for some reason it did not apply it to the parameters $repository and $migrator.

Reproducer

I could get this error in this PR theofidry/AliceDataFixtures#294 but to narrow down the issue I extracted theofidry/AliceDataFixtures#296.

Expected Behaviour

Rector should propose the following diff instead:

1) src/Bridge/Eloquent/Purger/ModelPurger.php:29

    ---------- begin diff ----------
@@ @@
     use IsAServiceTrait;

-     private Migrator $migrator;
-    private string $migrationPath;
-     private MigrationRepositoryInterface $repository;

-    public function __construct(MigrationRepositoryInterface $repository, string $migrationPath, Migrator $migrator)
+    public function __construct(private MigrationRepositoryInterface $repository, private string $migrationPath, private Migrator $migrator)
     {
-         $this->migrator = $migrator;
-        $this->migrationPath = $migrationPath;
-         $this->repository = $repository;
     }
    ----------- end diff -----------

Applied rules:
 * ClassPropertyAssignToConstructorPromotionRector

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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