File SurveyCompareSnippet.php
has 486 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace Gems\Snippets\Survey;
class SurveyCompareSnippet extends \MUtil_Snippets_WizardFormSnippetAbstract {
SurveyCompareSnippet
has 30 functions (exceeds 20 allowed). Consider refactoring. Open
class SurveyCompareSnippet extends \MUtil_Snippets_WizardFormSnippetAbstract {
/**
*
* @var \Zend_Session_Namespace
The class SurveyCompareSnippet has an overall complexity of 94 which is very high. The configured complexity threshold is 50. Open
class SurveyCompareSnippet extends \MUtil_Snippets_WizardFormSnippetAbstract {
/**
*
* @var \Zend_Session_Namespace
- Exclude checks
Function addSurveyCompareForm
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
public function addSurveyCompareForm($tableBody, $post) {
if ($this->sourceSurveyId && $this->targetSurveyId) {
$sourceSurveyData = $this->getSurveyData($this->sourceSurveyId);
$targetSurveyData = $this->getSurveyData($this->targetSurveyId);
$surveyCompare = $this->getSurveyCompare($sourceSurveyData, $targetSurveyData, $post);
- 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 loadFormData
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
protected function loadFormData() {
if ($this->request->isPost()) {
$this->formData = $this->request->getPost() + $this->formData;
} else {
foreach ($this->model->getColNames('default') as $name) {
- 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 getSurveyCompare
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function getSurveyCompare($sourceSurveyData, $targetSurveyData, $post) {
$surveyCompareArray = [];
$missingSourceSurveyTitles = $sourceSurveyData;
// show all questions that can be send to the target survey
- 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 addSurveyCompareForm
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addSurveyCompareForm($tableBody, $post) {
if ($this->sourceSurveyId && $this->targetSurveyId) {
$sourceSurveyData = $this->getSurveyData($this->sourceSurveyId);
$targetSurveyData = $this->getSurveyData($this->targetSurveyId);
$surveyCompare = $this->getSurveyCompare($sourceSurveyData, $targetSurveyData, $post);
Method getSurveyCompare
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getSurveyCompare($sourceSurveyData, $targetSurveyData, $post) {
$surveyCompareArray = [];
$missingSourceSurveyTitles = $sourceSurveyData;
// show all questions that can be send to the target survey
Method addStepElementsForStep4
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function addStepElementsForStep4(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model) {
// Things go really wrong (at the session level) if we run this code
// while the finish button was pressed
if ($this->isFinishedClicked()) {
return;
Method loadFormData
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function loadFormData() {
if ($this->request->isPost()) {
$this->formData = $this->request->getPost() + $this->formData;
} else {
foreach ($this->model->getColNames('default') as $name) {
Method addStepElementsFor
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function addStepElementsFor(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model, $step) {
$this->displayHeader($bridge, $this->_('Survey replace'), 'h1');
// If we don't copy answers, we skip step 2
if ($this->formData['copy_answers'] == 0 && $step > 1) {
Function getCategorizedResults
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected function getCategorizedResults($post, $sourceSurveyData, $targetSurveyData) {
$surveyCompare = $this->getSurveyCompare($sourceSurveyData, $targetSurveyData, $post);
$categorizedResults = [];
foreach (array_keys($this->questionStatusClasses) as $status) {
- 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 addStepElementsFor
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function addStepElementsFor(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model, $step) {
$this->displayHeader($bridge, $this->_('Survey replace'), 'h1');
// If we don't copy answers, we skip step 2
if ($this->formData['copy_answers'] == 0 && $step > 1) {
- 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 loadFormData() has an NPath complexity of 405. The configured NPath complexity threshold is 200. Open
protected function loadFormData() {
if ($this->request->isPost()) {
$this->formData = $this->request->getPost() + $this->formData;
} else {
foreach ($this->model->getColNames('default') as $name) {
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method loadFormData() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
protected function loadFormData() {
if ($this->request->isPost()) {
$this->formData = $this->request->getPost() + $this->formData;
} else {
foreach ($this->model->getColNames('default') as $name) {
- 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 addSurveyCompareForm() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function addSurveyCompareForm($tableBody, $post) {
if ($this->sourceSurveyId && $this->targetSurveyId) {
$sourceSurveyData = $this->getSurveyData($this->sourceSurveyId);
$targetSurveyData = $this->getSurveyData($this->targetSurveyId);
$surveyCompare = $this->getSurveyCompare($sourceSurveyData, $targetSurveyData, $post);
- 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 SurveyCompareSnippet has a coupling between objects value of 18. Consider to reduce the number of dependencies under 13. Open
class SurveyCompareSnippet extends \MUtil_Snippets_WizardFormSnippetAbstract {
/**
*
* @var \Zend_Session_Namespace
- 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
The method addStepElementsForStep4() contains an exit expression. Open
exit;
- Read upRead up
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
Avoid unused parameters such as '$model'. Open
protected function addStepElementsForStep3(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model) {
- 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 '$surveys'. Open
$surveys = $this->surveys;
- 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 '$post'. Open
public function getSurveySelect($name, $post) {
- 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 parameters such as '$model'. Open
protected function addStepElementsForStep2(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model) {
- 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 parameters such as '$model'. Open
protected function addStepElementsForStep4(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model) {
- 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 excessively long variable names like $questionStatusClasses. Keep variable name length under 20. Open
protected $questionStatusClasses = [
'same' => 'success',
'new' => 'info',
'type-difference' => 'warning',
'missing' => 'danger',
- 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 $missingSourceSurveyTitles. Keep variable name length under 20. Open
$missingSourceSurveyTitles = $sourceSurveyData;
- 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 $db. Configured minimum length is 3. Open
public $db;
- 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;
}
}
}