File RespondentTrack.php
has 928 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
*
* @package Gems
Gems_Tracker_RespondentTrack
has 65 functions (exceeds 20 allowed). Consider refactoring. Open
class Gems_Tracker_RespondentTrack extends \Gems_Registry_TargetAbstract
{
use DbTranslateUtilTrait;
/**
Function assignTokensToRelations
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
public function assignTokensToRelations()
{
// Find out if we have relation fields and return when none exists in this track
$relationFields = $this->getTrackEngine()->getFieldsOfType('relation');
if (empty($relationFields)) {
- 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_RespondentTrack has 20 public methods. Consider refactoring Gems_Tracker_RespondentTrack to keep number of public methods under 10. Open
class Gems_Tracker_RespondentTrack extends \Gems_Registry_TargetAbstract
{
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_RespondentTrack has an overall complexity of 227 which is very high. The configured complexity threshold is 50. Open
class Gems_Tracker_RespondentTrack extends \Gems_Registry_TargetAbstract
{
use DbTranslateUtilTrait;
/**
- Exclude checks
The class Gems_Tracker_RespondentTrack has 26 non-getter- and setter-methods. Consider refactoring Gems_Tracker_RespondentTrack to keep number of methods under 25. Open
class Gems_Tracker_RespondentTrack extends \Gems_Registry_TargetAbstract
{
use DbTranslateUtilTrait;
/**
- 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 setReceptionCode
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function setReceptionCode($code, $comment, $userId)
{
// Make sure it is a \Gems_Util_ReceptionCode object
if (! $code instanceof \Gems_Util_ReceptionCode) {
$code = $this->util->getReceptionCode($code);
- 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 _mergeFieldValues
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
protected function _mergeFieldValues(array $newFieldData, array $oldFieldData, \Gems_Tracker_Engine_TrackEngineInterface $trackEngine)
{
$fieldDef = $trackEngine->getFieldsDefinition();
$fieldMap = $fieldDef->getFieldCodes() + $fieldDef->getManualFields();
$output = array();
- 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 getCurrentRound
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function getCurrentRound()
{
$isStop = false;
$today = new \Zend_Date();
$tokens = $this->getTokens();
- 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 getDate
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function getDate($fieldName)
{
if (isset($this->_respTrackData[$fieldName])) {
$date = $this->_respTrackData[$fieldName];
} else {
- 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 assignTokensToRelations
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function assignTokensToRelations()
{
// Find out if we have relation fields and return when none exists in this track
$relationFields = $this->getTrackEngine()->getFieldsOfType('relation');
if (empty($relationFields)) {
Method handleRoundCompletion
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function handleRoundCompletion($token, $userId)
{
if (! $token instanceof \Gems_Tracker_Token) {
$token = $this->tracker->getToken($token);
}
Method handleBeforeFieldUpdate
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function handleBeforeFieldUpdate(array $fieldData)
{
static $running = array();
// Process any events
Function _updateTrack
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
protected function _updateTrack(array $values, $userId = null)
{
if (null === $userId) {
$userId = $this->currentUser->getUserId();
}
- 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 getTokens
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function getTokens($refresh = false)
{
if (! $this->_tokens || $refresh) {
if ($refresh) {
$this->_firstToken = null;
- 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 calculateEndDate
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function calculateEndDate()
{
// Exclude the tokens whose end date is calculated from the track end date
$excludeWheres[] = sprintf(
"gro_valid_for_source = '%s' AND gro_valid_for_field = 'gr2t_end_date'",
Method _mergeFieldValues
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _mergeFieldValues(array $newFieldData, array $oldFieldData, \Gems_Tracker_Engine_TrackEngineInterface $trackEngine)
{
$fieldDef = $trackEngine->getFieldsDefinition();
$fieldMap = $fieldDef->getFieldCodes() + $fieldDef->getManualFields();
$output = array();
Method handleFieldUpdate
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function handleFieldUpdate(array $oldFieldData = null)
{
static $running = array();
// Process any events
Function handleRoundCompletion
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function handleRoundCompletion($token, $userId)
{
if (! $token instanceof \Gems_Tracker_Token) {
$token = $this->tracker->getToken($token);
}
- 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 restoreTokens
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function restoreTokens(\Gems_Util_ReceptionCode $oldCode, \Gems_Util_ReceptionCode $newCode) {
$count = 0;
if (!$oldCode->isSuccess() && $newCode->isSuccess()) {
foreach ($this->getTokens() as $token) {
- 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_RespondentTrack has 59 public methods and attributes. Consider reducing the number of public items to less than 45. Open
class Gems_Tracker_RespondentTrack extends \Gems_Registry_TargetAbstract
{
use DbTranslateUtilTrait;
/**
- Read upRead up
- Exclude checks
ExcessivePublicCount
Since: 0.1
A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it.
Example
public class Foo {
public $value;
public $something;
public $var;
// [... more more public attributes ...]
public function doWork() {}
public function doMoreWork() {}
public function doWorkAgain() {}
// [... more more public methods ...]
}
Source https://phpmd.org/rules/codesize.html#excessivepubliccount
Function getRoundAfterAppointmentId
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function getRoundAfterAppointmentId($roundId)
{
$this->_ensureFieldData();
$this->_ensureRounds();
- 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 getActiveRoundToken
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getActiveRoundToken($roundId, \Gems_Tracker_Token $token = null)
{
if ((null !== $token) && $token->hasSuccesCode()) {
// Cache the token
//
- 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 handleBeforeFieldUpdate
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function handleBeforeFieldUpdate(array $fieldData)
{
static $running = array();
// Process any events
- 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 handleFieldUpdate
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function handleFieldUpdate(array $oldFieldData = null)
{
static $running = array();
// Process any events
- 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 getCodeFields
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getCodeFields()
{
$fieldDef = $this->getTrackEngine()->getFieldsDefinition();
$codes = $this->tracker->getAllCodeFields();
$results = array_fill_keys($codes, null);
- 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 checkRegistryRequestsAnswers
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function checkRegistryRequestsAnswers()
{
$this->initDbTranslations();
if ($this->_respTrackData) {
- 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_RespondentTrack has 1653 lines of code. Current threshold is 1000. Avoid really long classes. Open
class Gems_Tracker_RespondentTrack extends \Gems_Registry_TargetAbstract
{
use DbTranslateUtilTrait;
/**
- Exclude checks
The method assignTokensToRelations() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
public function assignTokensToRelations()
{
// Find out if we have relation fields and return when none exists in this track
$relationFields = $this->getTrackEngine()->getFieldsOfType('relation');
if (empty($relationFields)) {
- 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 method setReceptionCode() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public function setReceptionCode($code, $comment, $userId)
{
// Make sure it is a \Gems_Util_ReceptionCode object
if (! $code instanceof \Gems_Util_ReceptionCode) {
$code = $this->util->getReceptionCode($code);
- 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_RespondentTrack has a coupling between objects value of 27. Consider to reduce the number of dependencies under 13. Open
class Gems_Tracker_RespondentTrack extends \Gems_Registry_TargetAbstract
{
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
protected function _ensureRespondentData()
{
if (! isset($this->_respTrackData['grs_id_user'], $this->_respTrackData['gr2o_id_user'], $this->_respTrackData['gco_code'])) {
$sql = "SELECT *
FROM gems__respondents INNER JOIN
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 134.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid excessively long variable names like $respondentTrackFieldEvent. Keep variable name length under 20. Open
$respondentTrackFieldEvent = new RespondentTrackFieldEvent($this, $this->currentUser->getUserId());
- 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 excessively long variable names like $beforeFieldUpdateEvent. Keep variable name length under 20. Open
$beforeFieldUpdateEvent = $trackEngine->getFieldBeforeUpdateEvent();
- 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 excessively long variable names like $_tablesForTranslations. Keep variable name length under 20. Open
protected $_tablesForTranslations = [
'gems__respondent2track' => 'gr2t_id_respondent_track',
'gems__tracks' => 'gtr_id_track',
];
- 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++ ) {
}
}
}