lib/Ajde/Controller.php

Summary

Maintainability
B
5 hrs
Test Coverage

invoke accesses the super-global variable $_SERVER.
Open

    public function invoke($action = null, $format = null)
    {
        $timerKey = Ajde::app()->addTimer((string) $this->_route);
        $action = issetor($action, $this->getAction());
        $format = issetor($format, $this->getFormat());
Severity: Minor
Found in lib/Ajde/Controller.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Method invoke has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function invoke($action = null, $format = null)
    {
        $timerKey = Ajde::app()->addTimer((string) $this->_route);
        $action = issetor($action, $this->getAction());
        $format = issetor($format, $this->getFormat());
Severity: Minor
Found in lib/Ajde/Controller.php - About 1 hr to fix

    Function fromRoute has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function fromRoute(Ajde_Core_Route $route)
        {
            if ($controller = $route->getController()) {
                $moduleController = ucfirst($route->getModule()).ucfirst($controller).'Controller';
            } else {
    Severity: Minor
    Found in lib/Ajde/Controller.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 invoke has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        public function invoke($action = null, $format = null)
        {
            $timerKey = Ajde::app()->addTimer((string) $this->_route);
            $action = issetor($action, $this->getAction());
            $format = issetor($format, $this->getFormat());
    Severity: Minor
    Found in lib/Ajde/Controller.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 fromRoute has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function fromRoute(Ajde_Core_Route $route)
        {
            if ($controller = $route->getController()) {
                $moduleController = ucfirst($route->getModule()).ucfirst($controller).'Controller';
            } else {
    Severity: Minor
    Found in lib/Ajde/Controller.php - About 1 hr to fix

      Missing class import via use statement (line '161', column '27').
      Open

                      throw new Ajde_Exception(sprintf('beforeInvoke() must return either TRUE or FALSE'));
      Severity: Minor
      Found in lib/Ajde/Controller.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

      Missing class import via use statement (line '149', column '30').
      Open

                  $exception = new Ajde_Core_Exception_Routing(sprintf('Action %s for module %s not found',
      Severity: Minor
      Found in lib/Ajde/Controller.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

      Missing class import via use statement (line '215', column '19').
      Open

              throw new Ajde_Core_Exception_Deprecated();
      Severity: Minor
      Found in lib/Ajde/Controller.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

      Missing class import via use statement (line '96', column '34').
      Open

                      $exception = new Exception("Controller $moduleController for module {$route->getModule()} not found");
      Severity: Minor
      Found in lib/Ajde/Controller.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

      Missing class import via use statement (line '84', column '38').
      Open

                      $notFoundRoute = new Ajde_Core_Route($errorRoutes[Ajde_Http_Response::RESPONSE_TYPE_NOTFOUND]);
      Severity: Minor
      Found in lib/Ajde/Controller.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

      Missing class import via use statement (line '24', column '22').
      Open

              $route = new Ajde_Core_Route($this->getAction());
      Severity: Minor
      Found in lib/Ajde/Controller.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

      Missing class import via use statement (line '92', column '34').
      Open

                      $exception = new Ajde_Core_Exception_Routing("Controller $moduleController for module {$route->getModule()} not found",
      Severity: Minor
      Found in lib/Ajde/Controller.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

      Missing class import via use statement (line '234', column '19').
      Open

              throw new Ajde_Core_Exception_Deprecated();
      Severity: Minor
      Found in lib/Ajde/Controller.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

      Missing class import via use statement (line '34', column '19').
      Open

              throw new Ajde_Exception('Call to undefined method '.get_class($this)."::$method()", 90006);
      Severity: Minor
      Found in lib/Ajde/Controller.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

      Missing class import via use statement (line '205', column '27').
      Open

                      throw new Ajde_Exception(sprintf('beforeRender() must return either TRUE or FALSE'));
      Severity: Minor
      Found in lib/Ajde/Controller.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

      Avoid using static access to class 'Ajde_Http_Response' in method 'fromRoute'.
      Open

                          Ajde_Http_Response::setResponseType(404);
      Severity: Minor
      Found in lib/Ajde/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

      Avoid using static access to class 'Ajde' in method 'invoke'.
      Open

                  Ajde::routingError($exception);
      Severity: Minor
      Found in lib/Ajde/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

      Avoid using static access to class 'Ajde_View' in method 'getView'.
      Open

                  $this->_view = Ajde_View::fromController($this);
      Severity: Minor
      Found in lib/Ajde/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 fromRoute uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      // Normal exception here to prevent [Class 'Ajde_Exception' not found] errors...
                      $exception = new Exception("Controller $moduleController for module {$route->getModule()} not found");
                  }
      Severity: Minor
      Found in lib/Ajde/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 'Ajde_View' in method 'loadTemplate'.
      Open

              $view = Ajde_View::fromController($this);
      Severity: Minor
      Found in lib/Ajde/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 fromRoute uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  $moduleController = ucfirst($route->getModule()).'Controller';
              }
      Severity: Minor
      Found in lib/Ajde/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 'Ajde' in method 'fromRoute'.
      Open

                  Ajde::routingError($exception);
      Severity: Minor
      Found in lib/Ajde/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

      Avoid using static access to class 'Ajde_Event' in method '__fallback'.
      Open

                  return Ajde_Event::trigger('Ajde_Controller', 'call', [$method, $arguments]);
      Severity: Minor
      Found in lib/Ajde/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

      Avoid assigning values to variables in if clauses and the like (line '74', column '13').
      Open

          public static function fromRoute(Ajde_Core_Route $route)
          {
              if ($controller = $route->getController()) {
                  $moduleController = ucfirst($route->getModule()).ucfirst($controller).'Controller';
              } else {
      Severity: Minor
      Found in lib/Ajde/Controller.php by phpmd

      IfStatementAssignment

      Since: 2.7.0

      Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($foo = 'bar') { // possible typo
                  // ...
              }
              if ($baz = 0) { // always false
                  // ...
              }
          }
      }

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

      Avoid using static access to class 'Ajde_Event' in method '__fallback'.
      Open

              if (Ajde_Event::has('Ajde_Controller', 'call')) {
      Severity: Minor
      Found in lib/Ajde/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 fromRoute() contains an exit expression.
      Open

                          die('<h2>Ouch, something broke.</h2><p>This is serious. We tried to give you a nice error page, but even that failed.</p><button onclick="location.href=\''.config('app.rootUrl').'\';">Go back to homepage</button>');
      Severity: Minor
      Found in lib/Ajde/Controller.php by phpmd

      ExitExpression

      Since: 0.2

      An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

      Example

      class Foo {
          public function bar($param)  {
              if ($param === 42) {
                  exit(23);
              }
          }
      }

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

      TODO found
      Open

                      // TODO:
      Severity: Minor
      Found in lib/Ajde/Controller.php by fixme

      TODO found
      Open

              // TODO:
      Severity: Minor
      Found in lib/Ajde/Controller.php by fixme

      TODO found
      Open

                      // TODO:
      Severity: Minor
      Found in lib/Ajde/Controller.php by fixme

      The property $_route is not named in camelCase.
      Open

      class Ajde_Controller extends Ajde_Object_Standard
      {
          /**
           * @var Ajde_View
           */
      Severity: Minor
      Found in lib/Ajde/Controller.php by phpmd

      CamelCasePropertyName

      Since: 0.2

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

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      The property $_view is not named in camelCase.
      Open

      class Ajde_Controller extends Ajde_Object_Standard
      {
          /**
           * @var Ajde_View
           */
      Severity: Minor
      Found in lib/Ajde/Controller.php by phpmd

      CamelCasePropertyName

      Since: 0.2

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

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      The class Ajde_Controller is not named in CamelCase.
      Open

      class Ajde_Controller extends Ajde_Object_Standard
      {
          /**
           * @var Ajde_View
           */
      Severity: Minor
      Found in lib/Ajde/Controller.php by phpmd

      CamelCaseClassName

      Since: 0.2

      It is considered best practice to use the CamelCase notation to name classes.

      Example

      class class_name {
      }

      Source

      The method __fallback is not named in camelCase.
      Open

          public function __fallback($method, $arguments)
          {
              if (Ajde_Event::has('Ajde_Controller', 'call')) {
                  return Ajde_Event::trigger('Ajde_Controller', 'call', [$method, $arguments]);
              }
      Severity: Minor
      Found in lib/Ajde/Controller.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