1.2.997. Property Could Be Local¶
A property only used in one method may be turned into a local variable.
Public an protected properties are omitted here : they may be modified somewhere else, in the code. This analysis may be upgraded to support those properties, when tracking of such properties becomes available.
Classes where only one non-magic method is available are omitted.
Traits with private properties are processed the same way.
<?php
class x {
private $foo = 1;
// Magic method, and constructor in particular, are omitted.
function __construct($foo) {
$this->foo = $foo;
}
function bar() {
$this->foo++;
return $this->foo;
}
function barbar() {}
}
?>
1.2.997.1. Suggestions¶
Remove the property and make it an argument in the method
Use that property elsewhere
1.2.997.2. Specs¶
Short name |
Classes/PropertyCouldBeLocal |
Rulesets |
|
Exakat since |
1.1.7 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Features |
property |
Examples |
|
Available in |