sehrgutesoftware/laravel5-api

View on GitHub
src/Laravel5_Api/Controller.php

Summary

Maintainability
C
1 day
Test Coverage

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

      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

      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 class Controller has a coupling between objects value of 25. Consider to reduce the number of dependencies under 13.
      Wontfix

      class Controller extends IlluminateController
      {
          /**
           * Maps request parameters to database columns.
           *
      Severity: Minor
      Found in src/Laravel5_Api/Controller.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

      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

      Avoid using static access to class '\Illuminate\Support\Facades\DB' in method 'createMany'.
      Open

              DB::transaction(function () {
                  foreach ($this->context->input as $attributes) {
                      $this->createResource($attributes);
                      $this->context->collection->push($this->context->resource);
                  }
      Severity: Minor
      Found in src/Laravel5_Api/Controller.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

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

      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

      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

      There are no issues that match your filters.

      Category
      Status