andrew-demb / PhpClean

Static Code Analysis for PhpStorm and Intellij Idea.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PhpClean - PhpStorm/IDEA plugin

Version Downloads License

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)

List of inspection:

AssignMisused

Detects assignment and comparison operators in one statement.

do{
 //...
}while( false == $user->getName() = self::ADMIN_USER );
 // ^^^ Hard to read this statements

ClassNameCollision

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

namespace App {
  class User{}; // <- Class name collision with \Cli\User
}
namespace Cli {
  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']; // <-- Deprecated global variable usage

MethodCanBePrivate

Protected methods can be converted to private.

final class User {
  protected function name() {} // <-- Method can be private
}

MethodShouldBeFinal

Methods should be closed (make method or class final)

class User {
 public function name() : string { // <-- Method should be final
   return "";
 }
}

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{
 function withName($name){}  // <-- Missing parameter type
}

MissingReturnType

Always specify result type of the function.

function phrase(){ // <-- Missing return type
    return 'hi';
}

ParentPropertyDeprecated

Check if parent property is deprecated.

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

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 type
 private $name;
 public function getName(){  }
 public function setName(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
 */
 function show(string $message):void {}

ToStringCall

Detect automatic type casting

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

VirtualTypeCheck

Use assert to check variable type instead of doc comment.

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

About

Static Code Analysis for PhpStorm and Intellij Idea.

License:MIT License


Languages

Language:Kotlin 96.8%Language:HTML 3.2%