Skip to content

Commit 1734e86

Browse files
greg0irekukulich
authored andcommitted
Bail out on #[Override]
SlevomatCodingStandard.TypeHints.ReturnTypeHint: do not report missing native type hint when method has #[Override] attribute. Same as cda88e6 but for return type declarations.
1 parent 90b6881 commit 1734e86

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

SlevomatCodingStandard/Sniffs/TypeHints/ReturnTypeHintSniff.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use SlevomatCodingStandard\Helpers\Annotation;
2020
use SlevomatCodingStandard\Helpers\AnnotationHelper;
2121
use SlevomatCodingStandard\Helpers\AnnotationTypeHelper;
22+
use SlevomatCodingStandard\Helpers\AttributeHelper;
2223
use SlevomatCodingStandard\Helpers\DocCommentHelper;
2324
use SlevomatCodingStandard\Helpers\FixerHelper;
2425
use SlevomatCodingStandard\Helpers\FunctionHelper;
@@ -109,6 +110,10 @@ public function process(File $phpcsFile, int $pointer): void
109110
return;
110111
}
111112

113+
if (AttributeHelper::hasAttribute($phpcsFile, $pointer, '\Override')) {
114+
return;
115+
}
116+
112117
if (DocCommentHelper::hasInheritdocAnnotation($phpcsFile, $pointer)) {
113118
return;
114119
}

tests/Sniffs/TypeHints/data/returnTypeHintNoErrors.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
<?php // lint >= 8.0
22

3-
abstract class Whatever
3+
use Override;
4+
5+
interface FloatsYourBoat
46
{
7+
/** @return array{} */
8+
public function overrideAttribute(): array;
9+
}
510

11+
abstract class Whatever implements FloatsYourBoat
12+
{
613
public function __construct()
714
{
815
}
@@ -87,6 +94,12 @@ private function noTraversableType(): int
8794
return 0;
8895
}
8996

97+
#[Override]
98+
public function overrideAttribute(): array
99+
{
100+
return [];
101+
}
102+
90103
/**
91104
* @return int[]
92105
*/

0 commit comments

Comments
 (0)