coding-standard
coding-standard copied to clipboard
Correct indent inside block, comments - feature request/question
I have noticed there is no sniff that would handle correct indentation inside a block or comments etc. Or am I wrong and there is a sniff that would handle those situations?
There are sniffs for bad indentation of closing braces, inside arrays, etc. But not for this, as far as I know.
16 spaces instead of 4
if (!App::isProduction()) {
return;
}
Bad indentation of doc block
class HealthChecksService
{
/**
* @param int|string $exitStatus
*/
public function exitStatus(
string $checkName,
$exitStatus,
?string $log = null,
int $retry = 3,
float $timeout = 3
): void {
$this->makeRequest("$exitStatus", $checkName, $log, $retry, $timeout);
}
}
I think it's solved by Generic.WhiteSpace.ScopeIndent
I thought too, but it is not. I created file below and run Code Sniffer. This is result with 2 errors, but there are much more indent errors in the code.
./vendor/bin/phpcs --sniffs=Generic.WhiteSpace.ScopeIndent ./indent.php
E 1 / 1 (100%)
FILE: indent.php
------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
------------------------------------------------------------------------------------------------------------------------
18 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
| | (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
29 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4
| | (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------
Time: 87ms; Memory: 14MB
<?php
function add($a, $b)
{
$ret = $a + $b;
return $ret;
}
class Math
{
/**
* Perform addition
*/
public function add($a, $b)
{
$ret = $a + $b;
return $ret;
} // <-- Line 18
/**
* Perform subtraction
*/
public function sub($a, $b)
{
$ret = $a - $b;
return $ret;
}
} // <-- Line 29