PSR2/RSPEC-1808 rule applied to grouped use statements inside same block

The following PSR2 (Namespace and Use Declarations) said:

There MUST be one blank line after the use block.

RSPEC-1808 is aplied to every line from use statement when has grouped namespaces same ocourre with PSR12.

Example:

<?php
namespace Test;

use FooClass;
use BarClass as Bar;
use OtherVendor\OtherPackage\BazClass;
use Vendor\Package\{ClassA as A, ClassB, ClassC as C};
use Vendor\Package\SomeNamespace\ClassD as D;
class Test
{

}

Sonarlint:
image

Another example:

<?php

namespace Test;

use Vendor\Package\{ClassA as A, ClassB, ClassC as C};
use Vendor\Package\{ClassZ, ClassX};
use Vendor\Package\{ClassQ, ClassY};
use Vendor\Package\SomeNamespace\ClassD as D;

class Test
{

}

image

https://rules.sonarsource.com/php/tag/psr2/RSPEC-1808

Hey @celosauro,

Indeed, this is a wrong behavior. Thank you for reporting this to us!

I did create https://jira.sonarsource.com/browse/SONARPHP-1219 to track this. We’ll also update this thread once the fix is released.

Best,
Karim.

1 Like

Hello,

This was fixed in the analyzer. The fixed version is already on SonarCloud, and will be added to the next SonarQube release.

Best,
Karim.

1 Like

Thanks, @Karim_El_Ouerghemmi !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.