File MenuAbstract.php
has 628 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
*
* @package Gems
Gems_Menu_MenuAbstract
has 37 functions (exceeds 20 allowed). Consider refactoring. Open
abstract class Gems_Menu_MenuAbstract extends \Gems_Loader_TargetLoaderAbstract
{
use TranslateableTrait;
/**
Method addTrackBuilderMenu
has 94 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addTrackBuilderMenu($label, array $other = array())
{
$setup = $this->addContainer($label);
// SURVEY SOURCES CONTROLLER
The class Gems_Menu_MenuAbstract has 23 public methods. Consider refactoring Gems_Menu_MenuAbstract to keep number of public methods under 10. Open
abstract class Gems_Menu_MenuAbstract extends \Gems_Loader_TargetLoaderAbstract
{
use TranslateableTrait;
/**
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
The class Gems_Menu_MenuAbstract has an overall complexity of 85 which is very high. The configured complexity threshold is 50. Open
abstract class Gems_Menu_MenuAbstract extends \Gems_Loader_TargetLoaderAbstract
{
use TranslateableTrait;
/**
- Exclude checks
The class Gems_Menu_MenuAbstract has 31 non-getter- and setter-methods. Consider refactoring Gems_Menu_MenuAbstract to keep number of methods under 25. Open
abstract class Gems_Menu_MenuAbstract extends \Gems_Loader_TargetLoaderAbstract
{
use TranslateableTrait;
/**
- Read upRead up
- Exclude checks
TooManyMethods
Since: 0.1
A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
The default was changed from 10 to 25 in PHPMD 2.3.
Example
Source https://phpmd.org/rules/codesize.html#toomanymethods
Function _toNavigationArray
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
protected function _toNavigationArray(\Gems_Menu_ParameterCollector $source)
{
$this->sortByOrder();
$lastParams = null;
$pageIdx = 0;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _addUsedPrivileges
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
protected function _addUsedPrivileges(array &$privileges, $label)
{
foreach ($this->_subItems as $item) {
// Skip autofilter action, but include all others
if ($item->get('action') == 'autofilter') {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method addProjectInfoPage
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addProjectInfoPage($label)
{
$page = $this->addPage($label, 'pr.project-information', 'project-information');
$page->addAction($this->_('Errors'), null, 'errors');
$page->addAction($this->_('PHP'), null, 'php');
Method addStaffPage
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addStaffPage($label, array $other = array())
{
if ($this->currentUser->hasPrivilege('pr.staff.edit.all')) {
$filter = array_keys($this->loader->getUtil()->getDbLookup()->getOrganizations());
} else {
Method _toNavigationArray
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _toNavigationArray(\Gems_Menu_ParameterCollector $source)
{
$this->sortByOrder();
$lastParams = null;
$pageIdx = 0;
Function applyAcl
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function applyAcl(\MUtil_Acl $acl, $userRole)
{
foreach ($this->_subItems as $item) {
$allowed = $item->get('allowed', true);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method addButtonOnly
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function addButtonOnly($label, $privilege, $controller, $action = 'index', array $other = array())
Method addPage
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function addPage($label, $privilege, $controller, $action = 'index', array $other = array())
Function setBranchVisible
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function setBranchVisible(array $activeBranch)
{
$current = array_pop($activeBranch);
foreach ($this->_subItems as $item) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
The method addTrackBuilderMenu() has 126 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function addTrackBuilderMenu($label, array $other = array())
{
$setup = $this->addContainer($label);
// SURVEY SOURCES CONTROLLER
- Exclude checks
The class Gems_Menu_MenuAbstract has 1095 lines of code. Current threshold is 1000. Avoid really long classes. Open
abstract class Gems_Menu_MenuAbstract extends \Gems_Loader_TargetLoaderAbstract
{
use TranslateableTrait;
/**
- Exclude checks
The method _toNavigationArray() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
protected function _toNavigationArray(\Gems_Menu_ParameterCollector $source)
{
$this->sortByOrder();
$lastParams = null;
$pageIdx = 0;
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The class Gems_Menu_MenuAbstract has a coupling between objects value of 17. Consider to reduce the number of dependencies under 13. Open
abstract class Gems_Menu_MenuAbstract extends \Gems_Loader_TargetLoaderAbstract
{
use TranslateableTrait;
/**
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Avoid unused local variables such as '$ajaxPage'. Open
$ajaxPage = $this->addPage($this->_('Round Selection'), 'pr.comm.job', 'comm-job', 'roundselect', array('visible' => false));
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused local variables such as '$codePage'. Open
$codePage = $showPage->addPage($this->_('Export codebook'), 'pr.survey-maintenance.code-book-export', 'survey-code-book-export', 'export')
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused local variables such as '$page'. Open
$page = $import->addPage($this->_('Answers'), 'pr.survey-maintenance.answer-import', 'file-import', 'answers-import');
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused parameters such as '$other'. Open
public function addTrackBuilderMenu($label, array $other = array())
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused local variables such as '$createPage'. Open
$createPage = $page->addCreateAction();
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused local variables such as '$createPage'. Open
$createPage = $page->addCreateAction();
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused local variables such as '$ajaxPage'. Open
$ajaxPage = $this->addPage($this->_('Sort rounds'), 'pr.track-maintenance.edit', 'track-rounds', 'sort', array('visible' => false));
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid variables with short names like $a. Configured minimum length is 3. Open
$a = $aItem->get('order');
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $b. Configured minimum length is 3. Open
$b = $bItem->get('order');
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The variable $_privilege is not named in camelCase. Open
protected function _addUsedPrivileges(array &$privileges, $label)
{
foreach ($this->_subItems as $item) {
// Skip autofilter action, but include all others
if ($item->get('action') == 'autofilter') {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_itemlabel is not named in camelCase. Open
protected function _addUsedPrivileges(array &$privileges, $label)
{
foreach ($this->_subItems as $item) {
// Skip autofilter action, but include all others
if ($item->get('action') == 'autofilter') {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_itemlabel is not named in camelCase. Open
protected function _addUsedPrivileges(array &$privileges, $label)
{
foreach ($this->_subItems as $item) {
// Skip autofilter action, but include all others
if ($item->get('action') == 'autofilter') {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_privilege is not named in camelCase. Open
protected function _addUsedPrivileges(array &$privileges, $label)
{
foreach ($this->_subItems as $item) {
// Skip autofilter action, but include all others
if ($item->get('action') == 'autofilter') {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_itemlabel is not named in camelCase. Open
protected function _addUsedPrivileges(array &$privileges, $label)
{
foreach ($this->_subItems as $item) {
// Skip autofilter action, but include all others
if ($item->get('action') == 'autofilter') {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_privilege is not named in camelCase. Open
protected function _addUsedPrivileges(array &$privileges, $label)
{
foreach ($this->_subItems as $item) {
// Skip autofilter action, but include all others
if ($item->get('action') == 'autofilter') {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_privilege is not named in camelCase. Open
protected function _addUsedPrivileges(array &$privileges, $label)
{
foreach ($this->_subItems as $item) {
// Skip autofilter action, but include all others
if ($item->get('action') == 'autofilter') {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_privilege is not named in camelCase. Open
protected function _addUsedPrivileges(array &$privileges, $label)
{
foreach ($this->_subItems as $item) {
// Skip autofilter action, but include all others
if ($item->get('action') == 'autofilter') {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_privilege is not named in camelCase. Open
protected function _addUsedPrivileges(array &$privileges, $label)
{
foreach ($this->_subItems as $item) {
// Skip autofilter action, but include all others
if ($item->get('action') == 'autofilter') {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_privilege is not named in camelCase. Open
protected function _addUsedPrivileges(array &$privileges, $label)
{
foreach ($this->_subItems as $item) {
// Skip autofilter action, but include all others
if ($item->get('action') == 'autofilter') {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_itemlabel is not named in camelCase. Open
protected function _addUsedPrivileges(array &$privileges, $label)
{
foreach ($this->_subItems as $item) {
// Skip autofilter action, but include all others
if ($item->get('action') == 'autofilter') {
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}