Download the PHP package suilven/php-travis-enhancer without Composer
On this page you can find all versions of the php package suilven/php-travis-enhancer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download suilven/php-travis-enhancer
More information about suilven/php-travis-enhancer
Files in suilven/php-travis-enhancer
Package php-travis-enhancer
Short Description Add code quality tools for PHP analysis, and search for code duplication
License MIT
Informations about the package php-travis-enhancer
PHP Travis Enhancer
Add stricter PHPStan and PHPCS coding standard checks, linting, Psalm standards checking, and detection of code duplication to your PHP projects.
Usage
Introduction
The goal of this package is to add strict coding checks to your PHP packages. I'd added these tasks manuallly to a couple of modules manually, and decided it was time to automate this as far as possible. Hence the existence of this package.
Any or all of the following coding checks can be added:
- lint - simply parses your PHP code looking for syntax errors, the build will break if there are some
- phpcs - checks PHP code against a subsection of the Slevomat coding standards. Some of the checks oppose each other,
I have commented those out in
ruleset.xml
that break code fixing. Automated fixes can then be achieved usingcomposer fixcs
, but some kinds of fixes can only be done manually. - phpstan - run PHPStan, a static PHP analysis tool, over your codebase. I have set the level to a fairly strict value of 6, you may wish to manually change this
- psalm - run Psalm, an alternative static analysis checker. Note this is somewhat strict regarding PHPDoc, which hey is a good thing.
- duplication - this is provided as an extra check for Travis, the build will fail if swathes of duplicate code is found.
Warning!!
Note that this module alters your codebase, as such run this on a backed up source tree, preerably in a separate branch from master so that a pull request can later be submitted.
The following files are altered
travis.yml
- additional code quality checks added to the matrix, install and running stepscomposer.json
- packages required for code checking, scripts to run code checksruleset.xml
- Based on PSR2 but with the addition of the Slevomat coding standardstests/phpstan.neon
- basic config file for phpstan to autoload files
Adding Code Checking Tools
Installation
Adding All Checks
This will take several minutes to run. If identical flags already exist, ditto coomposer script names, then these are
left as is in .travis.yml
and composer.json
respecctively.
Adding Individual Checks
Checks can be added indiviually if so desired.
Note that the script checkCode
in the altered composer file will only include the individual command installed.
Removal
This module is one shot, as such remove it after being used
Checking Code Locally
If the checks were installed using all
then composer checkCode
will run through the code checks. It is an alias for
If any one of these fail it will exit immediately.
What Does a Run Look Like?
This is snipped but hopefully enough to provide context. Here I am testing on an old small SilverStripe module.
Automatically Fixing Errors
Those errors marked above with an X
can be automatically fixed.
Run Code Check After Automatic Fixing
These errors need fixed manually
Afterthoughts
I've had a go at applying this to a reasonably large codebase (Manticore PHP Search Client) and gave up due to the sheer volume of errors. As such I am uing this with new projects (including this one), and retrofixing old small projects.
License
- MIT license
- Copyright 2020 © Gordon Anderson.
All versions of php-travis-enhancer with dependencies
league/climate Version ^3.5
splitbrain/php-cli Version ^1.1