In my projects I apply the PSR-2 code styling rules and I use Codesniffer to check my code through Continues Integration.
I use PhpStrorm to write my code and PhpStorm has a functionality to reformat the code before commiting or while writing your code in order to minimize the errors.
But I have a problem with the following rule:
PSR2.Classes.ClassDeclaration.CloseBraceAfterBody
Let's say that I have the following class:
<?php
namespace MyNamespace;
class MyClass
{
public $myVar1;
public $myVar2;
/**
* @var string
*/
public $myVar;
/**
* This is a test function
*/
public function myFunction()
{
...
}
}
When I commit my code and the Continuous Integration runs then I get the following error:
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
183 | ERROR | [x] The closing brace for the class must go on the next
| | line after the body
| | (PSR2.Classes.ClassDeclaration.CloseBraceAfterBody)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
The problem is the empty line between the closing brace of the class and the closing brace of the function.
If on CodeStyle Settings of PhpStrom on tab Blank Lines I set In declarations = 0
the last empty line of the class will be removed but then the empty line between the DocBlock of $myVar and $myVar2 will be removed also but if I set the Around Field = 1
then the empty lines between the DocBlock and the var will stay there.But again I am not getting what I need because there will be an empty line between $myVar1 and $myVar2.
I haven't found a way for PhpStorm to get the desirable result.
Does anyone know if there is a way?