File TrackEngineAbstract.php
has 590 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
*
* @package Gems
Gems_Tracker_Engine_TrackEngineAbstract
has 49 functions (exceeds 20 allowed). Consider refactoring. Open
abstract class Gems_Tracker_Engine_TrackEngineAbstract extends \MUtil_Translate_TranslateableAbstract implements \Gems_Tracker_Engine_TrackEngineInterface
{
use DbTranslateUtilTrait;
/**
Method getRoundModel
has 84 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getRoundModel($detailed, $action)
{
$model = $this->createRoundModel();
$translated = $this->util->getTranslated();
The class Gems_Tracker_Engine_TrackEngineAbstract has 11 public methods. Consider refactoring Gems_Tracker_Engine_TrackEngineAbstract to keep number of public methods under 10. Open
abstract class Gems_Tracker_Engine_TrackEngineAbstract extends \MUtil_Translate_TranslateableAbstract implements \Gems_Tracker_Engine_TrackEngineInterface
{
use DbTranslateUtilTrait;
/**
- 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_Tracker_Engine_TrackEngineAbstract has an overall complexity of 122 which is very high. The configured complexity threshold is 50. Open
abstract class Gems_Tracker_Engine_TrackEngineAbstract extends \MUtil_Translate_TranslateableAbstract implements \Gems_Tracker_Engine_TrackEngineInterface
{
use DbTranslateUtilTrait;
/**
- Exclude checks
Method copyTrack
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function copyTrack($oldTrackId)
{
$trackModel = $this->tracker->getTrackModel();
$roundModel = $this->getRoundModel(true, 'rounds');
Function copyTrack
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function copyTrack($oldTrackId)
{
$trackModel = $this->tracker->getTrackModel();
$roundModel = $this->getRoundModel(true, 'rounds');
- 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 checkExistingRoundsFor
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function checkExistingRoundsFor(\Gems_Tracker_RespondentTrack $respTrack, $userId)
{
// FOR TESTING: sqlite can not de update and joins, so when testing just return zero for now
if (\Zend_Session::$_unitTestEnabled === true) return 0;
// @@ TODO Make this testable and not db dependent anymore
Function getPreviousRoundId
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function getPreviousRoundId($roundId, $roundOrder = null)
{
$this->_ensureRounds();
if ($this->_rounds && $roundId) {
- 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 _update
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private function _update(array $values, $userId)
{
if ($this->tracker->filterChangesOnly($this->_trackData, $values)) {
if (\Gems_Tracker::$verbose) {
- 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 getNextRoundId
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function getNextRoundId($roundId)
{
$this->_ensureRounds();
if ($this->_rounds && $roundId) {
- 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 addFieldsToModel
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function addFieldsToModel(\MUtil_Model_ModelAbstract $model, $addDependency = true, $respTrackId = false)
{
if ($this->_fieldsDefinition->exists) {
// Add the data to the load / save
$transformer = new AddTrackFieldsTransformer($this->loader, $this->_fieldsDefinition, $respTrackId);
- 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 addNewTokens
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function addNewTokens(\Gems_Tracker_RespondentTrack $respTrack, $userId)
{
$orgId = $respTrack->getOrganizationId();
$respId = $respTrack->getRespondentId();
$respTrackId = $respTrack->getRespondentTrackId();
Function getRoundModel
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function getRoundModel($detailed, $action)
{
$model = $this->createRoundModel();
$translated = $this->util->getTranslated();
- 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 _getAvailableIcons
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function _getAvailableIcons()
{
$dir = GEMS_WEB_DIR . '/gems-responsive/images/icons';
if (!file_exists($dir)) {
$dir = GEMS_WEB_DIR . '/gems/icons';
- 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 class Gems_Tracker_Engine_TrackEngineAbstract has 1091 lines of code. Current threshold is 1000. Avoid really long classes. Open
abstract class Gems_Tracker_Engine_TrackEngineAbstract extends \MUtil_Translate_TranslateableAbstract implements \Gems_Tracker_Engine_TrackEngineInterface
{
use DbTranslateUtilTrait;
/**
- Exclude checks
The method getRoundModel() has 106 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function getRoundModel($detailed, $action)
{
$model = $this->createRoundModel();
$translated = $this->util->getTranslated();
- Exclude checks
The method getPreviousRoundId() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function getPreviousRoundId($roundId, $roundOrder = null)
{
$this->_ensureRounds();
if ($this->_rounds && $roundId) {
- 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_Tracker_Engine_TrackEngineAbstract has a coupling between objects value of 38. Consider to reduce the number of dependencies under 13. Open
abstract class Gems_Tracker_Engine_TrackEngineAbstract extends \MUtil_Translate_TranslateableAbstract implements \Gems_Tracker_Engine_TrackEngineInterface
{
use DbTranslateUtilTrait;
/**
- 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 parameters such as '$userId'. Open
protected function removeInactiveRounds(\Gems_Tracker_RespondentTrack $respTrack, $userId)
- 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 '$round'. Open
foreach ($this->_rounds as $currentRoundId => $round) {
- 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 '$newField'. Open
foreach ($newFields as $idx => $newField) {
- 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 '$newRound'. Open
foreach ($newRounds as $idx => $newRound) {
- 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
TODO found Open
// @@ TODO Make this testable and not db dependent anymore
- Exclude checks
Avoid excessively long variable names like $conversionTargetClass. Keep variable name length under 20. Open
public function convertTo($conversionTargetClass)
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid variables with short names like $tp. Configured minimum length is 3. Open
$tp = new \MUtil_Model_Type_ConcatenatedRow('|', $this->_(', '));
- 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 $i. Configured minimum length is 3. Open
$i = $batch->addToCounter('roundChangeUpdates', $this->checkExistingRoundsFor($respTrack, $userId));
- 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;
}
}
}