GemsTracker/gemstracker-library

View on GitHub
classes/Gems/Export/ModelSource/AnswerExportModelSource.php

Summary

Maintainability
F
3 days
Test Coverage
F
0%

Function _addSurveyAnswersToExportModel has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

    protected function _addSurveyAnswersToExportModel(\MUtil_Model_ModelAbstract $model, \Gems_Tracker_Survey $survey, array $data, array &$prefixes)
    {
        $prefixes['A'] = [];
        $language = $this->locale->getLanguage();
        $questions = $survey->getQuestionList($language);
Severity: Minor
Found in classes/Gems/Export/ModelSource/AnswerExportModelSource.php - About 4 hrs to fix

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 _addManualFields has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

    protected function _addManualFields(\MUtil_Model_ModelAbstract $model, array $data, array &$prefixes)
    {
        if (isset($data['manualFields'])) {
            $manualFields = $data['manualFields'];
            if (!is_array($data['manualFields'])) {
Severity: Minor
Found in classes/Gems/Export/ModelSource/AnswerExportModelSource.php - About 4 hrs to fix

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

File AnswerExportModelSource.php has 359 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 *
 * @package    Gems
Severity: Minor
Found in classes/Gems/Export/ModelSource/AnswerExportModelSource.php - About 4 hrs to fix

    Function getModel has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getModel($filter = array(), $data = array())
        {
            if ($filter !== $this->filter || !$this->model) {
                $this->filter = $filter;
    
    
    Severity: Minor
    Found in classes/Gems/Export/ModelSource/AnswerExportModelSource.php - About 3 hrs to fix

    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_Export_ModelSource_AnswerExportModelSource has an overall complexity of 94 which is very high. The configured complexity threshold is 50.
    Open

    class Gems_Export_ModelSource_AnswerExportModelSource extends \Gems_Export_ModelSource_ExportModelSourceAbstract
    {
        /**
         *
         * @var \Gems_Model_RespondentModel

    Function _addExtraGenderAge has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function _addExtraGenderAge(\MUtil_Model_ModelAbstract $model, array $data, array &$prefixes)
        {
            if ($this->currentUser->hasPrivilege('pr.export.gender-age')) {
                if (isset($data['export_resp_gender']) && $data['export_resp_gender']) {
                    $model->set('grs_gender', 'label', $this->getRespondentModel()->get('grs_gender', 'label'),
    Severity: Minor
    Found in classes/Gems/Export/ModelSource/AnswerExportModelSource.php - About 2 hrs to fix

    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 getExtraDataFormElements has 49 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getExtraDataFormElements(\Gems_Form $form, $data)
        {
            $this->form = $form;
            $elements   = [];
    
    
    Severity: Minor
    Found in classes/Gems/Export/ModelSource/AnswerExportModelSource.php - About 1 hr to fix

      Method _addDefaultFieldsToExportModel has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function _addDefaultFieldsToExportModel(\MUtil_Model_ModelAbstract $model, array $data, array &$prefixes)
          {
              if (!$model->checkJoinExists('gems__respondent2org.gr2o_id_user', 'gems__tokens.gto_id_respondent')) {
                  $model->addTable('gems__respondent2org', array(
                      'gems__respondent2org.gr2o_id_user' => 'gems__tokens.gto_id_respondent',
      Severity: Minor
      Found in classes/Gems/Export/ModelSource/AnswerExportModelSource.php - About 1 hr to fix

        Method _addManualFields has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function _addManualFields(\MUtil_Model_ModelAbstract $model, array $data, array &$prefixes)
            {
                if (isset($data['manualFields'])) {
                    $manualFields = $data['manualFields'];
                    if (!is_array($data['manualFields'])) {
        Severity: Minor
        Found in classes/Gems/Export/ModelSource/AnswerExportModelSource.php - About 1 hr to fix

          Method getModel has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getModel($filter = array(), $data = array())
              {
                  if ($filter !== $this->filter || !$this->model) {
                      $this->filter = $filter;
          
          
          Severity: Minor
          Found in classes/Gems/Export/ModelSource/AnswerExportModelSource.php - About 1 hr to fix

            Method _addSurveyAnswersToExportModel has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function _addSurveyAnswersToExportModel(\MUtil_Model_ModelAbstract $model, \Gems_Tracker_Survey $survey, array $data, array &$prefixes)
                {
                    $prefixes['A'] = [];
                    $language = $this->locale->getLanguage();
                    $questions = $survey->getQuestionList($language);
            Severity: Minor
            Found in classes/Gems/Export/ModelSource/AnswerExportModelSource.php - About 1 hr to fix

              Method _addExtraGenderAge has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function _addExtraGenderAge(\MUtil_Model_ModelAbstract $model, array $data, array &$prefixes)
                  {
                      if ($this->currentUser->hasPrivilege('pr.export.gender-age')) {
                          if (isset($data['export_resp_gender']) && $data['export_resp_gender']) {
                              $model->set('grs_gender', 'label', $this->getRespondentModel()->get('grs_gender', 'label'),
              Severity: Minor
              Found in classes/Gems/Export/ModelSource/AnswerExportModelSource.php - About 1 hr to fix

                Function _addExtraTrackFieldsByCode has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function _addExtraTrackFieldsByCode(\MUtil_Model_ModelAbstract $model, array $data, array &$prefixes)
                    {
                        if (isset($data['export_trackfield_codes'])) {
                            $includeCodes = array_map('trim', explode(',', $data['export_trackfield_codes']));
                            $codes = [];
                Severity: Minor
                Found in classes/Gems/Export/ModelSource/AnswerExportModelSource.php - About 45 mins to fix

                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 _addNestedFieldsToExportModel has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function _addNestedFieldsToExportModel(\MUtil_Model_ModelAbstract $model, array $data, array &$prefixes)
                    {
                        // Set labels in the main model for the submodel fields
                        if ($model->getMeta('nested', false)) {
                            $nestedNames = $model->getMeta('nestedNames');
                Severity: Minor
                Found in classes/Gems/Export/ModelSource/AnswerExportModelSource.php - About 25 mins to fix

                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 _addManualFields() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
                Open

                    protected function _addManualFields(\MUtil_Model_ModelAbstract $model, array $data, array &$prefixes)
                    {
                        if (isset($data['manualFields'])) {
                            $manualFields = $data['manualFields'];
                            if (!is_array($data['manualFields'])) {

                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 _addSurveyAnswersToExportModel() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
                Open

                    protected function _addSurveyAnswersToExportModel(\MUtil_Model_ModelAbstract $model, \Gems_Tracker_Survey $survey, array $data, array &$prefixes)
                    {
                        $prefixes['A'] = [];
                        $language = $this->locale->getLanguage();
                        $questions = $survey->getQuestionList($language);

                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 _addExtraGenderAge() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
                Open

                    protected function _addExtraGenderAge(\MUtil_Model_ModelAbstract $model, array $data, array &$prefixes)
                    {
                        if ($this->currentUser->hasPrivilege('pr.export.gender-age')) {
                            if (isset($data['export_resp_gender']) && $data['export_resp_gender']) {
                                $model->set('grs_gender', 'label', $this->getRespondentModel()->get('grs_gender', 'label'),

                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 getModel() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
                Open

                    public function getModel($filter = array(), $data = array())
                    {
                        if ($filter !== $this->filter || !$this->model) {
                            $this->filter = $filter;
                
                

                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

                Avoid unused parameters such as '$data'.
                Open

                    protected function _addDefaultFieldsToExportModel(\MUtil_Model_ModelAbstract $model, array $data, array &$prefixes)

                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 '$data'.
                Open

                    protected function _addNestedFieldsToExportModel(\MUtil_Model_ModelAbstract $model, array $data, array &$prefixes)

                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 '$prefixes'.
                Open

                    protected function _addNestedFieldsToExportModel(\MUtil_Model_ModelAbstract $model, array $data, array &$prefixes)

                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 '$prefixes'.
                Open

                    protected function _addSurveySourceAttributesToExportModel(\MUtil_Model_ModelAbstract $model, \Gems_Tracker_Survey $survey, array $data, array &$prefixes)

                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 '$prefixes'.
                Open

                    protected function _addDefaultFieldsToExportModel(\MUtil_Model_ModelAbstract $model, array $data, array &$prefixes)

                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 '$question'.
                Open

                            if ($question = $model->get($questionName, 'survey_question') && $model->get($questionName, 'label') == null) {

                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 '$data'.
                Open

                    protected function _addSurveySourceAttributesToExportModel(\MUtil_Model_ModelAbstract $model, \Gems_Tracker_Survey $survey, array $data, array &$prefixes)

                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

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                    protected function _createCheckboxElement($name, $label, $description = null)
                    {
                        if ($name && $label) {
                            $element = $this->form->createElement('checkbox', $name);
                            $element->setLabel($label);
                Severity: Major
                Found in classes/Gems/Export/ModelSource/AnswerExportModelSource.php and 1 other location - About 1 hr to fix
                classes/Gems/Snippets/AutosearchFormSnippet.php on lines 192..206

                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 107.

                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

                Further Reading

                Avoid excessively long class names like Gems_Export_ModelSource_AnswerExportModelSource. Keep class name length under 40.
                Open

                class Gems_Export_ModelSource_AnswerExportModelSource extends \Gems_Export_ModelSource_ExportModelSourceAbstract
                {
                    /**
                     *
                     * @var \Gems_Model_RespondentModel

                LongClassName

                Since: 2.9

                Detects when classes or interfaces are declared with excessively long names.

                Example

                class ATooLongClassNameThatHintsAtADesignProblem {
                
                }
                
                interface ATooLongInterfaceNameThatHintsAtADesignProblem {
                
                }

                Source https://phpmd.org/rules/naming.html#longclassname

                There are no issues that match your filters.

                Category
                Status