Skip to content

SenselessProxyMethod ​

warning on by default quick-fix

Group: Unused · PhpStorm name: SenselessProxyMethodInspection

An override whose only statement forwards its parameters unchanged to the same-named parent method — with the same signature, modifiers and documentation tags — adds nothing; inheritance already provides that behaviour. Remove it.

Example ​

php
<?php
class Store
{
    protected function __construct($cfg = []) {}

    public function put($key, $value = 0) { return true; }

    public function get($key) {}

    public function drop($key) {}

    public function tag($key) {}

    /**
     * @api
     */
    public function flush($all) {}

    public function label($text = __CLASS__) {}

    public function size(): int { return 0; }

    public function keys(array $filter) { return []; }

    public static function make() {}
}

class DiskStore extends Store
{
    public function __construct($cfg = [])
    {
        parent::__construct($cfg);
    }

    /** Disk variant. */
    public function put($k, $v = 0)
    {
        return parent::put($k, $v);
    }

    public function get($key)
    {
        // just delegate
        parent::get($key);
    }

    public function drop($key)
    {
        parent::drop(trim($key));
    }

    /**
     * @internal
     */
    public function tag($key)
    {
        parent::tag($key);
    }

    /**
     * @api
     */
    public function flush($all)
    {
        parent::flush($all);
    }

    public function label($text = __CLASS__)
    {
        parent::label($text);
    }

    public function size(): ?int
    {
        return parent::size();
    }

    public function keys($filter)
    {
        return parent::keys($filter);
    }

    #[Cached]
    public static function make()
    {
        parent::make();
    }
}
php
<?php
class Store
{
    protected function __construct($cfg = []) {}

    public function put($key, $value = 0) { return true; }

    public function get($key) {}

    public function drop($key) {}

    public function tag($key) {}

    /**
     * @api
     */
    public function flush($all) {}

    public function label($text = __CLASS__) {}

    public function size(): int { return 0; }

    public function keys(array $filter) { return []; }

    public static function make() {}
}

class DiskStore extends Store
{
    public function __construct($cfg = [])
    {
        parent::__construct($cfg);
    }

    public function drop($key)
    {
        parent::drop(trim($key));
    }

    /**
     * @internal
     */
    public function tag($key)
    {
        parent::tag($key);
    }

    public function label($text = __CLASS__)
    {
        parent::label($text);
    }

    public function size(): ?int
    {
        return parent::size();
    }

    public function keys($filter)
    {
        return parent::keys($filter);
    }

    #[Cached]
    public static function make()
    {
        parent::make();
    }
}

Reported:

  • line 36: Method 'put' only forwards to its parent; remove it.
  • line 41: Method 'get' only forwards to its parent; remove it.
  • line 63: Method 'flush' only forwards to its parent; remove it.

Configure ​

In custos.json:

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

Suppress ​

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

php
// @custos-ignore SenselessProxyMethod

/**
 * @noinspection SenselessProxyMethodInspection
 */

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