The PHP Refactor Toolkit is a comprehensive script designed to streamline and automate the refactoring of PHP code. It leverages several powerful tools to ensure your code adheres to best practices and modern coding standards.
- RectorPHP: Automated code refactoring.
- Easy Coding Standard (ECS): Enforces coding standards.
- PHP CS Fixer: Fixes code to follow standards.
- Laravel Pint: Laravel-specific code formatting.
- PHP: Ensure you have PHP version 8.3 or higher installed. This toolkit is designed for modern coding practices and helps migrate old version syntaxes to new upgraded versions.
- Composer: Ensure Composer is installed for managing PHP dependencies.
- Zsh or Bash: This toolkit can be configured for either Zsh or Bash shell environments.
You can install the toolkit using the following command:
curl -sL https://github.com/SHSharkar/PHP-Refactor-Toolkit/raw/main/installer.sh | bashThis command will:
- Clone the repository to your home directory.
- Copy the necessary configuration files.
- Set up the script for global access.
If you prefer to install manually, follow these steps:
-
Clone the repository:
git clone https://github.com/SHSharkar/PHP-Refactor-Toolkit ~/php_refactor_toolkit -
Copy the configuration files:
cp ~/php_refactor_toolkit/rector.php ~/ cp ~/php_refactor_toolkit/.ecs.php ~/ cp ~/php_refactor_toolkit/.php-cs-fixer.php ~/ cp ~/php_refactor_toolkit/pint.json ~/
-
Set up the script:
mkdir -p ~/bin cp ~/php_refactor_toolkit/php_refactor_toolkit.sh ~/bin/php_refactor_toolkit chmod +x ~/bin/php_refactor_toolkit
-
Add
~/binto yourPATHin your shell configuration file (.zshrcor.bashrc):echo 'export PATH=$HOME/bin:$PATH' >> ~/.zshrc source ~/.zshrc
For Bash:
echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc source ~/.bashrc
Once installed, you can run the PHP Refactor Toolkit using the following command:
php_refactor_toolkitThe toolkit provides a user-friendly menu with the following options:
- Refactor a PHP file: Choose this option to refactor a single PHP file using one of the supported tools.
- Refactor all PHP files in a directory: This option allows you to refactor all PHP files within a specified directory.
- Quit: Exit the script.
After selecting a file or directory, you'll be prompted to choose a refactoring tool:
- RectorPHP: For automated code refactoring.
- Easy Coding Standard (ECS): To enforce coding standards.
- PHP CS Fixer: For fixing code style issues.
- Laravel Pint: For Laravel-specific formatting.
- Apply All: Apply all the above tools sequentially.
- Back to main menu: Return to the main menu to select a different option.
The toolkit will guide you through the refactoring process. If you choose to refactor another file or directory after completing a task, you can either continue with the same tool or return to the main menu to choose a different tool.
Verbose output, including diffs and applied changes, will be displayed to provide insight into what changes were made by each tool.
We welcome contributions and encourage you to report any issues or feature requests. Please visit the GitHub Issues page to report any bugs or request new features.
If you would like to contribute to the project, feel free to fork the repository, make your changes, and submit a pull request. We appreciate all contributions that help improve the PHP Refactor Toolkit.
This project is licensed under the MIT License. See the LICENSE file for more details.