Skip to content

Commit

Permalink
Rector (#5)
Browse files Browse the repository at this point in the history
feat: Rector
  • Loading branch information
leocavalcante authored Jan 26, 2024
1 parent d254560 commit 788e59b
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ install:
@sudo ln -sf $(shell pwd)/bin/pint /usr/local/bin/pint
@sudo ln -sf $(shell pwd)/bin/exakat /usr/local/bin/exakat
@sudo ln -sf $(shell pwd)/bin/frankenphp /usr/local/bin/frankenphp
@sudo ln -sf $(shell pwd)/bin/rector /usr/local/bin/rector
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ phpctl sh echo 'Hello, World!' # To run arbitrary sh commands inside the contain
| `box` | Runs [Box](https://github.com/box-project/box). |
| `exakat` | Runs [Exakat](https://www.exakat.io) |
| `frankenphp` | Runs [FrankenPHP](https://frankenphp.dev) |
| `rector` | Runs [Rector](https://getrector.com) |

### Scaffolders
| Command | Description |
Expand Down
2 changes: 2 additions & 0 deletions bin/rector
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
phpctl rector $@
1 change: 1 addition & 0 deletions examples/rector/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
36 changes: 36 additions & 0 deletions examples/rector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Rector

This is an example of how to use Rector to refactor your code.

Run `phpctl rector -n` (yes, with the `-n` flag) to see what Rector would do.

You should be seeing something like:
```shell
➜ rector git:(feat/rector) ✗ phpctl rector -n
Running opencodeco/phpctl:php82
1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
1 file with changes
===================

1) src/example.php:0

---------- begin diff ----------
@@ @@
<?php

-$arr = array();
+$arr = [];
----------- end diff -----------

Applied rules:
* LongArrayToShortArrayRector



[OK] 1 file would have changed (dry-run) by Rector



```

Where Rector attempts to change the code from using `array()` to `[]`.
5 changes: 5 additions & 0 deletions examples/rector/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require-dev": {
"rector/rector": "^0.19.2"
}
}
137 changes: 137 additions & 0 deletions examples/rector/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions examples/rector/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_82
]);
};
3 changes: 3 additions & 0 deletions examples/rector/src/example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$arr = array();
2 changes: 2 additions & 0 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ symlink() {
sudo ln -sf "${INSTALL_DIR}/bin/pint" /usr/local/bin/pint
sudo ln -sf "${INSTALL_DIR}/bin/exakat" /usr/local/bin/exakat
sudo ln -sf "${INSTALL_DIR}/bin/frankenphp" /usr/local/bin/frankenphp
sudo ln -sf "${INSTALL_DIR}/bin/rector" /usr/local/bin/rector
}

echo "\033[0;33mInstalling phpctl at \033[0m$INSTALL_DIR"
Expand Down Expand Up @@ -45,5 +46,6 @@ else
echo " sudo ln -sf ${INSTALL_DIR}/bin/pint /usr/local/bin/pint"
echo " sudo ln -sf ${INSTALL_DIR}/bin/exakat /usr/local/bin/exakat"
echo " sudo ln -sf ${INSTALL_DIR}/bin/frankenphp /usr/local/bin/frankenphp"
echo " sudo ln -sf ${INSTALL_DIR}/bin/rector /usr/local/bin/rector"
echo ""
fi
1 change: 1 addition & 0 deletions src/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ help() {
echo -e "\033[0;32m box \033[0m Runs Box (PHAR builder)"
echo -e "\033[0;32m exakat \033[0m Runs Exakat"
echo -e "\033[0;32m frankenphp \033[0m Runs FrankenPHP"
echo -e "\033[0;32m rector \033[0m Runs Rector"
echo -e ""
}
4 changes: 4 additions & 0 deletions src/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ pint() {
run -- pint ${@}
fi;
}

rector() {
run -- vendor/bin/rector ${@}
}

0 comments on commit 788e59b

Please sign in to comment.