rectorphp/rector-doctrine

Refactor getReference adding $class parameter

aniltonjunior opened this issue · 0 comments

Hello, I'm trying to learn how to create my own Rules to address some changes in my project. However, I'm struggling to find material on how to access previous Nodes and obtain the type of an argument. For example, I would like to resolve deprecation warnings resulting from the use of getReference without the argument $class. In my case, I'm having difficulty obtaining the type of the parameter of the setter that expects the result of the getReference method.
I'm trying to achive a result like this:

         $causaPrescritiva = new CausaPrescritivaCredito();
-        $causaPrescritiva->setCredito($this->getReference('Credito-016'));
-        $causaPrescritiva->setTipoCausaPrescritiva($this->getReference('TipoCausaPrescritiva-SUSPENSÃO DA PRESCRIÇÃO POR DEFERIMENTO DE PARCELAMENTO'));
+        $causaPrescritiva->setCredito($this->getReference('Credito-016', Credito::class));
+        $causaPrescritiva->setTipoCausaPrescritiva($this->getReference('TipoCausaPrescritiva-SUSPENSÃO DA PRESCRIÇÃO POR DEFERIMENTO DE PARCELAMENTO', TipoCausaPrescritiva::class));
         $causaPrescritiva->setDataInicio(DateTime::createFromFormat('d/m/y H:i:s', '01/01/02 00:00:00'));
         $causaPrescritiva->setDataFim(DateTime::createFromFormat('d/m/y H:i:s', '01/01/05 00:00:00'));