Skip to content

Commit 646c1ef

Browse files
committed
Feat: Add FullyQualifiedStrictTypesFixer to import all FQCN (part of #94)
1 parent df6d309 commit 646c1ef

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

ecs.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToReturnTypeFixer;
8080
use PhpCsFixer\Fixer\FunctionNotation\ReturnTypeDeclarationFixer;
8181
use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer;
82+
use PhpCsFixer\Fixer\Import\FullyQualifiedStrictTypesFixer;
8283
use PhpCsFixer\Fixer\Import\NoLeadingImportSlashFixer;
8384
use PhpCsFixer\Fixer\Import\NoUnneededImportAliasFixer;
8485
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
@@ -550,6 +551,11 @@
550551
TrailingCommaInMultilineFixer::class,
551552
['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']], // Defined in PER 2.0
552553
)
554+
// Removes the leading part of FQCN
555+
->withConfiguredRule(
556+
FullyQualifiedStrictTypesFixer::class,
557+
['import_symbols' => true], // Also import symbols from other namespaces than in current file
558+
)
553559
->withSkip([
554560
// We allow empty catch statements (but they must have comment - see EmptyCatchCommentSniff)
555561
EmptyStatementSniff::class . '.DetectedCatch' => null,

tests/Integration/Fixtures/Basic.correct.php.inc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<?php declare(strict_types=1);
22

3-
use Bar\Foo; // NoUnneededImportAliasFixer
3+
namespace Lmc\CodingStandard\Integration\Fixtures;
44

5-
class Basic
5+
// NoUnneededImportAliasFixer
6+
use Bar\Foo;
7+
use Some\Other\Namespace\AbstractBasic;
8+
9+
class Basic extends AbstractBasic implements InterfaceFromThisNamespace // FullyQualifiedStrictTypesFixer
610
{
711
use SomeUsefulTrait; // OrderedClassElementsFixer
812
public const FOO = 'foo'; // ClassAttributesSeparationFixer

tests/Integration/Fixtures/Basic.wrong.php.inc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?php
22

3-
use Bar\Foo as Foo; // NoUnneededImportAliasFixer
3+
namespace Lmc\CodingStandard\Integration\Fixtures;
44

5-
class Basic
5+
// NoUnneededImportAliasFixer
6+
use Bar\Foo as Foo;
7+
8+
class Basic extends \Some\Other\Namespace\AbstractBasic implements \Lmc\CodingStandard\Integration\Fixtures\InterfaceFromThisNamespace // FullyQualifiedStrictTypesFixer
69
{
710
const FOO = 'foo'; // ClassAttributesSeparationFixer
811
function isEqual($a, ? string $b): ? bool // VisibilityRequiredFixer, CompactNullableTypeDeclarationFixer

0 commit comments

Comments
 (0)