Combines various code quality tools into a single command with shared output for easier CI integration
phpcstd
combines various code quality tools (e.g. linting and static analysis)
into one, easy to use package which can be shared across teams and code bases.
There are two parts to this:
phpcstd
executes all the enabled tools and returns a single per-file error outputacme/coding-standard
)phpcstd
and includes the various base configurationsphpcstd
itself does not come with any tools preinstalled.
You can take a look at my own coding standards as an example.
Tool | Lint | Fix | Source list | Description |
---|---|---|---|---|
⭐ EasyCodingStandard | ✅ | ✅ | ✅ | Combination of PHP_CodeSniffer and PHP-CS-Fixer |
PHP Mess Detector | ✅ | ❌ | ✅ | Code complexity checker |
PHP_CodeSniffer | ✅ | ✅ | ✅ | Style linter + fixer |
⭐ composer-normalize | ✅ | ✅ | ✅ | Validates and rearranges composer.json files |
phan | ✅ | ✅ | ❌ | Static analyzer, requires the “php-ast” extension |
⭐ php-parallel-lint | ✅ | ❌ | ✅ | Checks for PHP (syntax) errors (using php -l ) |
⭐ phpstan | ✅ | ❌ | ⏹ | Static analyzer, source list is optional, but not recommended |
psalm | ✅ | ✅ | ✅ | Static analyzer |
⭐ rector | ✅ | ✅ | ✅ | Code up-/downgrading and refactoring tool |
deptrac | ✅ | ❌ | ❌ | Static analyzer that enforces rules for dependencies between software layers |
⭐ = recommended
composer require-dev spaceemotion/php-coding-standard
This will install the phpcstd
binary to your vendor folder.
To minimize dependencies, phpcstd
uses .ini-files for its configuration.
If no .phpcstd.ini
file can be found in your project folder,
a .phpcstd.dist.ini
file will be used as fallback (if possible).
Usage:
run [options] [--] [<files>...]
Arguments:
files List of files to parse instead of the configured sources
Options:
-s, --skip=SKIP Disables the list of tools during the run (comma-separated list) (multiple values allowed)
-o, --only=ONLY Only executes the list of tools during the run (comma-separated list) (multiple values allowed)
--continue Run the next check even if the previous one failed
--fix Try to fix any linting errors
--hide-source Hides the "source" lines from console output
--lint-staged Uses "git diff" to determine staged files to lint
--ci Changes the output format to GithubActions for better CI integration
--no-fail Only returns with exit code 0, regardless of any errors/warnings
-h, --help Display help for the given command. When no command is given display help for the run command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Instead of defining the files/folders directly (in either the config or as arguments), you can also pipe a list into it:
$ ls -A1 | vendor/bin/phpcstd
To not have to wait for CI pipelines to finish, you can use git hooks to run over the changed files before committing.
vendor/bin/phpcstd --lint-staged
The --ci
flag returns a format that can be used by GithubActions to annotate commits and PRs
(see their documentation on how this works).
GITHUB_PERSONAL_ACCESS_TOKEN=<token> docker-compose up -d --build
docker-compose exec php <command here>
This project uses composer/xdebug-handler to improve performance
by disabling xdebug upon startup. To enable XDebug during development you need to set the following env variable:
PHPCSTD_ALLOW_XDEBUG=1
(as written in their README).