Rector has one main CLI command to process files. There are few less known, but useful commands that you might use in different situations:
Are you curious, how many rules are running in your project? Run:
You'll see list of all rules that are being run and skipped in your config.
vendor/bin/rector list-rules --config config/other-rector.php
Do you want to pipe result into next tool? Get it in JSON:
vendor/bin/rector list-rules --output-format json
Do you use Github Actions or Gitlab CI? Rector can generate a CI script for you:
It will generate
.gitlab-ci.yml file with Rector run that works for you. Fill you credentials and Rector will work for you on CI.
Do you want to create a custom rule? Rector can generate a basic structure for you:
Just fill your rule name and Rector generates a basic structure for you, including psr-4 paths in
composer.json. Don't forget to dump autoload, to enable the new psr-4 paths:
Following command comes handy when you want to write your custom rule. If you're new to the abstract syntax tree, it might take a while to understand what PHP code is represented by which node.
That's why Rector has a command to help you with that:
For input, write any valid PHP code - usually a short snippet that you want to change:
Write short PHP code snippet:
> echo "hey"
The command will return the AST nodes that represent the PHP code:
0: PhpParser\Node\Scalar\String_( value: "hey" )
Do you want to keep trying various PHP code samples and play around?
vendor/bin/rector detect-node --loop