phpstorm 및 Intellij 아이디어에 대한 정적 코드 분석.
IDE OPE Settings->Plugins->Marketplace PhpClean 검색으로 이동하십시오. install 버튼을 누르십시오.
- 검사
- 행동
한 명령문에서 할당 및 비교 연산자를 감지합니다.
while ( false !== $ current = ldap_next_entry ( $ con , $ current )) {
// ^^^ Hard to read this statements
yield $ this -> getSingleEntry ( $ con , $ current );
}다른 네임 스페이스에 동일한 이름을 가진 클래스는 혼란 스러울 수 있습니다. (기본적으로 비활성화)
namespace App {
class User {}; // <- Class name collision with CliUser
}
namespace Cli {
class User {}; // <- Class name collision with AppUser
}프로젝트에서 일부 PHPDOC 태그를 더 이상 사용하지 못할 수 있습니다.
이 검사는 글로벌 변수의 사용법을 감지합니다.
echo $ _GET [ ' name ' ]; // <-- Global variable usage 보호 된 방법은 비공개로 변환 할 수 있습니다.
final class User {
protected function name () {} // <-- Method can be private
}방법을 닫아야합니다 (메소드 또는 클래스 최종 결승)
class User {
public function name (): string { // <-- Method should be final
return '' ;
}
}보호 된 방법은 수업을보다 개방적으로 만듭니다. 개인 또는 공개 방법 만 작성하십시오.
항상 매개 변수 유형을 지정합니다. 이것은 좋은 연습입니다.
class User {
public function withName ( $ name ) {} // <-- Missing parameter type
}항상 함수의 결과 유형을 지정하십시오.
function phrase () { // <-- Missing return type
return ' hi ' ;
}부모 속성이 더 이상 사용되지 않는지 확인하십시오.
class A {
/** @deprecated */
protected $ name ;
}
class B extends A {
protected $ name ; // <-- Warn about deprecation
} @final doc 태그로 표시된 클래스를 확장해서는 안됩니다.
/**
* @final
*/
class User {};
class Admin extends User {}; // <- Prohibited extentions of @final class User. 생성자에서 초기화되지 않은 속성은 무일치로 주석을 달아야합니다.
class User {
/** @var string */ // <-- Property is not annotated correctly. Add null type
private $ name ;
public function getName () { }
public function setName ( string $ name ) { }
}보호 특성은 비공개로 변환 할 수 있습니다.
class User {
protected $ user ; // <-- Property can be private
} PHP에 지정된 유형은 PHPDOC 블록에서 생략 할 수 있습니다.
/**
* @return void // <-- Redundant PhpDoc tag
*/
function show ( string $ message ): void {}자동 유형 주조를 감지합니다
class Hello {
public function randomize (): self { /* ... */ return $ this ; }
public function __toString () { return ' Hi ' ; }
}
echo ( new Hello ())-> randomize (); // <-- Deprecated __toString call Doc 댓글 대신 가변 유형을 확인하려면 Assert를 사용하십시오.
/** @var User $user */ // <-- Use assert to check variable type
assert ( $ user instanceof User); new ClassName() 선택한 이름의 생성자로 바꾸십시오.
class Text {
public function __construct ( string $ name ){ }
public static fromName (string $ n ){}
} 메소드 이름에서 fromName 에서 refactor this 호출하면이 클래스의 모든 새 문장이 변경됩니다.
new Text ( ' User ' ) // old code
Text:: fromName ( ' User ' ) // new code