skqr/hateoas

View on GitHub
JsonApi/Serializer/ResourceObjectSerializer.php

Summary

Maintainability
B
4 hrs
Test Coverage

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

    public function serialize()
    {
        $metadata = $this->resource->getMetadata();
        $json = [
            'id' => $this->resource->id,
Severity: Minor
Found in JsonApi/Serializer/ResourceObjectSerializer.php - About 1 hr to fix

    Function serialize has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        public function serialize()
        {
            $metadata = $this->resource->getMetadata();
            $json = [
                'id' => $this->resource->id,
    Severity: Minor
    Found in JsonApi/Serializer/ResourceObjectSerializer.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 getResourceLinks has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function getResourceLinks(EntityResource $resource)
        {
            $links = [];
    
            foreach (
    Severity: Minor
    Found in JsonApi/Serializer/ResourceObjectSerializer.php - About 1 hr to fix

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

          private function getResourceLinks(EntityResource $resource)
          {
              $links = [];
      
              foreach (
      Severity: Minor
      Found in JsonApi/Serializer/ResourceObjectSerializer.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

      Avoid unused parameters such as '$resource'.
      Open

          private function getResourceLinks(EntityResource $resource)

      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 using static access to class '\GoIntegro\Hateoas\JsonApi\EntityResource' in method 'getResourceLinks'.
      Open

                  $collection = EntityResource::normalizeToManyRelation(
                      $collection, $relationship
                  );

      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 static access to class '\GoIntegro\Hateoas\JsonApi\EntityResource' in method 'getResourceLinks'.
      Open

                  EntityResource::validateToOneRelation($entity, $relationship);

      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 static access to class '\GoIntegro\Hateoas\JsonApi\EntityResource' in method 'getResourceLinks'.
      Open

                      $links[$relationship][] = EntityResource::getStringId($entity);

      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 static access to class '\GoIntegro\Hateoas\JsonApi\EntityResource' in method 'getResourceLinks'.
      Open

                  ) ? EntityResource::getStringId($entity) : NULL;

      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

      Space found before closing bracket of FOREACH loop
      Open

              foreach (

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

                  ) ? EntityResource::getStringId($entity) : NULL;

      Expected 1 space before "as"; 16 found
      Open

              foreach (

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

          {

      Space found after opening bracket of FOREACH loop
      Open

              foreach (

      Expected 1 space before "as"; 16 found
      Open

              foreach (

      Space found before closing bracket of FOREACH loop
      Open

              foreach (

      Space found after opening bracket of FOREACH loop
      Open

              foreach (

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

                          $field, $this->resource, $message

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

                          $field, $this->resource, $message

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

                      $collection, $relationship

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

                          $field, $this->resource, $message

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

                          $field, $this->resource, $message

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

                          static::ACCESS_VIEW, $entity

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

                          $field, $this->resource, $message

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

                          $field, $this->resource, $message

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

                      static::ACCESS_VIEW, $entity

      Expected 0 spaces after opening bracket; newline found
      Open

              foreach (

      Expected 0 spaces after opening bracket; newline found
      Open

              foreach (

      There are no issues that match your filters.

      Category
      Status