Skip to content

rhowardiv/phpcs-standard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 

Repository files navigation

These are files that can be used to check your PHP code using PHP
CodeSniffer.  Code will be checked for coding standards, formatting,
PHPDoc blocks, silly mistakes and more.

Developed under phpcs version 1.3.3.
Seems fine so far also under 1.3.4.

Installation
------------

Clone this repo in a directory named "Snap" under the "Standards" folder
of your phpcs installation. Change the default standard for phpcs to
"Snap" by either editing CodeSniffer.conf directly or running the
command:

phpcs --config-set default_standard Snap

Editor integration
------------------

VIM

Add to your .vimrc:

function! RunPhpcs()
	let l:filename=@%
	let l:phpcs_output=system('phpcs --report=csv '.l:filename)
	let l:phpcs_list=split(l:phpcs_output, "\n")
	unlet l:phpcs_list[0]
	cexpr l:phpcs_list
	cwindow
endfunction
set errorformat+=\"%f\"\\,%l\\,%c\\,%t%*[a-zA-Z]\\,\"%m\"\\,%*[a-zA-Z0-9_.-]\\,%*[0-9]
command! Phpcs execute RunPhpcs()
nmap <Leader>sn :call RunPhpcs()<cr>

This will allow you to run phpcs with the results in a Quickfix list by
entering the command :Phpcs or \sn (mnemonic: sniff).

Alternatively you can try the Vim Syntastic plugin which will use phpcs
automatically if it's in your PATH.

Some notes about working in these files
---------------------------------------

Anyone wanting to update this PHPCS standard could probably use some starting
advice:

PHPCS operates by tokenizing the file in question then going through every
token and calling the "Sniffs" that are registered to listen for that token.

PHPCS comes with many standards (including Generic, PEAR, Squiz and Zend). Any
run of PHPCS follows exactly one standard.

You configure which standard you want to run in CodeSniffer.conf in the root
directory of the PHPCS installation.

All the Sniffs in the standard you select will be run. The Standard has a
ruleset.xml file in its top directory that can include Sniffs from other
Standards.

This repository is the Snap standard. It includes customized Sniffs that it
considers its own, copied originally from the Generic, Squiz and PEAR
standards, and also pulls in sniffs from Generic, Squiz and Zend via its
ruleset.xml file.

About

Snap-Interactive code standard files for PHP CodeSniffer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages