nabbar/SwaggerValidator-PHP

View on GitHub
src/Common/ContextBase.php

Summary

Maintainability
D
1 day
Test Coverage

ContextBase has 51 functions (exceeds 20 allowed). Consider refactoring.
Open

class ContextBase implements \SwaggerValidator\Interfaces\ContextBase
{

    /**
     *
Severity: Major
Found in src/Common/ContextBase.php - About 7 hrs to fix

    File ContextBase.php has 389 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    /*
     * Copyright 2016 Nicolas JUHEL<swaggervalidator@nabbar.com>.
     *
    Severity: Minor
    Found in src/Common/ContextBase.php - About 5 hrs to fix

      The class ContextBase has 12 public methods. Consider refactoring ContextBase to keep number of public methods under 10.
      Open

      class ContextBase implements \SwaggerValidator\Interfaces\ContextBase
      {
      
          /**
           *
      Severity: Minor
      Found in src/Common/ContextBase.php by phpmd

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

      class ContextBase implements \SwaggerValidator\Interfaces\ContextBase
      {
      
          /**
           *
      Severity: Minor
      Found in src/Common/ContextBase.php by phpmd

      The class ContextBase has 21 fields. Consider redesigning ContextBase to keep the number of fields under 15.
      Open

      class ContextBase implements \SwaggerValidator\Interfaces\ContextBase
      {
      
          /**
           *
      Severity: Minor
      Found in src/Common/ContextBase.php by phpmd

      TooManyFields

      Since: 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 https://phpmd.org/rules/codesize.html#toomanyfields

      The class ContextBase has 49 public methods and attributes. Consider reducing the number of public items to less than 45.
      Open

      class ContextBase implements \SwaggerValidator\Interfaces\ContextBase
      {
      
          /**
           *
      Severity: Minor
      Found in src/Common/ContextBase.php by phpmd

      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

      Method setLocation has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function setLocation($value = null)
          {
              switch (strtolower($value)) {
                  case \SwaggerValidator\Common\FactorySwagger::LOCATION_BODY:
                  case 'body':
      Severity: Minor
      Found in src/Common/ContextBase.php - About 1 hr to fix

        Function setLocation has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            public function setLocation($value = null)
            {
                switch (strtolower($value)) {
                    case \SwaggerValidator\Common\FactorySwagger::LOCATION_BODY:
                    case 'body':
        Severity: Minor
        Found in src/Common/ContextBase.php - About 35 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 searchDataPath has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            public function searchDataPath($search, $nb = 1)
            {
                $ref  = $this->__get('DataPath');
                $find = null;
        
        Severity: Minor
        Found in src/Common/ContextBase.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 setLocation() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
        Open

            public function setLocation($value = null)
            {
                switch (strtolower($value)) {
                    case \SwaggerValidator\Common\FactorySwagger::LOCATION_BODY:
                    case 'body':
        Severity: Minor
        Found in src/Common/ContextBase.php by phpmd

        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 setCombined has a boolean flag argument $value, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function setCombined($value = false)
        Severity: Minor
        Found in src/Common/ContextBase.php by phpmd

        BooleanArgumentFlag

        Since: 1.4.0

        A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

        Example

        class Foo {
            public function bar($flag = true) {
            }
        }

        Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

        The method setDataValue has a boolean flag argument $isExisting, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function setDataValue($value = null, $isExisting = true)
        Severity: Minor
        Found in src/Common/ContextBase.php by phpmd

        BooleanArgumentFlag

        Since: 1.4.0

        A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

        Example

        class Foo {
            public function bar($flag = true) {
            }
        }

        Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

        The method __set uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                    else {
                        throw new Exception('Cannot find this Method : ' . $methodName);
                    }
        Severity: Minor
        Found in src/Common/ContextBase.php by phpmd

        ElseExpression

        Since: 1.4.0

        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($flag) {
                    // one branch
                } else {
                    // another branch
                }
            }
        }

        Source https://phpmd.org/rules/cleancode.html#elseexpression

        Avoid using static access to class '\SwaggerValidator\Common\Collection' in method '__toString'.
        Open

                return \SwaggerValidator\Common\Collection::jsonEncode($this->__debugInfo());
        Severity: Minor
        Found in src/Common/ContextBase.php by phpmd

        StaticAccess

        Since: 1.4.0

        Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

        Example

        class Foo
        {
            public function bar()
            {
                Bar::baz();
            }
        }

        Source https://phpmd.org/rules/cleancode.html#staticaccess

        Avoid using SwaggerValidator\Common\count() function in while loops.
        Open

                while ($find != $search && count($ref) > 0) {
                    $find = array_pop($ref);
                }
        Severity: Minor
        Found in src/Common/ContextBase.php by phpmd

        CountInLoopExpression

        Since: 2.7.0

        Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.

        Example

        class Foo {
        
          public function bar()
          {
            $array = array();
        
            for ($i = 0; count($array); $i++) {
              // ...
            }
          }
        }

        Source https://phpmd.org/rules/design.html#countinloopexpression

        Avoid excessively long variable names like $contextValidationCode. Keep variable name length under 20.
        Open

            protected $contextValidationCode = null;
        Severity: Minor
        Found in src/Common/ContextBase.php by phpmd

        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 $nb. Configured minimum length is 3.
        Open

            public function getLastDataPath($nb = 1)
        Severity: Minor
        Found in src/Common/ContextBase.php by phpmd

        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;
                }
            }
        }

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

        Avoid variables with short names like $nb. Configured minimum length is 3.
        Open

            public function searchDataPath($search, $nb = 1)
        Severity: Minor
        Found in src/Common/ContextBase.php by phpmd

        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;
                }
            }
        }

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

        The method __storeData is not named in camelCase.
        Open

            protected function __storeData($key, $value = null)
            {
                if (property_exists($this, $key)) {
                    $this->$key = $value;
                }
        Severity: Minor
        Found in src/Common/ContextBase.php by phpmd

        CamelCaseMethodName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name methods.

        Example

        class ClassName {
            public function get_name() {
            }
        }

        Source

        There are no issues that match your filters.

        Category
        Status