Skip to content

Repository files navigation

PhpClean - PhpStorm/IDEA plugin

VersionDownloadsLicense

Static Code Analysis for PhpStorm and Intellij Idea.

Installation

Open IDE go to Settings->Plugins->Marketplace search for the PhpClean. Hit install button.

GitHub commits (since latest release)

- Inspections

- Actions

Inspections

AssignMisused

Detects assignment and comparison operators in one statement.

while (false !== $current = ldap_next_entry($con, $current)) {
// ^^^ Hard to read this statementsyield$this->getSingleEntry($con, $current);
}

ClassNameCollision

Classes with same name in different namespaces can be confused. (Disabled by default)

namespaceApp {
class User {}; // <- Class name collision with \Cli\User
}
namespaceCli {
class User {}; // <- Class name collision with \App\User
}

DeprecatedDocTag

You can deprecate some PhpDoc tags in your project.

GlobalVariableUsage

This inspection detects usages of global variables.

echo$_GET['name']; // <-- Global variable usage

MethodCanBePrivate

Protected methods can be converted to private.

finalclass User {
protectedfunctionname() {} // <-- Method can be private
}

MethodShouldBeFinal

Methods should be closed (make method or class final)

class User {
publicfunctionname(): string { // <-- Method should be finalreturn'';
}
}

MethodVisibility

Protected methods make our classes more open. Write private or public methods only.

MissingParameterTypeDeclaration

Always specify parameter type. This is a good practice.

class User {
publicfunctionwithName($name) {} // <-- Missing parameter type
}

MissingReturnType

Always specify result type of the function.

functionphrase() { // <-- Missing return typereturn'hi';
}

ParentPropertyDeprecated

Check if parent property is deprecated.

class A {
/** @deprecated */protected$name;
}
class B extends A {
protected$name; // <-- Warn about deprecation
}

ProhibitedClassExtend

Classes marked with @final doc tag should not be extended

/** * @final */class User {};
class Admin extends User {}; // <- Prohibited extentions of @final class User.

PropertyAnnotation

Properties that are not initialized in the constructor should be annotated as nullable.

class User {
/** @var string */// <-- Property is not annotated correctly. Add null typeprivate$name;
publicfunctiongetName() { }
publicfunctionsetName(string$name) { }
}

PropertyCanBePrivate

Protected properties can be converted to private.

class User {
protected$user; // <-- Property can be private
}

RedundantDocCommentTag

Types that are specified in the php can be omitted in the PhpDoc blocks

/** * @return void // <-- Redundant PhpDoc tag */functionshow(string$message): void {}

ToStringCall

Detect automatic type casting

class Hello {
publicfunctionrandomize(): self { /* ... */return$this; }
publicfunction__toString() { return'Hi'; }
}
echo (newHello())->randomize(); // <-- Deprecated __toString call

VirtualTypeCheck

Use assert to check variable type instead of doc comment.

/** @var User $user */// <-- Use assert to check variable typeassert($userinstanceof User);

Actions

UseNamedConstructor

Replace new ClassName() with selected named constructor.

class Text {
publicfunction__construct(string$name){ }
publicstaticfromName(string $n){}
}

Invoke refactor this on method name fromName and all new statements with this class will be changed

newText('User') // old code
Text::fromName('User') // new code

About

Static Code Analysis for PhpStorm and Intellij Idea.

Topics

Resources

Stars

85 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages