Skip to content

Commit 5e6947c

Browse files
committed
Bail out on #[Override]
- `SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification`: do not report missing native type hint when method has `#[Override]` attribute. - `SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingAnyTypeHint`: do not report missing native type hint when method has `#[Override]` attribute. This time I took a more holistic approach and search for occurrences of `DocCommentHelper::hasInheritdocAnnotation`, and checked if there was a similar check for the override attribute.
1 parent 4ef8e3e commit 5e6947c

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

SlevomatCodingStandard/Sniffs/TypeHints/ParameterTypeHintSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ public function process(File $phpcsFile, int $functionPointer): void
111111
return;
112112
}
113113

114+
if (AttributeHelper::hasAttribute($phpcsFile, $functionPointer, '\Override')) {
115+
return;
116+
}
117+
114118
if (DocCommentHelper::hasInheritdocAnnotation($phpcsFile, $functionPointer)) {
115119
return;
116120
}

SlevomatCodingStandard/Sniffs/TypeHints/PropertyTypeHintSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ public function process(File $phpcsFile, int $pointer): void
144144
return;
145145
}
146146

147+
if (AttributeHelper::hasAttribute($phpcsFile, $propertyPointer, '\Override')) {
148+
return;
149+
}
150+
147151
$docCommentOpenPointer = DocCommentHelper::findDocCommentOpenPointer($phpcsFile, $propertyPointer);
148152
if ($docCommentOpenPointer !== null) {
149153
if (DocCommentHelper::hasInheritdocAnnotation($phpcsFile, $docCommentOpenPointer)) {

tests/Sniffs/TypeHints/data/parameterTypeHintNoErrors.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ class ParentClass
88

99
/**
1010
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint
11+
* @param array{} $b
1112
*/
12-
public function overrideAttribute($a): void
13+
public function overrideAttribute($a, array $b): void
1314
{
1415
}
1516

@@ -293,7 +294,7 @@ public function brokenParameterDescription(int $a, array $b)
293294
* @param bool $a
294295
*/
295296
#[Override]
296-
public function overrideAttribute($a): void
297+
public function overrideAttribute($a, array $b): void
297298
{
298299
}
299300

tests/Sniffs/TypeHints/data/propertyTypeHintEnabledNativeNoErrors.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,6 @@ class Whatever extends ParentClass
200200
*/
201201
public WeakMap $objectShapeInItems;
202202

203-
/**
204-
* @var string[]
205-
*/
206203
#[Override]
207204
public $arrayTypeHint = ['hello'];
208205

0 commit comments

Comments
 (0)