lovata/oc-toolbox-plugin

View on GitHub
classes/collection/ElementCollection.php

Summary

Maintainability
D
1 day
Test Coverage

File ElementCollection.php has 418 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php namespace Lovata\Toolbox\Classes\Collection;

use ArrayIterator;
use October\Contracts\Twig\CallsAnyMethod;
use October\Rain\Extension\Extendable;
Severity: Minor
Found in classes/collection/ElementCollection.php - About 6 hrs to fix

    ElementCollection has 40 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class ElementCollection extends Extendable implements CallsAnyMethod, \IteratorAggregate, \Countable
    {
        const COUNT_PER_PAGE = 10;
        const ITEM_CLASS = \Lovata\Toolbox\Classes\Item\ElementItem::class;
    
    
    Severity: Minor
    Found in classes/collection/ElementCollection.php - About 5 hrs to fix

      The class ElementCollection has an overall complexity of 112 which is very high. The configured complexity threshold is 50.
      Open

      abstract class ElementCollection extends Extendable implements CallsAnyMethod, \IteratorAggregate, \Countable
      {
          const COUNT_PER_PAGE = 10;
          const ITEM_CLASS = \Lovata\Toolbox\Classes\Item\ElementItem::class;
      
      

      The class ElementCollection has 31 public methods. Consider refactoring ElementCollection to keep number of public methods under 10.
      Open

      abstract class ElementCollection extends Extendable implements CallsAnyMethod, \IteratorAggregate, \Countable
      {
          const COUNT_PER_PAGE = 10;
          const ITEM_CLASS = \Lovata\Toolbox\Classes\Item\ElementItem::class;
      
      

      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 ElementCollection has 34 non-getter- and setter-methods. Consider refactoring ElementCollection to keep number of methods under 25.
      Open

      abstract class ElementCollection extends Extendable implements CallsAnyMethod, \IteratorAggregate, \Countable
      {
          const COUNT_PER_PAGE = 10;
          const ITEM_CLASS = \Lovata\Toolbox\Classes\Item\ElementItem::class;
      
      

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

          protected function getElementListFromDB($arElementIDList, $arResult)
          {
              if (empty($arElementIDList)) {
                  return $arResult;
              }
      Severity: Minor
      Found in classes/collection/ElementCollection.php - About 1 hr 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 pluck has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          public function pluck($sFieldName)
          {
              if (empty($sFieldName) || $this->isEmpty()) {
                  return null;
              }
      Severity: Minor
      Found in classes/collection/ElementCollection.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

      Class "ElementCollection" has 40 methods, which is greater than 20 authorized. Split it into smaller classes.
      Open

      abstract class ElementCollection extends Extendable implements CallsAnyMethod, \IteratorAggregate, \Countable

      A class that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to maintain. Above a specific threshold, it is strongly advised to refactor the class into smaller ones which focus on well defined topics.

      Reduce the number of returns of this function 4, down to the maximum allowed 3.
      Open

          public function applySorting($arResultIDList)

      Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

      Noncompliant Code Example

      With the default threshold of 3:

      function myFunction(){ // Noncompliant as there are 4 return statements
        if (condition1) {
          return true;
        } else {
          if (condition2) {
            return false;
          } else {
            return true;
          }
        }
        return false;
      }
      

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

          public function first()
          {
              if ($this->isEmpty()) {
                  return $this->makeItem(null);
              }
      Severity: Minor
      Found in classes/collection/ElementCollection.php and 1 other location - About 45 mins to fix
      classes/collection/ElementCollection.php on lines 437..448

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

      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

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

          public function last()
          {
              if ($this->isEmpty()) {
                  return $this->makeItem(null);
              }
      Severity: Minor
      Found in classes/collection/ElementCollection.php and 1 other location - About 45 mins to fix
      classes/collection/ElementCollection.php on lines 418..429

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

      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

      Abstract class name is not prefixed with "Abstract"
      Open

      abstract class ElementCollection extends Extendable implements CallsAnyMethod, \IteratorAggregate, \Countable

      There are no issues that match your filters.

      Category
      Status