spaceemotion / php-coding-standard
Combines multiple code quality tools into one binary with unified output.
Installs: 112 175
Dependents: 6
Suggesters: 0
Security: 0
Stars: 18
Watchers: 3
Forks: 6
Open Issues: 5
Requires
- php: ^7.1 || ^8.0
- ext-json: *
- composer/xdebug-handler: ^1.0
Requires (Dev)
- brainmaestro/composer-git-hooks: ^2.8
- ergebnis/composer-normalize: ^2.4
- phan/phan: 3.x
- php-parallel-lint/php-parallel-lint: ^1.2
- phpmd/phpmd: ^2.8
- phpstan/phpstan: ^0.12
- phpstan/phpstan-deprecation-rules: ^0.12
- phpstan/phpstan-strict-rules: ^0.12
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.15.0
- squizlabs/php_codesniffer: ^3.5
- symplify/easy-coding-standard-prefixed: ^9
- vimeo/psalm: ^4.3
Suggests
- ergebnis/composer-normalize: Normalizes composer.json files
- phan/phan: Static analysis (needs php-ast extension)
- php-parallel-lint/php-parallel-lint: Quickly lints the whole codebase for PHP errors
- phpmd/phpmd: Code mess detection
- phpstan/phpstan: Static analysis
- psalm/phar: Static analysis (.phar)
- squizlabs/php_codesniffer: Code style linter + fixer
- symplify/easy-coding-standard: Code style linter + fixer
- symplify/easy-coding-standard-prefixed: Code style linter + fixer (.phar)
- vimeo/psalm: Static analysis
This package is auto-updated.
Last update: 2024-10-31 00:23:24 UTC
README
php-coding-standard (phpcstd)
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 output- In your projects, you depend on a single repository (e.g.
acme/coding-standard
) which depends onphpcstd
and includes the various base configurations (e.g. phpmd.xml, ecs.yaml, ...). Your own projects then depend on your own coding standard.
phpcstd
itself does not come with any tools preinstalled.
You can take a look at my own coding standards as an example.
Tools supported
⭐ = recommended
Getting started
composer require-dev spaceemotion/php-coding-standard
This will install the phpcstd
binary to your vendor folder.
Configuration via .phpcstd(.dist).ini
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).
Command options
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
Git Hooks
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
CI-Support
Github Actions
The --ci
flag returns a format that can be used by GithubActions to annotate commits and PRs
(see their documentation on how this works).
Development
Using Docker
- Spin up the container using
GITHUB_PERSONAL_ACCESS_TOKEN=<token> docker-compose up -d --build
- Run all commands using
docker-compose exec php <command here>
Using XDebug
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).