Skip to content

Commit 8c99293

Browse files
committed
Missing traversable specification was not reported for unqualified type hints
1 parent 9a864dd commit 8c99293

File tree

3 files changed

+98
-69
lines changed

3 files changed

+98
-69
lines changed

SlevomatCodingStandard/Sniffs/TypeHints/TypeHintDeclarationSniff.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private function checkParametersTypeHints(\PHP_CodeSniffer_File $phpcsFile, int
9898
if (!SuppressHelper::isSniffSuppressed($phpcsFile, $functionPointer, $this->getSniffName(self::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION))) {
9999
foreach (FunctionHelper::getParametersTypeHints($phpcsFile, $functionPointer) as $parameterName => $parameterTypeHint) {
100100
$traversableTypeHint = false;
101-
if ($parameterTypeHint !== null && $this->isTraversableTypeHint($parameterTypeHint->getTypeHint())) {
101+
if ($parameterTypeHint !== null && $this->isTraversableTypeHint(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $parameterTypeHint->getTypeHint()))) {
102102
$traversableTypeHint = true;
103103
} elseif (array_key_exists($parameterName, $parametersTypeHintsDefinitions) && $this->definitionContainsTraversableTypeHint($phpcsFile, $functionPointer, $parametersTypeHintsDefinitions[$parameterName])) {
104104
$traversableTypeHint = true;
@@ -116,7 +116,11 @@ private function checkParametersTypeHints(\PHP_CodeSniffer_File $phpcsFile, int
116116
self::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION
117117
);
118118
} elseif (($traversableTypeHint && !$this->definitionContainsTraversableTypeHintSpeficication($parametersTypeHintsDefinitions[$parameterName]))
119-
|| (array_key_exists($parameterName, $parametersTypeHintsDefinitions) && $this->definitionContainsTraversableTypeHintSpeficication($parametersTypeHintsDefinitions[$parameterName]) && !$this->definitionContainsItemsSpecificationForTraversable($parametersTypeHintsDefinitions[$parameterName]))
119+
|| (
120+
array_key_exists($parameterName, $parametersTypeHintsDefinitions)
121+
&& $this->definitionContainsTraversableTypeHintSpeficication($parametersTypeHintsDefinitions[$parameterName])
122+
&& !$this->definitionContainsItemsSpecificationForTraversable($phpcsFile, $functionPointer, $parametersTypeHintsDefinitions[$parameterName])
123+
)
120124
) {
121125
$phpcsFile->addError(
122126
sprintf(
@@ -277,7 +281,7 @@ private function checkReturnTypeHints(\PHP_CodeSniffer_File $phpcsFile, int $fun
277281
$returnTypeHintDefinition = $hasReturnAnnotation ? preg_split('~\\s+~', $returnAnnotation->getContent())[0] : '';
278282

279283
$traversableTypeHint = false;
280-
if ($returnTypeHint !== null && $this->isTraversableTypeHint($returnTypeHint->getTypeHint())) {
284+
if ($returnTypeHint !== null && $this->isTraversableTypeHint(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $returnTypeHint->getTypeHint()))) {
281285
$traversableTypeHint = true;
282286
} elseif ($hasReturnAnnotation && $this->definitionContainsTraversableTypeHint($phpcsFile, $functionPointer, $returnTypeHintDefinition)) {
283287
$traversableTypeHint = true;
@@ -295,7 +299,10 @@ private function checkReturnTypeHints(\PHP_CodeSniffer_File $phpcsFile, int $fun
295299
self::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION
296300
);
297301
} elseif (($traversableTypeHint && !$this->definitionContainsTraversableTypeHintSpeficication($returnTypeHintDefinition))
298-
|| ($this->definitionContainsTraversableTypeHintSpeficication($returnTypeHintDefinition) && !$this->definitionContainsItemsSpecificationForTraversable($returnTypeHintDefinition))
302+
|| (
303+
$this->definitionContainsTraversableTypeHintSpeficication($returnTypeHintDefinition)
304+
&& !$this->definitionContainsItemsSpecificationForTraversable($phpcsFile, $functionPointer, $returnTypeHintDefinition)
305+
)
299306
) {
300307
$phpcsFile->addError(
301308
sprintf(
@@ -663,7 +670,11 @@ private function checkPropertyTypeHint(\PHP_CodeSniffer_File $phpcsFile, int $pr
663670
$propertyTypeHintDefinition = preg_split('~\\s+~', (string) $varAnnotations[0]->getContent())[0];
664671

665672
if (($this->definitionContainsTraversableTypeHint($phpcsFile, $propertyPointer, $propertyTypeHintDefinition) && !$this->definitionContainsTraversableTypeHintSpeficication($propertyTypeHintDefinition))
666-
|| ($this->definitionContainsTraversableTypeHintSpeficication($propertyTypeHintDefinition) && !$this->definitionContainsItemsSpecificationForTraversable($propertyTypeHintDefinition))) {
673+
|| (
674+
$this->definitionContainsTraversableTypeHintSpeficication($propertyTypeHintDefinition)
675+
&& !$this->definitionContainsItemsSpecificationForTraversable($phpcsFile, $propertyPointer, $propertyTypeHintDefinition)
676+
)
677+
) {
667678
$phpcsFile->addError(
668679
sprintf(
669680
'@var annotation of property %s does not specify type hint for its items.',
@@ -725,11 +736,11 @@ private function definitionContainsTraversableTypeHintSpeficication(string $type
725736
return (bool) preg_match('~\[\](?:\||$)~', $typeHintDefinition);
726737
}
727738

728-
private function definitionContainsItemsSpecificationForTraversable(string $typeHintDefinition): bool
739+
private function definitionContainsItemsSpecificationForTraversable(\PHP_CodeSniffer_File $phpcsFile, int $pointer, string $typeHintDefinition): bool
729740
{
730741
if (preg_match_all('~(?<=^|\|)(.+?)\[\](?=\||$)~', $typeHintDefinition, $matches)) {
731742
foreach ($matches[1] as $typeHint) {
732-
if (!$this->isTraversableTypeHint($typeHint)) {
743+
if (!$this->isTraversableTypeHint(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $pointer, $typeHint))) {
733744
return true;
734745
}
735746
}

tests/Sniffs/TypeHints/TypeHintDeclarationSniffTest.php

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -31,71 +31,75 @@ public function testErrors()
3131
'enableVoidTypeHint' => false,
3232
'traversableTypeHints' => [
3333
\Traversable::class,
34+
'AnyNamespace\Traversable',
3435
],
3536
]);
3637

37-
$this->assertSame(53, $report->getErrorCount());
38-
39-
$this->assertSniffError($report, 8, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
40-
$this->assertSniffError($report, 15, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
41-
$this->assertSniffError($report, 22, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
42-
$this->assertSniffError($report, 29, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
43-
$this->assertSniffError($report, 36, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
44-
$this->assertSniffError($report, 43, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
45-
$this->assertSniffError($report, 119, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
46-
$this->assertSniffError($report, 125, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT, 'Method \FooClass::parametersWithoutTypeHintAndWithAnnotationWithoutParameterName() does not have parameter type hint for its parameter $a but it should be possible to add it based on @param annotation "string".');
47-
$this->assertSniffError($report, 125, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT, 'Method \FooClass::parametersWithoutTypeHintAndWithAnnotationWithoutParameterName() does not have parameter type hint for its parameter $b but it should be possible to add it based on @param annotation "bool|null".');
48-
$this->assertSniffError($report, 134, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
49-
$this->assertSniffError($report, 207, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
50-
51-
$this->assertSniffError($report, 47, TypeHintDeclarationSniff::CODE_MISSING_RETURN_TYPE_HINT);
52-
$this->assertSniffError($report, 55, TypeHintDeclarationSniff::CODE_MISSING_RETURN_TYPE_HINT);
53-
$this->assertSniffError($report, 63, TypeHintDeclarationSniff::CODE_MISSING_RETURN_TYPE_HINT);
54-
$this->assertSniffError($report, 71, TypeHintDeclarationSniff::CODE_MISSING_RETURN_TYPE_HINT);
55-
$this->assertSniffError($report, 79, TypeHintDeclarationSniff::CODE_MISSING_RETURN_TYPE_HINT);
56-
$this->assertSniffError($report, 87, TypeHintDeclarationSniff::CODE_MISSING_RETURN_TYPE_HINT);
57-
$this->assertSniffError($report, 111, TypeHintDeclarationSniff::CODE_MISSING_RETURN_TYPE_HINT);
58-
59-
$this->assertSniffError($report, 15, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
60-
$this->assertSniffError($report, 55, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
61-
$this->assertSniffError($report, 95, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
62-
$this->assertSniffError($report, 102, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
63-
$this->assertSniffError($report, 214, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
64-
$this->assertSniffError($report, 222, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
65-
$this->assertSniffError($report, 230, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
66-
$this->assertSniffError($report, 238, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
67-
$this->assertSniffError($report, 245, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
68-
$this->assertSniffError($report, 252, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
69-
70-
$this->assertSniffError($report, 104, TypeHintDeclarationSniff::CODE_MISSING_PROPERTY_TYPE_HINT);
71-
$this->assertSniffError($report, 106, TypeHintDeclarationSniff::CODE_MISSING_PROPERTY_TYPE_HINT);
72-
73-
$this->assertSniffError($report, 138, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
74-
$this->assertSniffError($report, 143, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
75-
$this->assertSniffError($report, 148, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
76-
$this->assertSniffError($report, 153, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
77-
$this->assertSniffError($report, 161, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
78-
$this->assertSniffError($report, 199, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
79-
$this->assertSniffError($report, 199, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
80-
$this->assertSniffError($report, 266, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
81-
$this->assertSniffError($report, 274, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
82-
$this->assertSniffError($report, 311, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
83-
84-
$this->assertSniffError($report, 166, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
85-
$this->assertSniffError($report, 170, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
86-
$this->assertSniffError($report, 174, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
87-
$this->assertSniffError($report, 179, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
88-
$this->assertSniffError($report, 186, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
89-
$this->assertSniffError($report, 207, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
90-
$this->assertSniffError($report, 282, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
91-
$this->assertSniffError($report, 289, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
92-
$this->assertSniffError($report, 320, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
93-
94-
$this->assertSniffError($report, 191, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PROPERTY_TYPE_HINT_SPECIFICATION);
95-
$this->assertSniffError($report, 194, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PROPERTY_TYPE_HINT_SPECIFICATION);
96-
$this->assertSniffError($report, 296, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PROPERTY_TYPE_HINT_SPECIFICATION);
97-
$this->assertSniffError($report, 301, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PROPERTY_TYPE_HINT_SPECIFICATION);
98-
$this->assertSniffError($report, 306, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PROPERTY_TYPE_HINT_SPECIFICATION);
38+
$this->assertSame(56, $report->getErrorCount());
39+
40+
$this->assertSniffError($report, 9, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
41+
$this->assertSniffError($report, 16, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
42+
$this->assertSniffError($report, 23, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
43+
$this->assertSniffError($report, 30, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
44+
$this->assertSniffError($report, 37, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
45+
$this->assertSniffError($report, 44, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
46+
$this->assertSniffError($report, 120, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
47+
$this->assertSniffError($report, 126, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT, 'Method \FooClass::parametersWithoutTypeHintAndWithAnnotationWithoutParameterName() does not have parameter type hint for its parameter $a but it should be possible to add it based on @param annotation "string".');
48+
$this->assertSniffError($report, 126, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT, 'Method \FooClass::parametersWithoutTypeHintAndWithAnnotationWithoutParameterName() does not have parameter type hint for its parameter $b but it should be possible to add it based on @param annotation "bool|null".');
49+
$this->assertSniffError($report, 135, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
50+
$this->assertSniffError($report, 208, TypeHintDeclarationSniff::CODE_MISSING_PARAMETER_TYPE_HINT);
51+
52+
$this->assertSniffError($report, 48, TypeHintDeclarationSniff::CODE_MISSING_RETURN_TYPE_HINT);
53+
$this->assertSniffError($report, 56, TypeHintDeclarationSniff::CODE_MISSING_RETURN_TYPE_HINT);
54+
$this->assertSniffError($report, 64, TypeHintDeclarationSniff::CODE_MISSING_RETURN_TYPE_HINT);
55+
$this->assertSniffError($report, 72, TypeHintDeclarationSniff::CODE_MISSING_RETURN_TYPE_HINT);
56+
$this->assertSniffError($report, 80, TypeHintDeclarationSniff::CODE_MISSING_RETURN_TYPE_HINT);
57+
$this->assertSniffError($report, 88, TypeHintDeclarationSniff::CODE_MISSING_RETURN_TYPE_HINT);
58+
$this->assertSniffError($report, 112, TypeHintDeclarationSniff::CODE_MISSING_RETURN_TYPE_HINT);
59+
60+
$this->assertSniffError($report, 16, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
61+
$this->assertSniffError($report, 56, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
62+
$this->assertSniffError($report, 96, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
63+
$this->assertSniffError($report, 103, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
64+
$this->assertSniffError($report, 215, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
65+
$this->assertSniffError($report, 223, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
66+
$this->assertSniffError($report, 231, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
67+
$this->assertSniffError($report, 239, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
68+
$this->assertSniffError($report, 246, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
69+
$this->assertSniffError($report, 253, TypeHintDeclarationSniff::CODE_USELESS_DOC_COMMENT);
70+
71+
$this->assertSniffError($report, 105, TypeHintDeclarationSniff::CODE_MISSING_PROPERTY_TYPE_HINT);
72+
$this->assertSniffError($report, 107, TypeHintDeclarationSniff::CODE_MISSING_PROPERTY_TYPE_HINT);
73+
74+
$this->assertSniffError($report, 139, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
75+
$this->assertSniffError($report, 144, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
76+
$this->assertSniffError($report, 149, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
77+
$this->assertSniffError($report, 154, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
78+
$this->assertSniffError($report, 162, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
79+
$this->assertSniffError($report, 200, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
80+
$this->assertSniffError($report, 200, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
81+
$this->assertSniffError($report, 267, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
82+
$this->assertSniffError($report, 275, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
83+
$this->assertSniffError($report, 312, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
84+
$this->assertSniffError($report, 325, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_RETURN_TYPE_HINT_SPECIFICATION);
85+
86+
$this->assertSniffError($report, 167, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
87+
$this->assertSniffError($report, 171, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
88+
$this->assertSniffError($report, 175, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
89+
$this->assertSniffError($report, 180, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
90+
$this->assertSniffError($report, 187, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
91+
$this->assertSniffError($report, 208, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
92+
$this->assertSniffError($report, 283, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
93+
$this->assertSniffError($report, 290, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
94+
$this->assertSniffError($report, 321, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
95+
$this->assertSniffError($report, 330, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PARAMETER_TYPE_HINT_SPECIFICATION);
96+
97+
$this->assertSniffError($report, 192, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PROPERTY_TYPE_HINT_SPECIFICATION);
98+
$this->assertSniffError($report, 195, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PROPERTY_TYPE_HINT_SPECIFICATION);
99+
$this->assertSniffError($report, 297, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PROPERTY_TYPE_HINT_SPECIFICATION);
100+
$this->assertSniffError($report, 302, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PROPERTY_TYPE_HINT_SPECIFICATION);
101+
$this->assertSniffError($report, 307, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PROPERTY_TYPE_HINT_SPECIFICATION);
102+
$this->assertSniffError($report, 336, TypeHintDeclarationSniff::CODE_MISSING_TRAVERSABLE_PROPERTY_TYPE_HINT_SPECIFICATION);
99103
}
100104

101105
public function testVoidAndIterable()

tests/Sniffs/TypeHints/data/typeHintDeclarationErrors.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use AnyNamespace\Anything;
4+
use AnyNamespace\Traversable;
45

56
abstract class FooClass
67
{
@@ -321,4 +322,17 @@ private function nullableMultidimensionalArrayParameter($a)
321322
{
322323
}
323324

325+
private function returnUsedTraversable(): Traversable
326+
{
327+
328+
}
329+
330+
public function usedTraversableParameter(Traversable $a)
331+
{
332+
333+
}
334+
335+
/** @var Traversable[] */
336+
private $usedTraversable = [];
337+
324338
}

0 commit comments

Comments
 (0)