Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging a custom Rector with xDebug and PHPStorm #3667

Closed
oceanicpanda opened this issue Jul 7, 2020 · 12 comments
Closed

Debugging a custom Rector with xDebug and PHPStorm #3667

oceanicpanda opened this issue Jul 7, 2020 · 12 comments

Comments

@oceanicpanda
Copy link

Hello,

I'm at a bit of a loss, how does one go about debugging a custom Rector, I've searched all over and can't find a guide that points me in the right direction?

Thanks!

@TomasVotruba
Copy link
Member

Hi,

good question. I thought we have it in README, but we don't. I've added it:
https://github.com/rectorphp/rector#debugging

@oceanicpanda
Copy link
Author

Thanks for the super fast reponse, that was 1 step forward! now I just need to figure out why I'm seeing:

Fatal error: Uncaught TypeError: realpath() expects parameter 1 to be a valid path, null given in phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php on line 209

@TomasVotruba
Copy link
Member

That's hard to tell just from this 1 line. What happens when you actually add the --debug option I linked?

We might need a reproducible repository for this.

@oceanicpanda
Copy link
Author

include/vendor/bin/rector process include/custom/reports.inc --config rector.yaml --dry-run --set code-quality --xdebug
Rector v0.7.46
Config file: rector.yaml

PHP Fatal error: Uncaught TypeError: realpath() expects parameter 1 to be a valid path, null given in phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php:209
Stack trace:
#0 phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php(209): realpath()
#1 phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php(174): _HumbugBox0cb1dfcaf397\Nette\Loaders\RobotLoader->createFileIterator()
#2 phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php(372): _HumbugBox0cb1dfcaf397\Nette\Loaders\RobotLoader->refreshClasses()
#3 phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/nette/robot-loader/src/RobotLoader/Robo in phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php on line 209

Fatal error: Uncaught TypeError: realpath() expects parameter 1 to be a valid path, null given in phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php on line 209

TypeError: realpath() expects parameter 1 to be a valid path, null given in phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php on line 209

Call Stack:
0.0078 401088 1. {main}() /media/app/include/vendor/rector/rector-prefixed/rector:0
0.0630 4638456 2. require('phar:///media/app/include/vendor/rector/rector-prefixed/rector/bin/rector') /media/app/include/vendor/rector/rector-prefixed/rector:6
11.1984 45892640 3. Rector\Core\Console\Application->run() phar:///media/app/include/vendor/rector/rector-prefixed/rector/bin/rector:48
11.1987 45897128 4. Rector\Core\Console\Application->doRun() phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/symfony/console/Application.php:136
11.1992 45906448 5. Rector\Core\Console\Application->doRun() phar:///media/app/include/vendor/rector/rector-prefixed/rector/src/Console/Application.php:83
11.1999 45925128 6. Rector\Core\Console\Application->doRunCommand() phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/symfony/console/Application.php:235
11.1999 45925128 7. Rector\Core\Console\Command\ProcessCommand->run() phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/symfony/console/Application.php:848
11.1999 45925128 8. Rector\Core\Console\Command\ProcessCommand->run() phar:///media/app/include/vendor/rector/rector-prefixed/rector/src/Console/Command/AbstractCommand.php:30
11.2001 45928048 9. Rector\Core\Console\Command\ProcessCommand->execute() phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/symfony/console/Command/Command.php:228
11.2044 46170192 10. Rector\Core\Autoloading\AdditionalAutoloader->autoloadWithInputAndSource() phar:///media/app/include/vendor/rector/rector-prefixed/rector/src/Console/Command/ProcessCommand.php:133
11.2047 46170872 11. Rector\Core\Autoloading\AdditionalAutoloader->autoloadDirectories() phar:///media/app/include/vendor/rector/rector-prefixed/rector/src/Autoloading/AdditionalAutoloader.php:51
11.2051 46243696 12. _HumbugBox0cb1dfcaf397\Nette\Loaders\RobotLoader->register() phar:///media/app/include/vendor/rector/rector-prefixed/rector/src/Autoloading/AdditionalAutoloader.php:92
11.2051 46243696 13. _HumbugBox0cb1dfcaf397\Nette\Loaders\RobotLoader->loadCache() phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php:58
11.2052 46244312 14. _HumbugBox0cb1dfcaf397\Nette\Loaders\RobotLoader->refreshClasses() phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php:372
11.2052 46244288 15. _HumbugBox0cb1dfcaf397\Nette\Loaders\RobotLoader->createFileIterator() phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php:174
11.2057 46245160 16. realpath() phar:///media/app/include/vendor/rector/rector-prefixed/rector/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php:209

Variables in local scope (#15):
$acceptFiles = uninitialized
$dir = '.'
$disallow = array ('/media/app/include/cache' => TRUE, '/media/app/include/jpgraph' => TRUE, '/media/app/include/vendor' => TRUE, '/media/app/include/tcpdf' => TRUE, '/media/app/build' => TRUE, '/media/app/tests' => TRUE)
$filter = uninitialized
$ignoreDirs = array (0 => '.', 1 => '.old', 2 => '.bak', 3 => '.tmp', 4 => 'temp', 5 => '*Fixtures', 6 => 'include/cache', 7 => 'include/jpgraph', 8 => 'include/vendor', 9 => 'include/tcpdf', 10 => 'build', 11 => 'tests', 12 => NULL)
$item = NULL
$iterator = uninitialized

@TomasVotruba
Copy link
Member

Thanks. Nothing obivous so far.

What's in your rector.yaml? If you remove any specifici line, does the output change?

Do you have PHPStan? If so and if you remove phpstan.neon, does it change in any way?

@oceanicpanda
Copy link
Author

oceanicpanda commented Jul 7, 2020

rector.yaml:

parameters:
php_version_features: '7.2'
auto_import_names: true
level: 'phpunit80'
file_extensions:
- 'php'
- 'inc'
autoload_paths:
- 'include/vendor/autoload.php'
- 'htdocs/scripts/autofilter.php'
- 'htdocs/prepend.inc'
- '.'
- 'include'
exclude_paths:
- 'include/cache'
- 'include/jpgraph'
- 'include/vendor'
- 'include/tcpdf'
- 'build'
- 'tests'
services:
SRector\TableRefreshColumn: ~

@oceanicpanda
Copy link
Author

phpstan.neon:

parameters:
fileExtensions:
- php
- inc
autoload_directories:
- '.'
autoload_files:
- 'include/autoloader.inc'
- 'include/vendor/autoload.php'
- 'include/autoloader.inc'
- 'htdocs/prepend.inc'
excludes_analyse:
- 'include/cache'
- 'include/jpgraph'
- 'include/st/custom'
- 'include/tcpdf'
- 'include/vendor'
- 'tests'
- 'build'

@oceanicpanda
Copy link
Author

oceanicpanda commented Jul 7, 2020

I've tried removing everything I think, none of which seems to have an effect.

Now that I look I have the phpstan.neon file but no mention of it in my composer.json

... Well that didn't change anything

@TomasVotruba
Copy link
Member

TomasVotruba commented Jul 7, 2020

That's unfortuntate 😢

In that case we need minimal reproductible repository in Github. That we can install & run locally and see the same error.

@oceanicpanda
Copy link
Author

OK I'll get something set up

@oceanicpanda
Copy link
Author

Oh my word.... so I just realised that under exclude_paths in rector.yaml I had one extra "-" which then didn't have an option to it:

  • 'include/vendor'
  • 'tests'
  • 'build'

Many thanks for your help!

@TomasVotruba
Copy link
Member

Great job! 👍

I recommend using higlight code here in github

key: value

image

It also sometimes lints the syntax, so you discover such bugs faster :)

TomasVotruba added a commit that referenced this issue Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants