This is a simple plugin to run phpcs by plugin. If there is any interest, perhaps this could be expanded to apply some fixes based on the text phpcs returns.
[code]import sublime, sublimeplugin
phpcs.py
This is a terribly simple plugin. Running it will call PHP Codesniffer
and validate your PHP code against the Codesniffer’s version of the
Zend Standards. Output will be shown in the console.
TODO: It should, in theory, be possible to automatically correct certain
errors by parsing the resulting text from phpcs and applying basic
string replacements on the correct lines- for example converting
56 | ERROR | Opening brace should be on a new line
to a regex on line 56 to turn …){… to …) {…
See http://pear.php.net/package/PHP_CodeSniffer/
class PhpcsCommand(sublimeplugin.TextCommand):
def run(self, view, args):
view.window().runCommand(“save”)
cmd = “phpcs --standard=Zend " + view.fileName()
view.window().runCommand(“exec”,”",cmd])[/code]
Also, I happen to prefer having this bound to F8 as such:
<binding key="f8" command="phpcs" />
Another point of improvement could be to add parameters/ multiple bindings to allow users to validate against multiple standards they may have installed.