Skip to content

AccessModifierPresented ​

info on by default quick-fix

Group: Code style · PhpStorm name: AccessModifierPresentedInspection

Class members that rely on PHP's implicit public visibility (methods declared with no visibility keyword, properties declared with var/static/readonly only, constants declared with a bare const) should spell out their visibility explicitly so intent is clear to readers.

Example ​

php
<?php

class Invoice
{
    var $total;
    static $registry = [];
    readonly int $number;
    protected $lines;
    private(set) string $currency;

    function render() {}
    final static function make() {}
    public function save() {}
}

abstract class Shape
{
    abstract function area();
}

interface Printable
{
    function printOut();
}
php
<?php

class Invoice
{
    public $total;
    public static $registry = [];
    public readonly int $number;
    protected $lines;
    private(set) string $currency;

    public function render() {}
    final public static function make() {}
    public function save() {}
}

abstract class Shape
{
    abstract public function area();
}

interface Printable
{
    public function printOut();
}

Reported:

  • line 5: Declare the visibility of 'total' explicitly.
  • line 6: Declare the visibility of 'registry' explicitly.
  • line 7: Declare the visibility of 'number' explicitly.
  • line 11: Declare the visibility of 'render' explicitly.
  • line 12: Declare the visibility of 'make' explicitly.
  • line 18: Declare the visibility of 'area' explicitly.
  • line 23: Declare the visibility of 'printOut' explicitly.

Options ​

OptionTypeDefaultEffect
ANALYZE_INTERFACESbooltrueWhen false, interface declarations are not inspected at all.
ANALYZE_CONSTANTSbooltrueWhen false, class constants are never reported (D3 disabled).

Configure ​

In custos.json:

json
{
  "rules": {
    "AccessModifierPresented": {
      "enabled": false,
      "options": {
        "ANALYZE_INTERFACES": true,
        "ANALYZE_CONSTANTS": true
      }
    }
  }
}

Suppress ​

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

php
// @custos-ignore AccessModifierPresented

/**
 * @noinspection AccessModifierPresentedInspection
 */

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