How to reformat PHP files so they end with a blank line to comply with PSR-2?

I am using Checkstyle to go through my project's code to comply with PSR-2[1]. PHPStorm's Reformat feature does a very good job of formatting PHP files so that they comply with the new standard but one thing it does not appear to do is insert a blank line at the end of a pure PHP file. You can find this requirement defined in PSR-2 Section 2.2 "All PHP files MUST end with a single blank line".

I have found this feature: File | Settings | IDE Settings | Editor | Ensure blank line before end of file on Save[2]. I have not yet tried it (though will begin trying it immediately) but from what I can tell it does not solve the problem of going through all my existing code and inserting a blank line at the end of all pure PHP files.

Does anyone know of a way to implemet this?

Thank you in advance.

[1] https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md

[2] http://www.jetbrains.com/phpstorm/webhelp/editor.html

4 comments
Comment actions Permalink

Jarrett,
currently reformatter doesn't handle spacing at the end of a file thus there is no way to force it to do so. You can make a feature request for that in YouTrack

0
Comment actions Permalink

Hi Rustam,

Thanks for the reply. Yes I might fill out a feature request.

Perhaps even better, maybe an extension can be built for the PHP Coding Standards Fixer by Sensio Labs.

0
Comment actions Permalink

OK. I will take care of the formatter extension.

0
Comment actions Permalink

Cool Rustam, I think you will find it'll be a popular extension. I look forward to using it.

Jarrett

0

Please sign in to leave a comment.