1.2.264. Could Be Protected Method

Those methods are declared ‘public’, but are never used publicly. They may be made ‘protected’.

These properties may even be made private.

<?php

class foo {
    // Public, and used publicly
    public publicMethod() {}

    // Public, but never used outside the class or its children
    public protectedMethod() {}

    private function bar() {
        $this->protectedMethod();
    }
}

$foo = new Foo();
$foo->publicMethod();

?>

1.2.264.1. Suggestions

  • Use protected visibility with these methods.

1.2.264.2. Specs

Short name

Classes/CouldBeProtectedMethod

Rulesets

All, Changed Behavior, Class Review

Exakat since

0.12.11

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

visibility, method

Available in

Entreprise Edition, Exakat Cloud