을 구성하는 방법 PHP CodeSniffer 을 허용하는 경우 내의 문을 들여쓰기를 내가 좋아하는 방법은?
-
11-12-2019 - |
문제
나는 코드는 다음과 같습니다.
function processRequest() {
// get the verb
$method = strtolower($_SERVER['REQUEST_METHOD']);
switch ($method) {
case 'get':
handleGet();
break;
case 'post':
handlePost();
// $data = $_POST;
break;
case 'delete':
handleDelete();
break;
case 'options':
header('Allow: GET, POST, DELETE, OPTIONS');
break;
default:
header('HTTP/1.1 405 Method Not Allowed');
break;
}
}
PHP CodeSniffer 에 대해 불평 들여쓰기들의 경우는 문입니다.에서 이맥스와 flymake 그것은 다음과 같습니다:
메시지는 다음과 같습니다.
러 라인 들여 잘못;예상 2 개의 공간,발견 4(배입니다.WhiteSpace.ScopeIndent.잘못)
분명히 CodeSniffer 원하는 경우 문장을 덜 들여보다 그들이 있습니다.
어떻게 알 수 있습니 CodeSniffer 을 허용하는 경우 내의 문을 들여쓰기를 내가 원하는 방식으로 그들을.또는 더 나은, 강제 적용 는 경우 문 들여 이 방법은?
해결책
냄새를 맡으로 알려져 PEAR.Whitespace.ScopeIndent
정의된 코드에서 파일 phpcs\CodeSniffer\Standards\PEAR\Sniffs\Whitespace\ScopeIndentSniff.php
과는 다음과 같은 코드를 포함합니다:
class PEAR_Sniffs_WhiteSpace_ScopeIndentSniff extends Generic_Sniffs_WhiteSpace_ScopeIndentSniff
{
/**
* Any scope openers that should not cause an indent.
*
* @var array(int)
*/
protected $nonIndentingScopes = array(T_SWITCH);
}//end class
보 $nonIndentingScopes
?그것은 분명히는 아무것도 범위 내에서 스위치 문의 예 지 들여쓰기와 존경의 범위-오픈 곱슬입니다.
나는 방법을 찾을 수 없습을 조정할 이 설정에서 PEAR.Whitespace.ScopeIndent
, 지만.......는 냄새를 확장하는 기본적인 Generic.Whitespace.ScopeIndent
, 을 포함하지 않는 T_SWITCH
에 $nonIndentingScopes
배열입니다.
그래서 무엇을 했는지를 허용하는 경우 내 계산서 내가 원하는 대로 수정 나 ruleset.xml 파일을 제외 배 버전의 냄새,그리고 포함은 일반 버전에는 냄새.그것은 다음과 같습니다:
<?xml version="1.0"?>
<ruleset name="Custom Standard">
<!-- http://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php -->
<description>My custom coding standard</description>
<rule ref="PEAR">
......
<exclude name="PEAR.WhiteSpace.ScopeIndent"/>
</rule>
....
<!-- not PEAR -->
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="2"/>
</properties>
</rule>
</ruleset>
이 파일에 있어야 합 a subdir 아래 기준에 대한 디렉토리 PHP CodeSniffer.나를 위해,파일 위치 \dev\phpcs\CodeSniffer\Standards\MyStandard\ruleset.xml
그때 실 phpcs 다음과 같다:
\php\php.exe \dev\phpcs\scripts\phpcs --standard=MyStandard --report=emacs -s file.php