-
I am using throw new \Exception(); to +use Exception;
-throw new \Exception();
+throw new Exception(); But I have some FQCN instances coming out of Edge Case Number 1namespace Entity;
class Apple extends \Entity\AbstractEntity The above is not being fixed, but should be converted as follows to remove the unnecessary namespace on namespace Entity;
-class Apple extends \Entity\AbstractEntity
+class Apple extends AbstractEntity Edge Case Number 2#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
public function testConstructorSuccess(): void This should be converted as follows: +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
-#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
+#[DoesNotPerformAssertions]
public function testConstructorSuccess(): void My fixer config: <?php declare(strict_types=1);
use PhpCsFixer\Fixer\Import\GlobalNamespaceImportFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
return function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);
$ecsConfig->rules([
GlobalNamespaceImportFixer::class, // Force use statement over FQCN reference
]);
$ecsConfig->sets([
SetList::COMMENTS,
SetList::NAMESPACES,
SetList::STRICT,
SetList::PSR_12,
]);
}; I'm guessing one of three things is going on:
I'm happy to debug further id there's any additional info that would help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
@Wirone, thanks for converting this to a discussion. Do you have any insight on the matter? |
Beta Was this translation helpful? Give feedback.
-
First of all, you asked about PHP CS Fixer's
|
Beta Was this translation helpful? Give feedback.
First of all, you asked about PHP CS Fixer's
GlobalNamespaceImportFixer
, but you mention Rector and provide ECS configuration 🤷♂️. But anyway...GlobalNamespaceImportFixer
, as its name speaks explicitly, handles only symbols from global namespace, so it won't fix any FQCN from custom namespace.fully_qualified_strict_types
fixer, which on the other hand handles FQCNs, but only for symbols already imported, and not all cases are covered.PS. Rector has configuration option to import FQCNs.