Skip to content

MisorderedModifiers ​

info on by default quick-fix

Group: Code style · PhpStorm name: MisorderedModifiersInspection

PSR-1/PSR-12 style expects method modifiers in a fixed order: final / abstract first, then the visibility, then static. Methods whose modifiers are written in another order are flagged and re-sorted.

Example ​

php
<?php

interface Registry
{
    static public function instance();
    public static function reset();
}

abstract class Repository
{
    public static function boot() {}
    abstract protected function table();
    final static function hash() {}
    protected
        static function cache() {}
    PRIVATE STATIC function lower() {}

    protected abstract function columns();
    static
        protected final function guard() {}
    Static Private Final function seal() {}
    public static abstract function make();
}
php
<?php

interface Registry
{
    public static function instance();
    public static function reset();
}

abstract class Repository
{
    public static function boot() {}
    abstract protected function table();
    final static function hash() {}
    protected
        static function cache() {}
    PRIVATE STATIC function lower() {}

    abstract protected function columns();
    final protected static function guard() {}
    final private static function seal() {}
    abstract public static function make();
}

Reported:

  • line 5: Reorder modifiers as: public static.
  • line 18: Reorder modifiers as: abstract protected.
  • line 19: Reorder modifiers as: final protected static.
  • line 21: Reorder modifiers as: final private static.
  • line 22: Reorder modifiers as: abstract public static.

Options ​

OptionTypeDefaultEffect

Configure ​

In custos.json:

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

Suppress ​

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

php
// @custos-ignore MisorderedModifiers

/**
 * @noinspection MisorderedModifiersInspection
 */

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