PSR Formatter


Hi, I’m looking for a way that I can Lint and Format my PHP code to meet PSR standards. Have we anything like this available?


As long as there are tools that can format STDIN and print it to STDOUT, you can add your own formatter in Komodo IDE. Creating a custom linter is much harder though, and there’s no such a thing for PHP in Komodo. (something like pep8 for Python).


Is there a PSR linter out there that is mature and popular?


I’m not aware of such. Maybe something has changed in the PHP world and they introduced some sort of a linter though.


This feature exist for PHPStorm. With it, one can easy format code to psr2. PHPStorm has formatters for many other languages as well… most of which is installed by default but not for some standard such as PSR which has to be enabled by the user. This would be a very powerful feature to include in KomodoIDE in order to help ensure clean looking code.


I assume because PHPStorm is for… PHP, uh. Komodo relies on open-source utils (like htmltidy for HTML or GoFmt for Golang) for formatting needs because of its wide range of supported languages. If PHPStorm is using a 3rd-party program to format php code according to PSR standards, then you are able to add this formatter to Komodo as long as it can take SDTIN to format the code and output it to STDOUT.
More over, if the program is under a license that allows to integrate it in paid software, it could become a built-in one.

I’m not aware of any open-source PHP formatting tools, if you know any I’d be happy to help configure it in Komodo :slight_smile:

Creating a linter though would require creating a new language for Komodo (something like PHP-PSR) or modifying the built-in one.

I think you can configure this thing for your formatting needs:

I heard that PHPUnit could do formatting, too.

No support for php formatting?

This is what i use with Komodo Edit.


And PHP installed locally :wink:

Now from the toolbox add four new user scripts (js) and set your paths :wink:

    if (komodo.view) { komodo.view.setFocus(); }, ‘php /YOUR_PATH/phpcpd.phar %F’);

  2. PHPMD - custom rulset used!
    if (komodo.view) { komodo.view.setFocus(); }, ‘php /YOUR_PATH/phpmd.phar %F text /YOUR_PATH/ruleset.xml {‘parseRegex’: u’^(?P.):(?P\\d+)(?P)\\t(?P.)’, ‘showParsedOutputList’: True, ‘cwd’: u’%D’, ‘parseOutput’: True}’);

  3. PHP-PSR2
    if (komodo.view) { komodo.view.setFocus(); }, ‘php /YOUR_PATH/phpcs.phar --standard=PSR2 --report=emacs --report-width=10000 %F {‘parseRegex’: u’^(?P.):(?P\\d+):(?P\\d+):(?P.)’, ‘showParsedOutputList’: True, ‘cwd’: u’%D’, ‘parseOutput’: True}’);

    if (komodo.view) { komodo.view.setFocus(); }, ‘php /YOUR_PATH/phpcbf.phar --standard=PSR2 %F’);

Note that you have to save your file first - maybe there is a way to execute those scripts on temporary file :wink:

Have Fun :wink:

No support for php formatting?
No support for php formatting?