sehrgutesoftware/laravel5-api

View on GitHub

Showing 35 of 37 total issues

Controller has 34 functions (exceeds 20 allowed). Consider refactoring.
Open

class Controller extends IlluminateController
{
    /**
     * Maps request parameters to database columns.
     *
Severity: Minor
Found in src/Laravel5_Api/Controller.php - About 4 hrs to fix

    File Controller.php has 318 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    namespace SehrGut\Laravel5_Api;
    
    use Illuminate\Database\Eloquent\Builder;
    Severity: Minor
    Found in src/Laravel5_Api/Controller.php - About 3 hrs to fix

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

      class Controller extends IlluminateController
      {
          /**
           * Maps request parameters to database columns.
           *
      Severity: Minor
      Found in src/Laravel5_Api/Controller.php by phpmd

      The class Controller has 29 non-getter- and setter-methods. Consider refactoring Controller to keep number of methods under 25.
      Open

      class Controller extends IlluminateController
      {
          /**
           * Maps request parameters to database columns.
           *
      Severity: Minor
      Found in src/Laravel5_Api/Controller.php by phpmd

      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

      Avoid excessively long variable names like $request_adapter_class. Keep variable name length under 20.
      Confirmed

          protected $request_adapter_class = RequestAdapter::class;
      Severity: Minor
      Found in src/Laravel5_Api/Controller.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

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

          protected function replaceWithIdsOrClear($model)
          {
              if (!$this->config['replace_with_ids']) {
                  // Remove all relatives from all relations on the model
                  $model->setRelations([]);
      Severity: Minor
      Found in src/Laravel5_Api/Plugins/RelationSplitter.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 validateInput has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function validateInput($only_present = false, $many = false)
          {
              $validator = $this->model_mapping->getValidatorFor($this->model);
              $raw_rules = $many ? $validator::getRulesMany() : $validator::getRules();
              $rules = $this->adaptRules($raw_rules);
      Severity: Minor
      Found in src/Laravel5_Api/Controller.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 filterByRequest has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function filterByRequest($query, $mapping = null)
          {
              $mapping = $mapping ?: $this->key_mapping;
      
              foreach ($mapping as $request_key => $db_key) {
      Severity: Minor
      Found in src/Laravel5_Api/Controller.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

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

          protected function validateInput($only_present = false, $many = false)
      Severity: Minor
      Found in src/Laravel5_Api/Controller.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 validateInput has a boolean flag argument $many, which is a certain sign of a Single Responsibility Principle violation.
      Open

          protected function validateInput($only_present = false, $many = false)
      Severity: Minor
      Found in src/Laravel5_Api/Controller.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 validate has a boolean flag argument $only_present, which is a certain sign of a Single Responsibility Principle violation.
      Confirmed

          public static function validate(array $input, $rules = null, $only_present = false)
      Severity: Minor
      Found in src/Laravel5_Api/Validator.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 getUrlFor has a boolean flag argument $absolute, which is a certain sign of a Single Responsibility Principle violation.
      Confirmed

          public function getUrlFor(Model $model, $absolute = true)
      Severity: Minor
      Found in src/Laravel5_Api/ModelMapping.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

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

          protected function createResource(array $attributes = null)
          {
              $input = is_null($attributes) ? $this->context->input : $attributes;
              $this->context->resource = new $this->model($input);
      
      
      Severity: Minor
      Found in src/Laravel5_Api/Controller.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 loadPlugin uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Confirmed

              } else {
                  throw new InvalidArgumentException();
              }
      Severity: Minor
      Found in src/Laravel5_Api/PluginLoader.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 '\Illuminate\Support\Facades\Log' in method 'authorizeAction'.
      Open

              Log::info('TestPlugin: called authorizeAction', ['context' => $this->context]);

      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 '\Illuminate\Support\Facades\Log' in method 'authorizeResource'.
      Open

              Log::info('TestPlugin: called authorizeResource', ['context' => $this->context]);

      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 unused local variables such as '$many'.
      Open

              $this->validateInput($only_present = false, $many = true);
      Severity: Minor
      Found in src/Laravel5_Api/Controller.php by phpmd

      UnusedLocalVariable

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

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

                  } else {
                      // Item is `key => value` -> directly map to model
                      if ($this->request_adapter->hasKey($request_key)) {
                          $query->where(
                              $db_key,
      Severity: Minor
      Found in src/Laravel5_Api/Controller.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 validateInput uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      $this->context->input = array_only($this->context->input, $input_whitelist);
                  }
      Severity: Minor
      Found in src/Laravel5_Api/Controller.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 '\Illuminate\Support\Facades\Log' in method 'adaptResourceQuery'.
      Open

              Log::info('TestPlugin: called adaptResourceQuery', ['context' => $this->context]);

      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

      Severity
      Category
      Status
      Source
      Language