Skip to content

EmptyClass ​

info off by default

Group: Architecture · PhpStorm name: EmptyClassInspection

A named class (or trait, or enum) that declares nothing at all — no properties, constants, methods, used traits or enum cases — is usually dead weight or an unfinished stub.

Example ​

php
<?php
class HasState  { private $count = 0; }
class HasLimit  { const MAX = 10; }
class HasAction { public function go() {} }
trait Greets    { public function hi() {} }
class UsesTrait { use Greets; }
interface Marker {}

class Placeholder {}
class Tagged implements Marker {}
trait Blank {}
enum Mood {}
enum Size { case Small; }

class ParseFailure extends \InvalidArgumentException {}
abstract class Shape { abstract public function area(); }
class Dot extends Shape {}
/** @deprecated use HasState */
class OldStub {}
class Fatal extends \Error {}
$x = new class {};

Reported:

  • line 9: This class declares no members; remove it or give it a purpose.
  • line 10: This class declares no members; remove it or give it a purpose.
  • line 11: This class declares no members; remove it or give it a purpose.
  • line 12: This enum declares no cases or methods.
  • line 20: This class declares no members; remove it or give it a purpose.

Configure ​

In custos.json:

json
{
  "rules": {
    "EmptyClass": {
      "enabled": true
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file), either of:

php
// @custos-ignore EmptyClass

/**
 * @noinspection EmptyClassInspection
 */

Released under the MIT License. Rule catalogue modelled on Php Inspections (EA Extended); independent clean-room implementation.