|
28 | 28 | */ |
29 | 29 | final class Normalizer extends FQCNTypeNormalizer |
30 | 30 | { |
| 31 | + public const BUILD_IN_TYPES = FQCNTypeNormalizer::BUILD_IN_TYPES + [17 => 'static', 18 => '$this']; |
| 32 | + |
| 33 | + private const DOLLAR = '$'; |
| 34 | + private const SLASH = '\\'; |
| 35 | + private const DUMB_DOLLAR = self::SLASH . self::DOLLAR; |
| 36 | + private const MIXED_FORMAT = 'mixed %s'; |
| 37 | + private const ARR = '[]'; |
| 38 | + |
31 | 39 | /** |
32 | 40 | * @param \AdamWojs\PhpCsFixerPhpdocForceFQCN\Analyzer\NamespaceInfo $namespaceInfo |
33 | 41 | * @param string $type |
34 | 42 | * @return string |
35 | 43 | */ |
36 | 44 | public function normalizeType(NamespaceInfo $namespaceInfo, string $type): string |
37 | 45 | { |
38 | | - if ('[]' === \substr($type, -2)) { |
39 | | - return $this->normalizeType($namespaceInfo, \substr($type, 0, -2)) . '[]'; |
| 46 | + if (self::ARR === \substr($type, -2)) { |
| 47 | + return $this->normalizeType($namespaceInfo, \substr($type, 0, -2)) . self::ARR; |
40 | 48 | } |
41 | 49 |
|
42 | 50 | // if this is a built-in type, already has a namespace prefix, or is merely empty, move on. |
43 | 51 | if (\in_array($type, self::BUILD_IN_TYPES, true) || |
44 | | - 0 === \strpos($type, '\\') || |
| 52 | + 0 === \strpos($type, self::SLASH) || |
45 | 53 | '' === \trim($type)) { |
46 | 54 | return $type; |
47 | 55 | } |
48 | 56 |
|
49 | | - // if this is a variable, set to 'mixed' and assume i'll fix it later |
50 | | - if (0 === \strpos($type, '$')) { |
51 | | - return "mixed {$type}"; |
| 57 | + // if this is a variable... |
| 58 | + if (0 === \strpos($type, self::DOLLAR)) { |
| 59 | + // ...otherwise set to 'mixed' and assume i'll fix it later |
| 60 | + return \sprintf(self::MIXED_FORMAT, $type); |
52 | 61 | } |
53 | 62 |
|
54 | 63 | // if this is a dumb thing, clean it up |
55 | | - if (0 === \strpos($type, '\\$')) { |
56 | | - return \sprintf('mixed %s', \ltrim($type, '\\')); |
| 64 | + if (0 === \strpos($type, self::DUMB_DOLLAR)) { |
| 65 | + return \sprintf(self::MIXED_FORMAT, \ltrim($type, self::SLASH)); |
57 | 66 | } |
58 | 67 |
|
59 | 68 | // in all other cases, try to find an ns prefix |
|
0 commit comments