1.2.1354. Use This

Those methods should be using $this, or a static method or property.

A method that doesn’t use any local data may be considered for a move : may be it doesn’t belong here.

The following functioncalls have been added, as access to the current class, without using $this or self :

<?php

class dog {
    private $name = 'Rex';

    // This method is related to the current object and class
    public function attaboy() {
        return Fetch, $this->name, Fetch\n;
    }

    // Not using any class related data : Does this belong here?
    public function addition($a, $b) {
        return $a + $b;
    }
}
?>

See also The Basics.

1.2.1354.1. Connex PHP features

1.2.1354.1.1. Suggestions

  • Add any use of $this pseudo-variable

  • Move the method to another class

  • Refactor the method as a function

1.2.1354.1.2. Specs

Short name

Classes/UseThis

Rulesets

All, Changed Behavior

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Slow (1 hour)

Precision

High

Available in

Entreprise Edition, Exakat Cloud