Skip to content

Commit f88a5e7

Browse files
committed
Merge branch '2.15'
* 2.15: Update symfony ruleset FunctionsAnalyzer: fix for comment in type
2 parents 68c932a + 27b45b8 commit f88a5e7

File tree

7 files changed

+46
-20
lines changed

7 files changed

+46
-20
lines changed

README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ Choose from the list of available rules:
264264

265265
Each element of an array must be indented exactly once.
266266

267-
* **array_syntax** [@PhpCsFixer]
267+
* **array_syntax** [@Symfony, @PhpCsFixer]
268268

269269
PHP arrays should be declared using the configured syntax.
270270

@@ -1283,7 +1283,7 @@ Choose from the list of available rules:
12831283
- ``sortAlgorithm`` (``'alpha'``, ``'none'``): how multiple occurrences of same type
12841284
statements should be sorted; defaults to ``'none'``
12851285

1286-
* **ordered_imports** [@PhpCsFixer]
1286+
* **ordered_imports** [@Symfony, @PhpCsFixer]
12871287

12881288
Ordering ``use`` statements.
12891289

@@ -1562,7 +1562,7 @@ Choose from the list of available rules:
15621562
ones; defaults to ``['property-read' => 'property', 'property-write' =>
15631563
'property', 'type' => 'var', 'link' => 'see']``
15641564

1565-
* **phpdoc_no_empty_return** [@Symfony, @PhpCsFixer]
1565+
* **phpdoc_no_empty_return** [@PhpCsFixer]
15661566

15671567
``@return void`` and ``@return null`` annotations should be omitted from
15681568
PHPDoc.
@@ -1639,7 +1639,7 @@ Choose from the list of available rules:
16391639
PHPDoc should start and end with content, excluding the very first and
16401640
last line of the docblocks.
16411641

1642-
* **phpdoc_trim_consecutive_blank_line_separation** [@PhpCsFixer]
1642+
* **phpdoc_trim_consecutive_blank_line_separation** [@Symfony, @PhpCsFixer]
16431643

16441644
Removes extra blank lines after summary and after description in PHPDoc.
16451645

@@ -1684,7 +1684,7 @@ Choose from the list of available rules:
16841684
Pre incrementation/decrementation should be used if possible.
16851685
DEPRECATED: use ``increment_style`` instead.
16861686

1687-
* **protected_to_private** [@Symfony, @PhpCsFixer]
1687+
* **protected_to_private** [@PhpCsFixer]
16881688

16891689
Converts ``protected`` variables and methods to ``private`` where possible.
16901690

src/RuleSet.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ final class RuleSet implements RuleSetInterface
5858
],
5959
'@Symfony' => [
6060
'@PSR2' => true,
61+
'array_syntax' => ['syntax' => 'short'],
6162
'binary_operator_spaces' => true,
6263
'blank_line_after_opening_tag' => true,
6364
'blank_line_before_statement' => [
@@ -112,6 +113,7 @@ final class RuleSet implements RuleSetInterface
112113
'no_whitespace_in_blank_line' => true,
113114
'normalize_index_brace' => true,
114115
'object_operator_without_whitespace' => true,
116+
'ordered_imports' => true,
115117
'php_unit_fqcn_annotation' => true,
116118
'phpdoc_align' => [
117119
// @TODO: on 3.0 switch whole rule to `=> true`, currently we use custom config that will be default on 3.0
@@ -130,7 +132,6 @@ final class RuleSet implements RuleSetInterface
130132
'phpdoc_inline_tag' => true,
131133
'phpdoc_no_access' => true,
132134
'phpdoc_no_alias_tag' => true,
133-
'phpdoc_no_empty_return' => true,
134135
'phpdoc_no_package' => true,
135136
'phpdoc_no_useless_inheritdoc' => true,
136137
'phpdoc_return_self_reference' => true,
@@ -140,13 +141,13 @@ final class RuleSet implements RuleSetInterface
140141
'phpdoc_summary' => true,
141142
'phpdoc_to_comment' => true,
142143
'phpdoc_trim' => true,
144+
'phpdoc_trim_consecutive_blank_line_separation' => true,
143145
'phpdoc_types' => true,
144146
'phpdoc_types_order' => [
145147
'null_adjustment' => 'always_last',
146148
'sort_algorithm' => 'none',
147149
],
148150
'phpdoc_var_without_name' => true,
149-
'protected_to_private' => true,
150151
'return_type_declaration' => true,
151152
'semicolon_after_instruction' => true,
152153
'short_scalar_cast' => true,
@@ -206,7 +207,6 @@ final class RuleSet implements RuleSetInterface
206207
'@Symfony' => true,
207208
'align_multiline_comment' => true,
208209
'array_indentation' => true,
209-
'array_syntax' => ['syntax' => 'short'],
210210
'blank_line_before_statement' => true,
211211
'combine_consecutive_issets' => true,
212212
'combine_consecutive_unsets' => true,
@@ -242,16 +242,16 @@ final class RuleSet implements RuleSetInterface
242242
'no_useless_else' => true,
243243
'no_useless_return' => true,
244244
'ordered_class_elements' => true,
245-
'ordered_imports' => true,
246245
'php_unit_internal_class' => true,
247246
'php_unit_method_casing' => true,
248247
'php_unit_ordered_covers' => true,
249248
'php_unit_test_class_requires_covers' => true,
250249
'phpdoc_add_missing_param_annotation' => true,
250+
'phpdoc_no_empty_return' => true,
251251
'phpdoc_order' => true,
252-
'phpdoc_trim_consecutive_blank_line_separation' => true,
253252
'phpdoc_types_order' => true,
254253
'phpdoc_var_annotation_correct_order' => true,
254+
'protected_to_private' => true,
255255
'return_assignment' => true,
256256
'simple_to_complex_string_variable' => true,
257257
'single_line_comment_style' => true,

src/Tokenizer/Analyzer/FunctionsAnalyzer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ public function getFunctionReturnType(Tokens $tokens, $methodIndex)
8282
}
8383

8484
$type = '';
85-
$typeStartIndex = $tokens->getNextNonWhitespace($typeColonIndex);
85+
$typeStartIndex = $tokens->getNextMeaningfulToken($typeColonIndex);
8686
$typeEndIndex = $typeStartIndex;
8787
$functionBodyStart = $tokens->getNextTokenOfKind($typeColonIndex, ['{', ';']);
8888
for ($i = $typeStartIndex; $i < $functionBodyStart; ++$i) {
89-
if ($tokens[$i]->isWhitespace()) {
89+
if ($tokens[$i]->isWhitespace() || $tokens[$i]->isComment()) {
9090
continue;
9191
}
9292

tests/Fixtures/Integration/misc/PHP7.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Foo implements FooInterface
4949
const FOR = 1;
5050

5151
// array const
52-
const ARR = array(1, 2);
52+
const ARR = [1, 2];
5353

5454
// semi-reserved keyword as function name
5555
public function list($a, $b)
@@ -65,7 +65,7 @@ class Foo implements FooInterface
6565
echo mt_rand(0, 1);
6666

6767
// uniform variable syntax
68-
$a = array('b' => 'c');
68+
$a = ['b' => 'c'];
6969
$c = 'Next step !';
7070
echo ${$a['b']};
7171

tests/Fixtures/Integration/set/@Symfony.test-out.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ public function __construct($dummy)
4141
*
4242
* @throws \RuntimeException
4343
*/
44-
private function transformText($dummy, array $options = array(), $data = null)
44+
private function transformText($dummy, array $options = [], $data = null)
4545
{
4646
$fnc = function () { return true; };
4747

4848
$mergedOptions = array_merge(
49-
array(
49+
[
5050
'some_default' => 'values',
5151
'another_default' => 'more values',
52-
),
52+
],
5353
$options
5454
);
5555

tests/Fixtures/Integration/set/@Symfony_whitespaces.test-out.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ public function __construct($dummy)
4141
*
4242
* @throws \RuntimeException
4343
*/
44-
private function transformText($dummy, array $options = array(), $data = null)
44+
private function transformText($dummy, array $options = [], $data = null)
4545
{
4646
$fnc = function () { return true; };
4747

4848
$mergedOptions = array_merge(
49-
array(
49+
[
5050
'some_default' => 'values',
5151
'another_default' => 'more values',
52-
),
52+
],
5353
$options
5454
);
5555

tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,30 @@ public function provideFunctionsWithArgumentsCases()
213213
)
214214
),
215215
]],
216+
['<?php function(\Foo\Bar $a){};', 1, [
217+
'$a' => new ArgumentAnalysis(
218+
'$a',
219+
8,
220+
null,
221+
new TypeAnalysis(
222+
'\Foo\Bar',
223+
3,
224+
6
225+
)
226+
),
227+
]],
228+
['<?php function(\Foo/** TODO: change to something else */\Bar $a){};', 1, [
229+
'$a' => new ArgumentAnalysis(
230+
'$a',
231+
9,
232+
null,
233+
new TypeAnalysis(
234+
'\Foo\Bar',
235+
3,
236+
7
237+
)
238+
),
239+
]],
216240
];
217241
}
218242

@@ -222,6 +246,8 @@ public function provideFunctionsWithReturnTypeCases()
222246
['<?php function(){};', 1, null],
223247
['<?php function($a): array {};', 1, new TypeAnalysis('array', 7, 7)],
224248
['<?php function($a): \Foo\Bar {};', 1, new TypeAnalysis('\Foo\Bar', 7, 10)],
249+
['<?php function($a): /* not sure if really an array */array {};', 1, new TypeAnalysis('array', 8, 8)],
250+
['<?php function($a): \Foo/** TODO: change to something else */\Bar {};', 1, new TypeAnalysis('\Foo\Bar', 7, 11)],
225251
];
226252
}
227253
}

0 commit comments

Comments
 (0)