我正在寻找 PHPCodeSniffer 规则来限制每个函数/方法的最大代码行数。
function something($b) {
// some comment that should be ignored in the count
$a = 12;
$value = sqrt(
$a * $b
);
return $value;
}
我希望将上述函数计为有 5 行编码(不包括注释和空行)。
我正在寻找 PHPCodeSniffer 规则来限制每个函数/方法的最大代码行数。
function something($b) {
// some comment that should be ignored in the count
$a = 12;
$value = sqrt(
$a * $b
);
return $value;
}
我希望将上述函数计为有 5 行编码(不包括注释和空行)。
我认为 PHPCodeSniffer (phpcs) 没有“代码行”的标准规则,我所能想到的就是使用另一个指标,例如 McCabe Cyclomatic Complexity(这包括在 Sniff 中Generic.Metrics.CyclomaticComplexity
)。它不一样,但高价值是杂乱代码的指标。
如果您愿意使用另一个名为PHP Mess Detector (phpmd)的工具,您可以使用该ExcessiveMethodLength
规则来跟踪方法的最大长度。