These are my personal phpcs standards, a collection of sniffs and rulesets from others, and some I've written myself (because, why not?).
This repo contains both my own work, and the works of Squiz Labs and Slevomat, and uses phpcs Sniffs written by multiple other parties.
Repositories for sniffs not included in the default set provided by Squiz Labs:
Before running the install or update scripts, make sure:
- you can clone git objects via the command line with
git clone
which phpcs
should return a path if you have previously installedphpcs
(if you have not installedphpcs
already, the install script will install it globally for you.)- you have a global installation of composer
All you should need to get started is the install script; simply
- Clone the Repo
- cd into the directory
- (optional)
cat install.sh
-- check the source code, make sure it's safe! chmod +x ./install.sh
- run
./install
- (optional) run
./update
to update! (re-clones the repos and re-installs sniffs)
If the above doesn't work for you, or if you have phpcs
installed but which phpcs
returns a blank string, try the below.
- find your desired installation of phpcs. If you already have it installed, find where the bin file symlinks to - this is the install directory.
- in the installation directory, find the
Standards
folder undersrc
- for my global composer install, it's under~/.composer/vendor/squizlabs/php_codesniffer/src/Standards
. - Clone each of repos listed in the preface above (slevomat/coding-standard, hostnet/phpcs-tool, sirbrillig/variable-analysis) and find the folder that contains a folder called
Sniffs
. Unless the repos have changed since I've wrote this, this folder should be the top namespace for the project (ie.SlevomatCodingStandard
,Hostnet
andVariableAnalysis
) and should either be in the root of the project or under a src folder. - copy the folders containing
Sniffs
for each repo into thesquizlabs/php_codesniffer/src/Standards
folder (ie. copySlevomatCodingStandard
,Hostnet
andVariableAnalysis
). - finally, copy this repo's ruleset and sniffs (the entire
XpBar
folder) tosquizlabs/php_codesniffer/src/Standards
.
- update your editor config to point to your global phpcs installation -
which phpcs
and to use theXpBar
standard as the default - (optional) run
phpcs --config-set warning_severity 3
to include warnings about return types, which I've marked with a lower priority until I move them into their own sniffs
You can find the accompanying zsh functions, koolaid
, here