Skip to content

Commit

Permalink
fix: FullyQualifiedStrictTypesFixer - do not change case of the sym…
Browse files Browse the repository at this point in the history
…bol when there's name collision between imported class and imported function (#7750)
  • Loading branch information
kubawerlos committed Jan 16, 2024
1 parent e3afa32 commit bf48c81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Fixer/Import/FullyQualifiedStrictTypesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
$lastUse = null;

foreach ($namespaceUsesAnalyzer->getDeclarationsInNamespace($tokens, $namespace) as $use) {
if (!$use->isClass()) {
continue;
}
$uses[ltrim($use->getFullName(), '\\')] = $use->getShortName();
$lastUse = $use;
}
Expand Down
17 changes: 17 additions & 0 deletions tests/Fixer/Import/FullyQualifiedStrictTypesFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,23 @@ class Cl {}
EOD,
];

yield 'do not fix class named the same as imported function' => [
<<<'EOD'
<?php
namespace Foo;
use Bar\Request;
use function Baz\request;
class Test
{
public function request(Request $request = null)
{
$request = $request ?? Request::create('/docs.json');
}
}
$request = new Request();
EOD,
];

yield 'do not fix property named the same as class' => [
<<<'EOD'
<?php
Expand Down

0 comments on commit bf48c81

Please sign in to comment.