Skip to content

Commit 0dfb6ab

Browse files
committed
Merge branch '2.14'
2 parents 6540b65 + 7773a30 commit 0dfb6ab

File tree

9 files changed

+87
-9
lines changed

9 files changed

+87
-9
lines changed

src/Fixer/CastNotation/ModernizeTypesCastingFixer.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
110110

111111
$preserveParenthesises = $countParamTokens > 1;
112112

113+
$afterCloseParenthesisIndex = $tokens->getNextMeaningfulToken($closeParenthesis);
114+
$afterCloseParenthesisToken = $tokens[$afterCloseParenthesisIndex];
115+
$wrapInParenthesises = $afterCloseParenthesisToken->equals('[') || $afterCloseParenthesisToken->isGivenKind(T_POW);
116+
113117
// analyse namespace specification (root one or none) and decide what to do
114118
$prevTokenIndex = $tokens->getPrevMeaningfulToken($functionName);
115119
if ($tokens[$prevTokenIndex]->isGivenKind(T_NS_SEPARATOR)) {
@@ -123,6 +127,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
123127
new Token($newToken),
124128
new Token([T_WHITESPACE, ' ']),
125129
];
130+
if ($wrapInParenthesises) {
131+
array_unshift($replacementSequence, new Token('('));
132+
}
126133

127134
if (!$preserveParenthesises) {
128135
// closing parenthesis removed with leading spaces
@@ -138,6 +145,10 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
138145
$tokens->removeTrailingWhitespace($functionName);
139146
}
140147

148+
if ($wrapInParenthesises) {
149+
$tokens->insertAt($closeParenthesis, new Token(')'));
150+
}
151+
141152
$tokens->overrideRange($functionName, $functionName, $replacementSequence);
142153

143154
// nested transformations support

src/Fixer/LanguageConstruct/NoUnsetOnPropertyFixer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
8989
* @param Tokens $tokens
9090
* @param int $index
9191
*
92-
* @return string[]
92+
* @return array<array<string, bool|int>>
9393
*/
9494
private function getUnsetsInfo(Tokens $tokens, $index)
9595
{
@@ -152,7 +152,7 @@ private function isProperty(Tokens $tokens, $index, $endIndex)
152152
}
153153

154154
/**
155-
* @param string[] $unsetsInfo
155+
* @param array<array<string, bool|int>> $unsetsInfo
156156
*
157157
* @return bool
158158
*/
@@ -168,9 +168,9 @@ private function isAnyUnsetToTransform(array $unsetsInfo)
168168
}
169169

170170
/**
171-
* @param Tokens $tokens
172-
* @param string[] $unsetInfo
173-
* @param bool $isLastUnset
171+
* @param Tokens $tokens
172+
* @param array<string, bool|int> $unsetInfo
173+
* @param bool $isLastUnset
174174
*/
175175
private function updateTokens(Tokens $tokens, array $unsetInfo, $isLastUnset)
176176
{

src/Fixer/Whitespace/ArrayIndentationFixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function isCandidate(Tokens $tokens)
4949
*/
5050
public function getPriority()
5151
{
52-
// should run after BracesFixer
52+
// should run after BracesFixer, MethodChainingIndentationFixer
5353
return -30;
5454
}
5555

@@ -300,7 +300,7 @@ private function getLineIndentation(Tokens $tokens, $index)
300300

301301
private function extractIndent($content)
302302
{
303-
if (Preg::match('/\R([\t ]*)[^\r\n]*$/', $content, $matches)) {
303+
if (Preg::match('/\R([\t ]*)[^\r\n]*$/D', $content, $matches)) {
304304
return $matches[1];
305305
}
306306

src/Fixer/Whitespace/MethodChainingIndentationFixer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public function getDefinition()
4343
public function getPriority()
4444
{
4545
// Should run after BracesFixer
46-
return -30;
46+
// Should run before ArrayIndentationFixer
47+
return -29;
4748
}
4849

4950
/**

src/Tokenizer/TokensAnalyzer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getClassyElements()
6464
*
6565
* @param bool $perNamespace Return namespace uses per namespace
6666
*
67-
* @return array|array[]
67+
* @return int[]|int[][]
6868
*/
6969
public function getImportUseIndexes($perNamespace = false)
7070
{

tests/AutoReview/FixerFactoryTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public function provideFixersPriorityCases()
102102
[$fixers['is_null'], $fixers['yoda_style']],
103103
[$fixers['list_syntax'], $fixers['binary_operator_spaces']],
104104
[$fixers['list_syntax'], $fixers['ternary_operator_spaces']],
105+
[$fixers['method_chaining_indentation'], $fixers['array_indentation']],
105106
[$fixers['method_separation'], $fixers['braces']],
106107
[$fixers['method_separation'], $fixers['indentation_type']],
107108
[$fixers['no_alias_functions'], $fixers['implode_call']],

tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,36 @@ public function &doubleval($a);
179179
)#
180180
;#',
181181
],
182+
[
183+
'<?php $foo = ((int) $x)**2;',
184+
'<?php $foo = intval($x)**2;',
185+
],
186+
];
187+
}
188+
189+
/**
190+
* @param string $expected
191+
* @param string $input
192+
*
193+
* @requires PHP 7.0
194+
* @dataProvider provideFix70Cases
195+
*/
196+
public function testFix70($expected, $input)
197+
{
198+
$this->doTest($expected, $input);
199+
}
200+
201+
public function provideFix70Cases()
202+
{
203+
return [
204+
[
205+
'<?php $foo = ((string) $x)[0];',
206+
'<?php $foo = strval($x)[0];',
207+
],
208+
[
209+
'<?php $foo = ((string) ($x + $y))[0];',
210+
'<?php $foo = strval($x + $y)[0];',
211+
],
182212
];
183213
}
184214

tests/Fixer/Whitespace/ArrayIndentationFixerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,14 @@ class="link"
724724
INPUT
725725
,
726726
],
727+
[
728+
'<?php
729+
'.'
730+
$foo = [
731+
"foo",
732+
"bar",
733+
];',
734+
],
727735
]);
728736
}
729737

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Integration of fixers: method_chaining_indentation,array_indentation.
3+
--RULESET--
4+
{"array_indentation": true, "method_chaining_indentation": true}
5+
--EXPECT--
6+
<?php
7+
function foo($foo)
8+
{
9+
$foo
10+
->bar()
11+
->baz([
12+
'foo' => 'bar',
13+
])
14+
;
15+
}
16+
17+
--INPUT--
18+
<?php
19+
function foo($foo)
20+
{
21+
$foo
22+
->bar()
23+
->baz([
24+
'foo' => 'bar',
25+
])
26+
;
27+
}

0 commit comments

Comments
 (0)