MyCLabsMethodCallToEnumConstRector should only refactor according to RuleDefinition

Aperta
#9,956 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
php
Ambito
devtools

Direzione di ricerca

Start with the MyCLabsMethodCallToEnumConstRector rule class and its getRuleDefinition() CodeSample, which shows SomeEnum::VALUE()->getKey() becoming SomeEnum::VALUE->name. The report says the rewrite also fires where the enum constructor expects an enum object, causing a TypeError. Reproduce with the linked demo, then find which call sites the rule should skip. Done means the reported case produces no change and the rule's existing tests still pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Bug Report

Subject Details
Rector version 2.8.3

Hi,
the rule MyCLabsMethodCallToEnumConstRector should only refactor according to the rule definiton:

public function getRuleDefinition(): RuleDefinition
    {
        return new RuleDefinition('Refactor MyCLabs enum fetch to Enum const', [
            new CodeSample(
                <<<'CODE_SAMPLE'
$name = SomeEnum::VALUE()->getKey();
CODE_SAMPLE

                ,
                <<<'CODE_SAMPLE'
$name = SomeEnum::VALUE->name;
CODE_SAMPLE
            ),
        ]);
    }

Always changing SomeEnum::VALUE() to SomeEnum::VALUE can produce fatal errors like in the example:
Fatal error: Uncaught TypeError: test\A::__construct(): Argument #1 ($evl) must be of type Endroid\QrCode\ErrorCorrectionLevel, string given, called in

Best regards

Minimal PHP Code Causing Issue

https://getrector.com/demo/fd1ed71b-d792-4531-a52a-0679bce0c134

Expected Behaviour

No change

Lingua principale
PHP
Stelle
10.5k
Fork
742
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rectorphp/rector

Tutte le issue di rectorphp/rector

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.