Skip to content

Commit 86143b3

Browse files
committed
Fix up tests.
1 parent dbb802b commit 86143b3

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

PhpCollective/Sniffs/Commenting/DocBlockReturnVoidSniff.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class DocBlockReturnVoidSniff extends AbstractSniff
2020
{
2121
use CommentingTrait;
2222

23+
public bool $strict = false;
24+
2325
/**
2426
* @var array<string>
2527
*/
@@ -75,15 +77,15 @@ public function process(File $phpcsFile, $stackPtr): void
7577

7678
// If interface we will at least report it
7779
if (empty($tokens[$stackPtr]['scope_opener']) || empty($tokens[$stackPtr]['scope_closer'])) {
78-
if (!$docBlockReturnIndex && !$hasInheritDoc && !$hasReturnType) {
80+
if (!$docBlockReturnIndex && !$hasInheritDoc && (!$hasReturnType || $this->strict)) {
7981
$phpcsFile->addError('Method does not have a return statement in doc block: ' . $tokens[$nextIndex]['content'], $nextIndex, 'ReturnMissingInInterface');
8082
}
8183

8284
return;
8385
}
8486

8587
// If inheritDoc is present assume the parent contains it
86-
if (!$docBlockReturnIndex && ($hasInheritDoc || $this->hasReturnType($phpcsFile, $stackPtr))) {
88+
if (!$docBlockReturnIndex && ($hasInheritDoc || $hasReturnType && !$this->strict)) {
8789
return;
8890
}
8991

tests/PhpCollective/Sniffs/Commenting/DocBlockReturnVoidSniffTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ class DocBlockReturnVoidSniffTest extends TestCase
1717
*/
1818
public function testDocBlockReturnVoidSniffer(): void
1919
{
20-
$this->assertSnifferFindsFixableErrors(new DocBlockReturnVoidSniff(), 3, 3);
20+
$sniff = new DocBlockReturnVoidSniff();
21+
$sniff->strict = true;
22+
$this->assertSnifferFindsFixableErrors($sniff, 3, 3);
2123
}
2224

2325
/**
2426
* @return void
2527
*/
2628
public function testDocBlockReturnVoidFixer(): void
2729
{
28-
$this->assertSnifferCanFixErrors(new DocBlockReturnVoidSniff(), 3);
30+
$sniff = new DocBlockReturnVoidSniff();
31+
$sniff->strict = true;
32+
$this->assertSnifferCanFixErrors($sniff, 3);
2933
}
3034
}

0 commit comments

Comments
 (0)