Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,3 @@ final class ImportPartialInstanceOf
}

?>
-----
<?php

declare(strict_types=1);

namespace Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Fixture;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall;

final class ImportPartialInstanceOf
{
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [FuncCall::class];
}

public function isIteratorToArrayFuncCall(Expr $expr): bool
{
return $expr instanceof FuncCall;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,3 @@ abstract class KeepStaticMethod
}

?>
-----
<?php

declare(strict_types=1);

namespace Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Fixture;

use Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Source\Contract\Token;
use Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Source\Contract;

abstract class KeepStaticMethod
{
public static function decode(string $token): Token
{
$parts = explode('|', (string) base64_decode($token, true));

return Token::create($parts[0] ?? '', $parts[1] ?? '');
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Fixture;

use PhpParser\Node;

class PreventDuplication
{
public function getNodeTypes(): array
{
return [Node\Stmt\Expression::class];
}
}

?>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Rector\Tests\Renaming\Rector\Name\RenameClassRector\FixtureAutoImportNames;

use Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\FirstNamespace\FirstOriginalClass as AliasedClass;
use Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\SecondNamespace;

$aliasedClass = new AliasedClass();
$secondClass = new SecondNamespace\SecondOriginalClass();

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\Tests\Renaming\Rector\Name\RenameClassRector\FixtureAutoImportNames;

use PhpParser\Node;

class PartialExpression
{
public function getNodeTypes(): array
{
return [Node\Stmt\Expression::class];
}
}

?>
17 changes: 17 additions & 0 deletions rules/CodingStyle/ClassNameImport/ClassNameImportSkipper.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public function shouldSkipNameForFullyQualifiedObjectType(File $file, Node $node
*/
public function shouldSkipName(FullyQualified $fullyQualified, array $uses): bool
{
if ($this->isWrittenPartiallyQualified($fullyQualified)) {
return true;
}

if (substr_count($fullyQualified->toCodeString(), '\\') === 1) {
return $this->isFunctionOrConstantImport($fullyQualified);
}
Expand Down Expand Up @@ -99,6 +103,19 @@ public function shouldSkipName(FullyQualified $fullyQualified, array $uses): boo
return false;
}

/**
* Keep names written as "Field\TextField" or "namespace\Sub\Foo" as they are
*/
private function isWrittenPartiallyQualified(FullyQualified $fullyQualified): bool
{
$originalName = $fullyQualified->getAttribute(AttributeKey::ORIGINAL_NAME);
if (! $originalName instanceof Name) {
return false;
}

return $originalName->isQualified() || $originalName->isRelative();
}

private function isFunctionOrConstantImport(FullyQualified $fullyQualified): bool
{
if ($fullyQualified->getAttribute(AttributeKey::IS_CONSTFETCH_NAME) === true) {
Expand Down

This file was deleted.

29 changes: 0 additions & 29 deletions tests/Issues/AutoImport/Fixture/inner_with_subnamespace.php.inc

This file was deleted.

29 changes: 0 additions & 29 deletions tests/Issues/AutoImport/Fixture/inner_with_subnamespace2.php.inc

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

final class DontRenameDifferentNamespacedFunction
{
public function run(): void
{
$addressParts = Psl\Str\split($addressLine, $houseNumber);
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace helpers;

/**
* @see https://3v4l.org/WMUjV0
* it read with "helpers" as prefix: helpers\Sub\VarDumper
*/
class InnerWithSubnamespace extends Sub\VarDumper
{
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace helpers;

/**
* @see https://3v4l.org/PsIsB
* it read as double "helpers" as sub sub: helpers\helpers\Sub\VarDumper
*/
class InnerWithSubnamespace extends helpers\Sub\VarDumper
{
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Issues\AutoImportAliasedNamespace;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class AutoImportAliasedNamespaceTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
Loading
Loading