|
@@ -52,7 +52,7 @@ final class FullyQualifiedStrictTypesFixer extends AbstractFixer implements Conf
|
|
|
public function getDefinition(): FixerDefinitionInterface
|
|
|
{
|
|
|
return new FixerDefinition(
|
|
|
- 'Removes the leading part of fully qualified symbol references if a given symbol is imported or belongs to the current namespace. Fixes function arguments, exceptions in `catch` block, `extend` and `implements` of classes and interfaces.',
|
|
|
+ 'Removes the leading part of fully qualified symbol references if a given symbol is imported or belongs to the current namespace.',
|
|
|
[
|
|
|
new CodeSample(
|
|
|
'<?php
|
|
@@ -162,12 +162,15 @@ class Foo extends \Other\BaseClass implements \Other\Interface1, \Other\Interfac
|
|
|
public function isCandidate(Tokens $tokens): bool
|
|
|
{
|
|
|
return $tokens->isAnyTokenKindsFound([
|
|
|
- T_FUNCTION,
|
|
|
- T_DOC_COMMENT,
|
|
|
- T_IMPLEMENTS,
|
|
|
- T_EXTENDS,
|
|
|
+ CT::T_USE_TRAIT,
|
|
|
T_CATCH,
|
|
|
T_DOUBLE_COLON,
|
|
|
+ T_DOC_COMMENT,
|
|
|
+ T_EXTENDS,
|
|
|
+ T_FUNCTION,
|
|
|
+ T_IMPLEMENTS,
|
|
|
+ T_INSTANCEOF,
|
|
|
+ T_NEW,
|
|
|
]);
|
|
|
}
|
|
|
|
|
@@ -242,7 +245,9 @@ class Foo extends \Other\BaseClass implements \Other\Interface1, \Other\Interfac
|
|
|
} elseif ($tokens[$index]->isGivenKind(T_CATCH)) {
|
|
|
$this->fixCatch($tokens, $index, $uses, $namespaceName);
|
|
|
} elseif ($tokens[$index]->isGivenKind(T_DOUBLE_COLON)) {
|
|
|
- $this->fixClassStaticAccess($tokens, $index, $uses, $namespaceName);
|
|
|
+ $this->fixPrevName($tokens, $index, $uses, $namespaceName);
|
|
|
+ } elseif ($tokens[$index]->isGivenKind([T_INSTANCEOF, T_NEW, CT::T_USE_TRAIT])) {
|
|
|
+ $this->fixNextName($tokens, $index, $uses, $namespaceName);
|
|
|
}
|
|
|
|
|
|
if ($tokens[$index]->isGivenKind(T_DOC_COMMENT)) {
|
|
@@ -390,7 +395,7 @@ class Foo extends \Other\BaseClass implements \Other\Interface1, \Other\Interfac
|
|
|
/**
|
|
|
* @param array<string, string> $uses
|
|
|
*/
|
|
|
- private function fixClassStaticAccess(Tokens $tokens, int $index, array &$uses, string $namespaceName): void
|
|
|
+ private function fixPrevName(Tokens $tokens, int $index, array &$uses, string $namespaceName): void
|
|
|
{
|
|
|
$classConstantRef = ['content' => '', 'tokens' => []];
|
|
|
|
|
@@ -409,6 +414,27 @@ class Foo extends \Other\BaseClass implements \Other\Interface1, \Other\Interfac
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param array<string, string> $uses
|
|
|
+ */
|
|
|
+ private function fixNextName(Tokens $tokens, int $index, array &$uses, string $namespaceName): void
|
|
|
+ {
|
|
|
+ $classConstantRef = ['content' => '', 'tokens' => []];
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ $index = $tokens->getNextMeaningfulToken($index);
|
|
|
+
|
|
|
+ if ($tokens[$index]->equalsAny([[T_STRING], [T_NS_SEPARATOR]])) {
|
|
|
+ $classConstantRef['tokens'][] = $index;
|
|
|
+ $classConstantRef['content'] .= $tokens[$index]->getContent();
|
|
|
+ } else {
|
|
|
+ $this->shortenClassIfPossible($tokens, $classConstantRef, $uses, $namespaceName);
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param array{content: string, tokens: array<int>} $class
|
|
|
* @param array<string, string> $uses
|