Skip to content

Commit 7658613

Browse files
committed
Ignore doc bloc lines for function lines
1 parent 90c3a7a commit 7658613

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

Inpsyde/Sniffs/CodeQuality/FunctionLengthSniff.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ final class FunctionLengthSniff implements Sniff
2929
*/
3030
public $maxLength = 50;
3131

32+
/**
33+
* @var true
34+
*/
35+
public $ignoreDocBlocks = true;
36+
3237
/**
3338
* @return int[]
3439
*/
@@ -72,7 +77,25 @@ public function getStructureLengthInLines(File $file, int $position): int
7277
return 0;
7378
}
7479

75-
return ($tokens[$token['scope_closer']]['line'] ?? 0)
76-
- ($tokens[$token['scope_opener']]['line'] ?? 0);
80+
$opener = $token['scope_opener'];
81+
$closer = $token['scope_closer'];
82+
$length = $tokens[$closer]['line'] - $tokens[$opener]['line'];
83+
84+
if (!$this->ignoreDocBlocks) {
85+
return $length;
86+
}
87+
88+
$decrease = 0;
89+
for ($i = $opener + 1; $i < $closer; $i++) {
90+
if ($tokens[$i]['code'] === T_DOC_COMMENT_OPEN_TAG) {
91+
$openerLine = (int)$tokens[$i]['line'];
92+
$closer = $tokens[$i]['comment_closer'] ?? null;
93+
$decrease += is_numeric($closer)
94+
? (int)$tokens[$closer]['line'] - ($openerLine - 1)
95+
: 1;
96+
}
97+
}
98+
99+
return max(0, $length - $decrease);
77100
}
78101
}

0 commit comments

Comments
 (0)