CRITICAL
Rule Definition
Access modifiers are essential element of object oriented language. Use of access modifier helps achieve encapsulation and abstraction. They also make code understanding clearer.
Remediation
Try to reduce the number of Class Methods and constructor without scope modifiers.
Violation Code Sample
class Toys {
$categories = array("puzzles","pull back","remote","soft");
function getToysCategories() {
return $this->categories;
}
}
$objToys = new Toys();
print "<pre>";
print_r($objToys->getToysCategories());
print "</pre>";
Fixed Code Sample
class Toys {
private $categories = array("puzzles","pull back","remote","soft");
public function getToysCategories() {
return $this->categories;
}
}
$objToys = new Toys();
print "<pre>";
print_r($objToys->getToysCategories());
print "</pre>";
Reference
Symfony2-coding-standard - Author :
https://github.com/djoos/Symfony2-coding-standard/blob/master/Symfony2/Sniffs/Scope/MethodScopeSniff.php
https://pear.php.net/reference/PHP_CodeSniffer-latest/PHP_CodeSniffer/Squiz_Sniffs_Scope_MethodScopeSniff.html
Related Technologies
Technical Criterion
Complexity - OO Inheritance and Polymorphism
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.