Skip to content

Commit b5b76c0

Browse files
committed
Merge branch '2.15' into 2.16
2 parents a147bcb + 0ac4405 commit b5b76c0

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

.circleci/config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2
33
jobs:
44
build:
55
macos:
6-
xcode: '11.3.1'
6+
xcode: '11.4.0'
77
steps:
88
- checkout
99

@@ -12,7 +12,6 @@ jobs:
1212
- cache-{{ checksum "composer.json" }}
1313

1414
- run: brew update
15-
- run: brew remove python@2
1615
- run: brew install php@7.4
1716
- run: echo "memory_limit = 512M" > $(brew --prefix)/etc/php/7.4/conf.d/memory.ini
1817
- run: curl -sS https://getcomposer.org/installer | php

src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -256,32 +256,25 @@ private function fixFunctionDocComment($content, Tokens $tokens, $functionIndex,
256256

257257
/**
258258
* @param string $content
259-
* @param int $docCommentIndex
259+
* @param int $index Index of the DocComment token
260260
*
261261
* @return string
262262
*/
263-
private function fixPropertyDocComment($content, Tokens $tokens, $docCommentIndex, array $shortNames)
263+
private function fixPropertyDocComment($content, Tokens $tokens, $index, array $shortNames)
264264
{
265265
$docBlock = new DocBlock($content);
266266

267-
$index = $tokens->getNextMeaningfulToken($docCommentIndex);
268-
269-
$kindsBeforeProperty = [T_STATIC, T_PRIVATE, T_PROTECTED, T_PUBLIC];
270-
271-
if (!$tokens[$index]->isGivenKind($kindsBeforeProperty)) {
272-
return $content;
273-
}
274-
275267
do {
276268
$index = $tokens->getNextMeaningfulToken($index);
269+
} while ($tokens[$index]->isGivenKind([T_STATIC, T_PRIVATE, T_PROTECTED, T_PUBLIC]));
277270

278-
$propertyTypeInfo = $this->parseTypeHint($tokens, $index);
279-
foreach ($docBlock->getAnnotationsOfType('var') as $annotation) {
280-
if ($this->annotationIsSuperfluous($annotation, $propertyTypeInfo, $shortNames)) {
281-
$annotation->remove();
282-
}
271+
$propertyTypeInfo = $this->getPropertyTypeInfo($tokens, $index);
272+
273+
foreach ($docBlock->getAnnotationsOfType('var') as $annotation) {
274+
if ($this->annotationIsSuperfluous($annotation, $propertyTypeInfo, $shortNames)) {
275+
$annotation->remove();
283276
}
284-
} while ($tokens[$index]->isGivenKind($kindsBeforeProperty));
277+
}
285278

286279
return $docBlock->getContent();
287280
}
@@ -344,6 +337,23 @@ private function getReturnTypeInfo(Tokens $tokens, $closingParenthesisIndex)
344337
];
345338
}
346339

340+
/**
341+
* @param int $index The index of the first token of the type hint
342+
*
343+
* @return array
344+
*/
345+
private function getPropertyTypeInfo(Tokens $tokens, $index)
346+
{
347+
if ($tokens[$index]->isGivenKind(T_VARIABLE)) {
348+
return [
349+
'type' => null,
350+
'allows_null' => true,
351+
];
352+
}
353+
354+
return $this->parseTypeHint($tokens, $index);
355+
}
356+
347357
/**
348358
* @param int $index The index of the first token of the type hint
349359
*

tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,25 @@ public function doFoo($foo) {}
10511051
null,
10521052
['remove_inheritdoc' => true],
10531053
],
1054+
'property with unsupported type' => [
1055+
'<?php
1056+
class Foo {
1057+
/**
1058+
* @var foo:bar
1059+
*/
1060+
private $foo;
1061+
}',
1062+
],
1063+
'method with unsupported types' => [
1064+
'<?php
1065+
class Foo {
1066+
/**
1067+
* @param foo:bar $foo
1068+
* @return foo:bar
1069+
*/
1070+
public function foo($foo) {}
1071+
}',
1072+
],
10541073
];
10551074
}
10561075

0 commit comments

Comments
 (0)