Refactor codeigniter 3 #8881
-
|
Hi! I'm trying to refactor some codeigniter 3 code. I don't know the name of this pattern, but it uses an old school big global object with dynamic properties where all other controllers/models/libraries are loaded. So rector can't really know what type of class or class method is used in an object at $this->Test_model->some_method(). Can I still refactor with rector somehow? Can I manually tell rector that "$this->Test_model" is an object of type Test_model? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
Hi, could you share your rule so far? Via https://getrector.com/custom-rule/ |
Beta Was this translation helpful? Give feedback.
-
|
For legacy CodeIgniter 3 that lack of composer autoloading, that's not possible, unless you may need to set it via composer classmap definition: then run then using |
Beta Was this translation helpful? Give feedback.
-
|
I actually found a way to solve my issue. I leave it here if anyone else happens to have the same problem. It both makes rector work without making custom rules (atleast the things I have tried to do so far) and it makes the code work better in your editor (autocomplete, go to definition, etc). It is basically just a matter of adding all the dynamic properties as actual properties with the type declared.
|
Beta Was this translation helpful? Give feedback.
For legacy CodeIgniter 3 that lack of composer autoloading, that's not possible, unless you may need to set it via composer classmap definition:
then run
composer dump-autoloadthen using
\PHPStan\Reflection\ReflectionProviderto pull the class based onPropertyFetch->name