Skip to content

Commit

Permalink
add enum support
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored and Wirone committed Jan 9, 2024
1 parent 4b8cfdf commit 7d84776
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Fixer/Import/FullyQualifiedStrictTypesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,15 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
foreach (true === $this->configuration['import_symbols'] ? [true, false] : [false] as $discoverSymbolsPhase) {
$this->discoveredSymbols = $discoverSymbolsPhase ? [] : null;

$classyKinds = [T_CLASS, T_INTERFACE, T_TRAIT];
if (\defined('T_ENUM')) { // @TODO: drop condition when PHP 8.1+ is required
$classyKinds[] = T_ENUM;
}

for ($index = $namespace->getScopeStartIndex(); $index < $namespace->getScopeEndIndex() + $indexDiff; ++$index) {
$origSize = \count($tokens);
if ($discoverSymbolsPhase && $tokens[$index]->isGivenKind([T_CLASS, T_INTERFACE, T_TRAIT])) {

if ($discoverSymbolsPhase && $tokens[$index]->isGivenKind($classyKinds)) {
$this->fixNextName($tokens, $index, $uses, $namespaceName);
} elseif ($tokens[$index]->isGivenKind(T_FUNCTION)) {
$this->fixFunction($functionsAnalyzer, $tokens, $index, $uses, $namespaceName);
Expand Down
15 changes: 15 additions & 0 deletions tests/Fixer/Import/FullyQualifiedStrictTypesFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,21 @@ public function doSomethingMore(\Foo\Bar|B $foo): \Foo\Bar\Baz{}
public function doSomethingElse(\Foo\Bar&\A\Z $foo): \Foo\Bar\Baz{}
}',
];

yield 'import only if not already implicitly used by enum declaration' => [
<<<'EOD'
<?php
namespace Ns;
enum City
{
public function f(\Ns2\City $city) {}
}
EOD,
null,
['import_symbols' => true],
];
}

/**
Expand Down

0 comments on commit 7d84776

Please sign in to comment.