skqr/hateoas

View on GitHub
JsonApi/Request/Parser.php

Summary

Maintainability
A
3 hrs
Test Coverage

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

    public function parse(Request $request)
    {
        $content = $request->getContent();

        if (!empty($content) && self::HTTP_DELETE == $request->getMethod()) {
Severity: Minor
Found in JsonApi/Request/Parser.php - About 1 hr to fix

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

            ResourceEntityMapper $resourceEntityMapper,
            DocNavigator $docNavigator,
            FilterParser $filterParser,
            PaginationParser $paginationParser,
            BodyParser $bodyParser,
    Severity: Major
    Found in JsonApi/Request/Parser.php - About 1 hr to fix

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

          public function parse(Request $request)
          {
              $content = $request->getContent();
      
              if (!empty($content) && self::HTTP_DELETE == $request->getMethod()) {
      Severity: Minor
      Found in JsonApi/Request/Parser.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

      The method __construct has 10 parameters. Consider reducing the number of parameters to less than 10.
      Open

          public function __construct(
              ResourceEntityMapper $resourceEntityMapper,
              DocNavigator $docNavigator,
              FilterParser $filterParser,
              PaginationParser $paginationParser,
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpmd

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

      class Parser
      {
          const HTTP_OPTIONS = 'OPTIONS',
              HTTP_HEAD = 'HEAD',
              HTTP_GET = 'GET',
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpmd

      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

      Missing class import via use statement (line '330', column '23').
      Open

                  throw new \Exception(self::ERROR_NO_API_BASE_PATH);
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpmd

      MissingImport

      Since: 2.7.0

      Importing all external classes in a file through use statements makes them clearly visible.

      Example

      function make() {
          return new \stdClass();
      }

      Source http://phpmd.org/rules/cleancode.html#MissingImport

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

                      } else {
                          $order = Params::DESCENDING_ORDER;
                          $field = substr($field, 1);
                      }
      Severity: Minor
      Found in JsonApi/Request/Parser.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

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

              } else {
                  $fields = [$primaryType => $callback($fields)];
              }
      Severity: Minor
      Found in JsonApi/Request/Parser.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 unused private fields such as '$magicServices'.
      Open

          private $magicServices;
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpmd

      UnusedPrivateField

      Since: 0.2

      Detects when a private field is declared and/or assigned a value, but not used.

      Example

      class Something
      {
          private static $FOO = 2; // Unused
          private $i = 5; // Unused
          private $j = 6;
          public function addOne()
          {
              return $this->j++;
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield

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

          private $mm;
      Severity: Minor
      Found in JsonApi/Request/Parser.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 $mm. Configured minimum length is 3.
      Open

              MetadataMinerInterface $mm,
      Severity: Minor
      Found in JsonApi/Request/Parser.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

      Multi-line function declarations must define one parameter per line
      Open

              Request $request, $part = self::PRIMARY_RESOURCE_TYPE
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      Expected 1 space after FUNCTION keyword; 0 found
      Open

              $callback = function($fields) {
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      Expected 1 space after FUNCTION keyword; 0 found
      Open

              $callback = function($sort, $type) use (&$sorting) {
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
      Open

          {
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
      Open

          {
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
      Open

          {
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      TRUE, FALSE and NULL must be lowercase; expected "null" but found "NULL"
      Open

              return isset($path[$part]) ? $path[$part] : NULL;
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      Expected 1 space after FUNCTION keyword; 0 found
      Open

              array_walk($include, function(&$relationship) {
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      Only one argument is allowed per line in a multi-line function call
      Open

                      self::ERROR_ACTION_NOT_ALLOWED, implode(', ', $allowedMethods)
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      Only one argument is allowed per line in a multi-line function call
      Open

                  $request, self::PRIMARY_RESOURCE_RELATIONSHIP
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      Line exceeds 120 characters; contains 133 characters
      Open

              ERROR_ACTION_NOT_ALLOWED = "The attempted action is not allowed on the requested resource. Supported HTTP methods are [%s].",
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      Inline control structures are not allowed
      Open

              if (isset($map[$type])) return $map[$type];
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      Line exceeds 120 characters; contains 122 characters
      Open

              ERROR_MULTIPLE_IDS_WITH_RELATIONSHIP = "Multiple Ids are not supported when requesting a resource field or link.",
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      Line exceeds 120 characters; contains 183 characters
      Open

              ERROR_RELATIONSHIP_UNDEFINED = "The requested relationship is undefined or can only be accessed through its own URL, filtering by its relationship with the current resource.",
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      Expected 0 spaces after opening bracket; newline found
      Open

                  if (
      Severity: Minor
      Found in JsonApi/Request/Parser.php by phpcodesniffer

      There are no issues that match your filters.

      Category
      Status