Skip to content

ClassReImplementsParentInterface ​

warning on by default quick-fix

Group: Architecture · PhpStorm name: ClassReImplementsParentInterfaceInspection

Listing an interface in implements when the parent class already implements it (directly or through its own ancestors) is redundant noise. Remove the entry.

Example ​

php
<?php
namespace Store {
    use Countable as Sized;

    interface Readable {}
    interface Seekable extends Readable {}
    abstract class Stream implements Readable {}
    abstract class FileStream implements Seekable, \Countable {}

    class Socket extends Stream
        implements
            Readable {}

    class Disk extends FileStream implements Readable, Sized {}

    class Tape extends FileStream implements \JsonSerializable, Seekable {
        public function jsonSerialize(): mixed { return null; }
        public function count(): int { return 0; }
    }

    class Pipe extends Stream implements Seekable {}
    class Loose implements Readable, Seekable {}
}
php
<?php
namespace Store {
    use Countable as Sized;

    interface Readable {}
    interface Seekable extends Readable {}
    abstract class Stream implements Readable {}
    abstract class FileStream implements Seekable, \Countable {}

    class Socket extends Stream
        {}

    class Disk extends FileStream {}

    class Tape extends FileStream implements \JsonSerializable {
        public function jsonSerialize(): mixed { return null; }
        public function count(): int { return 0; }
    }

    class Pipe extends Stream implements Seekable {}
    class Loose implements Readable, Seekable {}
}

Reported:

  • line 12: '\Store\Readable' is already implemented by '\Store\Stream'; remove it here.
  • line 14: '\Store\Readable' is already implemented by '\Store\FileStream'; remove it here.
  • line 14: '\Countable' is already implemented by '\Store\FileStream'; remove it here.
  • line 16: '\Store\Seekable' is already implemented by '\Store\FileStream'; remove it here.

Configure ​

In custos.json:

json
{
  "rules": {
    "ClassReImplementsParentInterface": {
      "enabled": false
    }
  }
}

Suppress ​

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

php
// @custos-ignore ClassReImplementsParentInterface

/**
 * @noinspection ClassReImplementsParentInterfaceInspection
 */

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