Questions tagged [rector]

Rector is a tool that support upgrades and refactoring of your php-code.

Rector is a tool that supports upgrades and refactoring of your php-code.

See getrector.org/

30 questions
10
votes
1 answer

Rector how to avoid formatting source code?

When running a simple Rector rule NormalizeNamespaceByPSR4ComposerAutoloadFileSystemRector the source code will be completely formatted, line breaks and spaces that are used to beautify the source code are removed. How can this be avoided in…
powtac
  • 40,542
  • 28
  • 115
  • 170
5
votes
1 answer

CakePHP 3.10 -> 4.x Upgrade - Rector won't start

I am in the process of upgrading a site from CakePHP 3.10.0 to CakePHP 4.x using the 4.x Upgrade Guide. I have been successful up until the point where you need to run the following commands: bin/cake upgrade rector --rules phpunit80…
Arcane Feenix
  • 120
  • 1
  • 8
3
votes
4 answers

Configure Rector and using a simple Rule with symfony 6/php8

i want to use Rector for refactoring my code because i update my project to symfony 5.4 to 6.1. My php project version : 8.1.5 So, i want to use a simple rule who change my annotation to attribut with rector. but when i execute rector with command :…
Chlem
  • 97
  • 2
  • 10
3
votes
2 answers

How to move from phpexcel to phpspreadsheet

I used to use phpexcel, but I want to move to phpspreadsheet. I tried to hit the command based on the following site, but it doesn't work. Did I make a mistake? I'm also using a container named phpexcel in my code, is this still…
scottie320
  • 153
  • 1
  • 26
3
votes
1 answer

CakePHP: upgrade from 3.9.x to 4.0: bin/cake upgrade rector --rules phpunit80 Hangs

I'm upgrading a CakePHP 3 app to CakePHP 4, and following the Upgrade Guide. However, the bin/cake upgrade rector --rules phpunit80 tool hangs. A little background, my app was made mostly in CakePHP 3.6. I upgraded it to 3.7,…
dividedbyzero
  • 181
  • 2
  • 13
2
votes
1 answer

What does TREAT_AS_NON_EMPTY do?

The tool rector has a configuration option for certain rules called TREAT_AS_NON_EMPTY. For example, https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#disallowedemptyrulefixerrector What does this configuration actually do?
Dharman
  • 30,962
  • 25
  • 85
  • 135
2
votes
2 answers

Rector not finding anything to change (Converting Doctrine annotations to attributes)

As Doctrine seems to have completely removed annotations support in their latest updates, I am trying to convert the annotations in my entities to attributes using Rector. I followed the (seemingly) simple official tutorial - I have the exact same…
Peter suib
  • 108
  • 2
  • 10
1
vote
0 answers

Rector php rule to fix undefined array key index

I am migrating from PHP version 7.4 to 8.2. Part of this upgrade is some notices are now warning. The project was set to ignore all the notices but warnings. Now after upgrading there are thousands of "undefined array key" warnings. I know how to…
Chirag Kalani
  • 368
  • 2
  • 9
1
vote
2 answers

When to use PHP self::class? When to use __CLASS__?

Preamble I'm working on a legacy Open Source project supporting PHP 5.5 to PHP 8.3. Question My question is simple: When to use PHP self::class? When to use __CLASS__? Does it may change from PHP version to version? (at least interested after PHP…
Valerio Bozz
  • 1,176
  • 16
  • 32
1
vote
1 answer

Rector Failed to create "/tmp/rector_cached_files/26": mkdir(): Permission denied

When I run the command: vendor/bin/rector process --dry-run I get the error: [ERROR] Failed to create "/tmp/rector_cached_files/26": mkdir(): Permission denied Web server processes on this system currently run as the user. If I run the script as…
1
vote
1 answer

rector: how to return a define using a $_SERVER element?

I want to change define('USER','pippo'); with define('USER', $_SERVER["DB_USER"]); I am not able to create a new FuncCall with a string as first argument and a array element from "DB_USER" index of $_SERVER ... Also, I was trying to workaround the…
realtebo
  • 23,922
  • 37
  • 112
  • 189
1
vote
0 answers

Don't import classes on specific path in rectorphp/rector

I have a rector setup for upgrading to laravel9 and php8.1, and it works good. My question is, how to set up the config so that it imports the classes everywhere, but not in config/app.php? return static function (RectorConfig $rectorConfig): void…
hdomos
  • 1,169
  • 16
  • 24
1
vote
2 answers

PHP Rector combine path and skip

I have a PHP Symfony project with much vendor and other sub dir files which should not bee touched by rector. So I setup the path variable to only check files within a specific folder tree. That works fine. return static function (RectorConfig…
dnaumann
  • 444
  • 3
  • 13
1
vote
0 answers

Upgrading plugin to CakePHP4, Rector gives Class not found error

Even though I think I specified the right AUTOLOAD_PATHS to rector.php, I keep getting the same error: Class Bake\View\Helper not found. I'm attempting to convert a CakePHP 3.10.1 plugin to CakePHP 4.0. $ bin/cake upgrade rector --rules cakephp40…
TechFanDan
  • 3,329
  • 6
  • 46
  • 89
1
vote
0 answers

Refactor create_function() to an anonymous function using RectorPHP

For php 7.2 compatibility, I need to refactor the following create_function() to an anonymous function: function bbpp_thankmelater_shortcode_h($atts, $content = NULL) { extract(Bbpp_ThankMeLater_Shortcoder::atts(array( "email_type" =>…
Evos
  • 11
  • 3
1
2