@@ -57,7 +57,7 @@ |
||
57 | 57 | $tokens[$index] = new Token([$token->getId(), $trimmedContent]); |
58 | 58 | |
59 | 59 | if (isset($tokens[$index + 1]) && $tokens[$index + 1]->isWhitespace()) { |
60 | - $tokens[$index + 1] = new Token([T_WHITESPACE, $whitespaces.$tokens[$index + 1]->getContent()]); |
|
60 | + $tokens[$index + 1] = new Token([T_WHITESPACE, $whitespaces . $tokens[$index + 1]->getContent()]); |
|
61 | 61 | } else { |
62 | 62 | $tokens->insertAt($index + 1, new Token([T_WHITESPACE, $whitespaces])); |
63 | 63 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | // First match explicit imports: |
35 | 35 | $useMap = $this->getUseMapFromTokens($tokens); |
36 | 36 | foreach ($useMap as $shortName => $fullName) { |
37 | - $regex = '/^\\\\?'.preg_quote($fullName, '/').'$/'; |
|
37 | + $regex = '/^\\\\?' . preg_quote($fullName, '/') . '$/'; |
|
38 | 38 | if (Preg::match($regex, $typeName)) { |
39 | 39 | return $shortName; |
40 | 40 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | if (1 === \count($namespaces)) { |
47 | 47 | foreach ($namespaces as $fullName) { |
48 | 48 | $matches = []; |
49 | - $regex = '/^\\\\?'.preg_quote($fullName, '/').'\\\\(?P<className>.+)$/'; |
|
49 | + $regex = '/^\\\\?' . preg_quote($fullName, '/') . '\\\\(?P<className>.+)$/'; |
|
50 | 50 | if (Preg::match($regex, $typeName, $matches)) { |
51 | 51 | return $matches['className']; |
52 | 52 | } |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | |
58 | 58 | foreach ($useMap as $shortName => $fullName) { |
59 | 59 | $matches = []; |
60 | - $regex = '/^\\\\?'.preg_quote($fullName, '/').'\\\\(?P<className>.+)$/'; |
|
60 | + $regex = '/^\\\\?' . preg_quote($fullName, '/') . '\\\\(?P<className>.+)$/'; |
|
61 | 61 | if (Preg::match($regex, $typeName, $matches)) { |
62 | - return $shortName.'\\'.$matches['className']; |
|
62 | + return $shortName . '\\' . $matches['className']; |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | private function getNamespacesFromTokens(Tokens $tokens): array |
73 | 73 | { |
74 | - return array_map(static function (NamespaceAnalysis $info) { |
|
74 | + return array_map(static function(NamespaceAnalysis $info) { |
|
75 | 75 | return $info->getFullName(); |
76 | 76 | }, (new NamespacesAnalyzer())->getDeclarations($tokens)); |
77 | 77 | } |
@@ -70,7 +70,7 @@ |
||
70 | 70 | |
71 | 71 | $tokens = self::getMapById(); |
72 | 72 | |
73 | - return 'CT::'.$tokens[$value]; |
|
73 | + return 'CT::' . $tokens[$value]; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -361,12 +361,12 @@ discard block |
||
361 | 361 | */ |
362 | 362 | public function ensureWhitespaceAtIndex(int $index, int $indexOffset, string $whitespace): bool |
363 | 363 | { |
364 | - $removeLastCommentLine = static function (self $tokens, int $index, int $indexOffset, string $whitespace): string { |
|
364 | + $removeLastCommentLine = static function(self $tokens, int $index, int $indexOffset, string $whitespace): string { |
|
365 | 365 | $token = $tokens[$index]; |
366 | 366 | |
367 | 367 | if (1 === $indexOffset && $token->isGivenKind(T_OPEN_TAG)) { |
368 | 368 | if (0 === strpos($whitespace, "\r\n")) { |
369 | - $tokens[$index] = new Token([T_OPEN_TAG, rtrim($token->getContent())."\r\n"]); |
|
369 | + $tokens[$index] = new Token([T_OPEN_TAG, rtrim($token->getContent()) . "\r\n"]); |
|
370 | 370 | |
371 | 371 | return \strlen($whitespace) > 2 // can be removed on PHP 7; https://php.net/manual/en/function.substr.php |
372 | 372 | ? substr($whitespace, 2) |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | ; |
375 | 375 | } |
376 | 376 | |
377 | - $tokens[$index] = new Token([T_OPEN_TAG, rtrim($token->getContent()).$whitespace[0]]); |
|
377 | + $tokens[$index] = new Token([T_OPEN_TAG, rtrim($token->getContent()) . $whitespace[0]]); |
|
378 | 378 | |
379 | 379 | return \strlen($whitespace) > 1 // can be removed on PHP 7; https://php.net/manual/en/function.substr.php |
380 | 380 | ? substr($whitespace, 1) |
@@ -447,13 +447,13 @@ discard block |
||
447 | 447 | } |
448 | 448 | |
449 | 449 | $elements = []; |
450 | - $possibleKinds = (array) $possibleKind; |
|
450 | + $possibleKinds = (array)$possibleKind; |
|
451 | 451 | |
452 | 452 | foreach ($possibleKinds as $kind) { |
453 | 453 | $elements[$kind] = []; |
454 | 454 | } |
455 | 455 | |
456 | - $possibleKinds = array_filter($possibleKinds, function ($kind) { |
|
456 | + $possibleKinds = array_filter($possibleKinds, function($kind) { |
|
457 | 457 | return $this->isTokenKindFound($kind); |
458 | 458 | }); |
459 | 459 | |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | */ |
588 | 588 | public function getTokenOfKindSibling(int $index, int $direction, array $tokens = [], bool $caseSensitive = true): ?int |
589 | 589 | { |
590 | - $tokens = array_filter($tokens, function ($token) { |
|
590 | + $tokens = array_filter($tokens, function($token) { |
|
591 | 591 | return $this->isTokenKindFound($this->extractTokenKind($token)); |
592 | 592 | }); |
593 | 593 | |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | return $this->getTokenNotOfKind( |
621 | 621 | $index, |
622 | 622 | $direction, |
623 | - function (int $a) use ($tokens) { |
|
623 | + function(int $a) use ($tokens) { |
|
624 | 624 | return $this[$a]->equalsAny($tokens); |
625 | 625 | } |
626 | 626 | ); |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | return $this->getTokenNotOfKind( |
639 | 639 | $index, |
640 | 640 | $direction, |
641 | - function (int $index) use ($kinds) { |
|
641 | + function(int $index) use ($kinds) { |
|
642 | 642 | return $this[$index]->isGivenKind($kinds); |
643 | 643 | } |
644 | 644 | ); |
@@ -1141,7 +1141,7 @@ discard block |
||
1141 | 1141 | $prevIndex = $this->getNonEmptySibling($index, -1); |
1142 | 1142 | |
1143 | 1143 | if ($this[$prevIndex]->isWhitespace()) { |
1144 | - $this[$prevIndex] = new Token([T_WHITESPACE, $this[$prevIndex]->getContent().$this[$nextIndex]->getContent()]); |
|
1144 | + $this[$prevIndex] = new Token([T_WHITESPACE, $this[$prevIndex]->getContent() . $this[$nextIndex]->getContent()]); |
|
1145 | 1145 | } elseif ($this->isEmptyAt($prevIndex + 1)) { |
1146 | 1146 | $this[$prevIndex + 1] = new Token([T_WHITESPACE, $this[$nextIndex]->getContent()]); |
1147 | 1147 | } |
@@ -31,6 +31,6 @@ |
||
31 | 31 | */ |
32 | 32 | public static function calculateCodeHash(string $code): string |
33 | 33 | { |
34 | - return (string) crc32($code); |
|
34 | + return (string)crc32($code); |
|
35 | 35 | } |
36 | 36 | } |
@@ -121,7 +121,7 @@ |
||
121 | 121 | private function normalizeType(string $type): string |
122 | 122 | { |
123 | 123 | if ('[]' === substr($type, -2)) { |
124 | - return $this->normalizeType(substr($type, 0, -2)).'[]'; |
|
124 | + return $this->normalizeType(substr($type, 0, -2)) . '[]'; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | return $this->normalize($type); |
@@ -53,17 +53,17 @@ discard block |
||
53 | 53 | { |
54 | 54 | $this->differ = new FullDiffer(); |
55 | 55 | |
56 | - $this->path = \dirname(__DIR__, 2).'/doc'; |
|
56 | + $this->path = \dirname(__DIR__, 2) . '/doc'; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | public function getFixersDocumentationDirectoryPath(): string |
60 | 60 | { |
61 | - return $this->path.'/rules'; |
|
61 | + return $this->path . '/rules'; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | public function getFixersDocumentationIndexFilePath(): string |
65 | 65 | { |
66 | - return $this->getFixersDocumentationDirectoryPath().'/index.rst'; |
|
66 | + return $this->getFixersDocumentationDirectoryPath() . '/index.rst'; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | 'Phpdoc' => 'PHPDoc', |
78 | 78 | ]; |
79 | 79 | |
80 | - usort($fixers, function (FixerInterface $a, FixerInterface $b) { |
|
80 | + usort($fixers, function(FixerInterface $a, FixerInterface $b) { |
|
81 | 81 | return strcmp(\get_class($a), \get_class($b)); |
82 | 82 | }); |
83 | 83 | |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | } |
115 | 115 | |
116 | 116 | if ([] !== $attributes) { |
117 | - $attributes = ' *('.implode(', ', $attributes).')*'; |
|
117 | + $attributes = ' *(' . implode(', ', $attributes) . ')*'; |
|
118 | 118 | } else { |
119 | 119 | $attributes = ''; |
120 | 120 | } |
121 | 121 | |
122 | - $path = './'.$this->getFixerDocumentationFileRelativePath($fixer); |
|
122 | + $path = './' . $this->getFixerDocumentationFileRelativePath($fixer); |
|
123 | 123 | |
124 | 124 | $documentation .= <<<RST |
125 | 125 | |
@@ -133,19 +133,19 @@ discard block |
||
133 | 133 | |
134 | 134 | public function getFixerDocumentationFilePath(FixerInterface $fixer): string |
135 | 135 | { |
136 | - return $this->getFixersDocumentationDirectoryPath().'/'.Preg::replaceCallback( |
|
136 | + return $this->getFixersDocumentationDirectoryPath() . '/' . Preg::replaceCallback( |
|
137 | 137 | '/^.*\\\\(.+)\\\\(.+)Fixer$/', |
138 | - function (array $matches) { |
|
139 | - return Utils::camelCaseToUnderscore($matches[1]).'/'.Utils::camelCaseToUnderscore($matches[2]); |
|
138 | + function(array $matches) { |
|
139 | + return Utils::camelCaseToUnderscore($matches[1]) . '/' . Utils::camelCaseToUnderscore($matches[2]); |
|
140 | 140 | }, |
141 | 141 | \get_class($fixer) |
142 | - ).'.rst'; |
|
142 | + ) . '.rst'; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | public function getFixerDocumentationFileRelativePath(FixerInterface $fixer): string |
146 | 146 | { |
147 | 147 | return Preg::replace( |
148 | - '#^'.preg_quote($this->getFixersDocumentationDirectoryPath(), '#').'/#', |
|
148 | + '#^' . preg_quote($this->getFixersDocumentationDirectoryPath(), '#') . '/#', |
|
149 | 149 | '', |
150 | 150 | $this->getFixerDocumentationFilePath($fixer) |
151 | 151 | ); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | |
174 | 174 | $definition = $fixer->getDefinition(); |
175 | 175 | |
176 | - $doc .= "\n\n".$this->toRst($definition->getSummary()); |
|
176 | + $doc .= "\n\n" . $this->toRst($definition->getSummary()); |
|
177 | 177 | |
178 | 178 | $description = $definition->getDescription(); |
179 | 179 | if (null !== $description) { |
@@ -215,13 +215,13 @@ discard block |
||
215 | 215 | |
216 | 216 | foreach ($configurationDefinition->getOptions() as $option) { |
217 | 217 | $optionInfo = "``{$option->getName()}``"; |
218 | - $optionInfo .= "\n".str_repeat('~', \strlen($optionInfo)); |
|
218 | + $optionInfo .= "\n" . str_repeat('~', \strlen($optionInfo)); |
|
219 | 219 | |
220 | 220 | if ($option instanceof DeprecatedFixerOptionInterface) { |
221 | 221 | $optionInfo .= "\n\n.. warning:: This option is deprecated and will be removed on next major version. {$this->toRst($option->getDeprecationMessage())}"; |
222 | 222 | } |
223 | 223 | |
224 | - $optionInfo .= "\n\n".$this->toRst($option->getDescription()); |
|
224 | + $optionInfo .= "\n\n" . $this->toRst($option->getDescription()); |
|
225 | 225 | |
226 | 226 | if ($option instanceof AliasedFixerOption) { |
227 | 227 | $optionInfo .= "\n\n.. note:: The previous name of this option was ``{$option->getAlias()}`` but it is now deprecated and will be removed on next major version."; |
@@ -232,15 +232,15 @@ discard block |
||
232 | 232 | if (null !== $allowed) { |
233 | 233 | foreach ($allowed as &$value) { |
234 | 234 | if ($value instanceof AllowedValueSubset) { |
235 | - $value = 'a subset of ``'.HelpCommand::toString($value->getAllowedValues()).'``'; |
|
235 | + $value = 'a subset of ``' . HelpCommand::toString($value->getAllowedValues()) . '``'; |
|
236 | 236 | } else { |
237 | - $value = '``'.HelpCommand::toString($value).'``'; |
|
237 | + $value = '``' . HelpCommand::toString($value) . '``'; |
|
238 | 238 | } |
239 | 239 | } |
240 | 240 | } else { |
241 | 241 | $allowedKind = 'Allowed types'; |
242 | - $allowed = array_map(function ($value) { |
|
243 | - return '``'.$value.'``'; |
|
242 | + $allowed = array_map(function($value) { |
|
243 | + return '``' . $value . '``'; |
|
244 | 244 | }, $option->getAllowedTypes()); |
245 | 245 | } |
246 | 246 | |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | } |
285 | 285 | } |
286 | 286 | |
287 | - $doc .= "\n".$this->generateSampleDiff($fixer, $sample, $index + 1, $name); |
|
287 | + $doc .= "\n" . $this->generateSampleDiff($fixer, $sample, $index + 1, $name); |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | RST; |
322 | 322 | |
323 | 323 | if (null !== $config) { |
324 | - $doc .= " with the config below:\n\n ``".HelpCommand::toString($config).'``'; |
|
324 | + $doc .= " with the config below:\n\n ``" . HelpCommand::toString($config) . '``'; |
|
325 | 325 | } elseif ($fixer instanceof ConfigurableFixerInterface) { |
326 | 326 | $doc .= ' with the default config.'; |
327 | 327 | } else { |
@@ -335,12 +335,12 @@ discard block |
||
335 | 335 | |
336 | 336 | public function getRuleSetsDocumentationDirectoryPath(): string |
337 | 337 | { |
338 | - return $this->path.'/ruleSets'; |
|
338 | + return $this->path . '/ruleSets'; |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | public function getRuleSetsDocumentationIndexFilePath(): string |
342 | 342 | { |
343 | - return $this->getRuleSetsDocumentationDirectoryPath().'/index.rst'; |
|
343 | + return $this->getRuleSetsDocumentationDirectoryPath() . '/index.rst'; |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | |
356 | 356 | $title = "Rule set ``{$definition->getName()}``"; |
357 | 357 | $titleLine = str_repeat('=', \strlen($title)); |
358 | - $doc = "{$titleLine}\n{$title}\n{$titleLine}\n\n".$definition->getDescription(); |
|
358 | + $doc = "{$titleLine}\n{$title}\n{$titleLine}\n\n" . $definition->getDescription(); |
|
359 | 359 | if ($definition->isRisky()) { |
360 | 360 | $doc .= ' This set contains rules that are risky.'; |
361 | 361 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | $doc .= "\n- `{$rule} <.{$ruleSetPath}>`_"; |
377 | 377 | } else { |
378 | 378 | $path = Preg::replace( |
379 | - '#^'.preg_quote($this->getFixersDocumentationDirectoryPath(), '#').'/#', |
|
379 | + '#^' . preg_quote($this->getFixersDocumentationDirectoryPath(), '#') . '/#', |
|
380 | 380 | './../rules/', |
381 | 381 | $this->getFixerDocumentationFilePath($fixerNames[$rule]) |
382 | 382 | ); |
@@ -385,17 +385,17 @@ discard block |
||
385 | 385 | } |
386 | 386 | |
387 | 387 | if (!\is_bool($config)) { |
388 | - $doc .= "\n config:\n ``".HelpCommand::toString($config).'``'; |
|
388 | + $doc .= "\n config:\n ``" . HelpCommand::toString($config) . '``'; |
|
389 | 389 | } |
390 | 390 | } |
391 | 391 | } |
392 | 392 | |
393 | - return $doc."\n"; |
|
393 | + return $doc . "\n"; |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | public function getRuleSetsDocumentationFilePath(string $name): string |
397 | 397 | { |
398 | - return $this->getRuleSetsDocumentationDirectoryPath().'/'.str_replace(':risky', 'Risky', ucfirst(substr($name, 1))).'.rst'; |
|
398 | + return $this->getRuleSetsDocumentationDirectoryPath() . '/' . str_replace(':risky', 'Risky', ucfirst(substr($name, 1))) . '.rst'; |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | public function generateRuleSetsDocumentationIndex(array $setDefinitions): string |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | $documentation .= "\n- `{$name} <.{$path}>`_"; |
411 | 411 | } |
412 | 412 | |
413 | - return $documentation."\n"; |
|
413 | + return $documentation . "\n"; |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | private function generateSampleDiff(FixerInterface $fixer, CodeSampleInterface $sample, int $sampleNumber, string $ruleName): string |
@@ -483,6 +483,6 @@ discard block |
||
483 | 483 | |
484 | 484 | private function indent(string $string, int $indent): string |
485 | 485 | { |
486 | - return Preg::replace('/(\n)(?!\n|$)/', '$1'.str_repeat(' ', $indent), $string); |
|
486 | + return Preg::replace('/(\n)(?!\n|$)/', '$1' . str_repeat(' ', $indent), $string); |
|
487 | 487 | } |
488 | 488 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function __sleep(): array |
84 | 84 | { |
85 | - throw new \BadMethodCallException('Cannot serialize '.__CLASS__); |
|
85 | + throw new \BadMethodCallException('Cannot serialize ' . __CLASS__); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function __wakeup(): void |
95 | 95 | { |
96 | - throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); |
|
96 | + throw new \BadMethodCallException('Cannot unserialize ' . __CLASS__); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | public function needFixing(string $file, string $fileContent): bool |
@@ -95,7 +95,7 @@ |
||
95 | 95 | return $data; |
96 | 96 | } |
97 | 97 | |
98 | - array_walk_recursive($data, static function (&$item): void { |
|
98 | + array_walk_recursive($data, static function(&$item): void { |
|
99 | 99 | if (\is_string($item) && !mb_detect_encoding($item, 'utf-8', true)) { |
100 | 100 | $item = utf8_encode($item); |
101 | 101 | } |