Kentico/delivery-sdk-php

View on GitHub

Showing 11 of 16 total issues

QueryParams has 23 functions (exceeds 20 allowed). Consider refactoring.
Open

class QueryParams implements \ArrayAccess
{
    /**
     * Filter key-value pairs.
     *
Severity: Minor
Found in src/KenticoCloud/Delivery/QueryParams.php - About 2 hrs to fix

    Function bindModel has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        public function bindModel($modelType, $data, $linkedItems = null, $processedItems = null)
        {
            $processedItems = $processedItems ?? array();
            $model = new $modelType();
            $modelProperties = $this->propertyMapper->getModelProperties($model, $data);
    Severity: Minor
    Found in src/KenticoCloud/Delivery/ModelBinder.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

    The class DeliveryClient has 17 fields. Consider redesigning DeliveryClient to keep the number of fields under 15.
    Open

    class DeliveryClient
    {
        private $sdkVersion = '2.0.0';
    
        private $urlBuilder = null;

    Since: PHPMD 0.1

    Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

    Example:

    class Person {
         protected $one;
         private $two;
         private $three;
         [... many more fields ...]
      }

    Source: http://phpmd.org/rules/codesize.txt

    Function bindLinkedItems has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        public function bindLinkedItems($element, $linkedItems, $processedItems)
        {
            $modelLinkedItems = null;
            if ($linkedItems != null) {
                $modelLinkedItems = array();
    Severity: Minor
    Found in src/KenticoCloud/Delivery/ModelBinder.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

    Method bindModel has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function bindModel($modelType, $data, $linkedItems = null, $processedItems = null)
        {
            $processedItems = $processedItems ?? array();
            $model = new $modelType();
            $modelProperties = $this->propertyMapper->getModelProperties($model, $data);
    Severity: Minor
    Found in src/KenticoCloud/Delivery/ModelBinder.php - About 1 hr to fix

      Method __construct has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          public function __construct($id = null, $name = null, $codename = null, $lastModified = null, $type = null, $sitemapLocations = null, $language = null)
      Severity: Major
      Found in src/KenticoCloud/Delivery/Models/Items/ContentItemSystem.php - About 50 mins to fix

        Method __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            public function __construct(string $projectId, string $previewApiKey = null, string $securedProductionApiKey = null, bool $waitForLoadingNewContent = null, bool $debugRequests = null, int $retryAttempts = null)
        Severity: Minor
        Found in src/KenticoCloud/Delivery/DeliveryClient.php - About 45 mins to fix

          The class DeliveryClient has a coupling between objects value of 21. Consider to reduce the number of dependencies under 13.
          Open

          class DeliveryClient
          {
              private $sdkVersion = '2.0.0';
          
              private $urlBuilder = null;

          Since: PHPMD 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: http://phpmd.org/rules/design.txt

          Function getTypeClass has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public function getTypeClass($typeName)
              {
                  switch ($typeName) {
                      case 'asset':
                          $type = \KenticoCloud\Delivery\Models\Items\Asset::class;
          Severity: Minor
          Found in src/KenticoCloud/Delivery/DefaultMapper.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

          Avoid unused local variables such as '$element'.
          Open

                      foreach ($data[self::ELEMENTS_ATTRIBUTE_NAME] as $elementName => $element) {

          Since: PHPMD 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: http://phpmd.org/rules/unusedcode.txt

          Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.
          Open

              public function bindModel($modelType, $data, $linkedItems = null, $processedItems = null)

          Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

          See

          Severity
          Category
          Status
          Source
          Language