1

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?

gmponos
  • 2,157
  • 4
  • 22
  • 33
  • If you remove that empty line manually -- will IDE add it again? For me it just stays as is -- it does not remove it but does add either. – LazyOne Nov 23 '16 at 18:27
  • No it doesn't add it back again. But it would be sweet if it could be removed automatically. – gmponos Nov 23 '16 at 18:29
  • *I guess* the best would be to just a submit new Feature Request ticket to their [Issue Tracker](https://youtrack.jetbrains.com/issues/WI). With my search I've only found [WI-22052](https://youtrack.jetbrains.com/issue/WI-22052) which is not about your case .. but one of the comments matches it .. and it's suggested there to adjust one particular setting .. but it does not do anything (I have that particular one set to `0` already) – LazyOne Nov 23 '16 at 18:42
  • On related note: you might be interested in https://youtrack.jetbrains.com/issue/WI-25815 as well. – LazyOne Nov 23 '16 at 18:42
  • Thank you.. I will check these out and most probably I will submit an issue if nothing else comes up here. – gmponos Nov 23 '16 at 18:50
  • I've created [WI-35475](https://youtrack.jetbrains.com/issue/WI-35475) to track this issue. – Jannik Jochem Mar 17 '17 at 11:01

0 Answers0