Cool Tools: Useful tools to update the PHP version
Amburi Roy
Posted on August 14, 2023
Let's go straight to the point,
1) check-platform-reqs
composer check-platform-reqs
This command checks whether the PHP and extension versions correspond to the platform requirements of the installed packages. It can be used to confirm that a production server has all the necessary extensions to execute a project post-installation, for instance, successfully.
2) Rector - Instant Upgrades and Automated Refactoring
https://github.com/rectorphp/rector
Rector, a PHP tool, offers instant upgrades for your PHP code to the latest version, making a potentially daunting task manageable with minimal manual intervention. Automating refactorings in your code enhances code quality, elevates maintainability, and reduces technical debt. Furthermore, it enhances the code's type coverage, aiding in early bug detection and increased reliability. Additionally, Rector supports achieving the latest PHPStan level, a static analysis tool that identifies bugs and errors in your code. Rector assists in refining your code to meet PHPStan's latest requirements.
How to use:
- Install Rector
composer require rector/rector --dev
- Then create a
rector.php
in your root directory and modify it. - Update Rules: docs/rector_rules_overview.md
- Then dry run Rector:
vendor/bin/rector process src --dry-run
- Rector will show you a diff of files that it would change. To make the changes, drop
--dry-run
:vendor/bin/rector process src
3) PHP_CodeSniffer & PHP-compatibility
PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenises PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.
https://github.com/squizlabs/PHP_CodeSniffer
PHP-compatibility: This is a set of sniffs for PHP CodeSniffer that checks for PHP cross-version compatibility. It will allow you to analyse your code for compatibility with higher and lower versions of PHP.
https://github.com/PHPCompatibility/PHPCompatibility
How to use:
- Download
PHP_CodeSniffer
locally,
curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar
- Add these lines in
composer.json
{
"require-dev": {
"phpcompatibility/php-compatibility": "*",
"squizlabs/php_codesniffer": "*"
}
}
- Run Command,
composer update
- then, run the below command too,
php phpcs.phar -p <Target_Path> --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion <Target_PHP_Version>
Posted on August 14, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.