1.2.1005. Property Could Be Private¶
The following properties are never used outside their class of definition. Given the analyzed code, they could be set as private. Note that dynamic properties (such as $x->$y) are not taken into account.
<?php
class foo {
public $couldBePrivate = 1;
public $cantdBePrivate = 1;
function bar() {
// couldBePrivate is used internally.
$this->couldBePrivate = 3;
}
}
class foo2 extends foo {
function bar2() {
// cantdBePrivate is used in a child class.
$this->cantdBePrivate = 3;
}
}
//$couldBePrivate is not used outside
$foo = new foo();
//$cantdBePrivate is used outside the class
$foo->cantdBePrivate = 2;
?>
1.2.1005.1. Connex PHP features¶
1.2.1005.1.1. Suggestions¶
Remove the unused property
Use the private property
Change the visibility to allow access the property from other part of the code
1.2.1005.1.2. Specs¶
Short name |
Classes/CouldBePrivate |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Available in |