canax/router

View on GitHub
src/Route/Router.php

Summary

Maintainability
B
5 hrs
Test Coverage

The class Router has 15 public methods. Consider refactoring Router to keep number of public methods under 10.
Open

class Router implements ContainerInjectableInterface
{
    use ContainerInjectableTrait;


Severity: Minor
Found in src/Route/Router.php by phpmd

TooManyPublicMethods

Since: 0.1

A class with too many public 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'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

Router has 23 functions (exceeds 20 allowed). Consider refactoring.
Open

class Router implements ContainerInjectableInterface
{
    use ContainerInjectableTrait;


Severity: Minor
Found in src/Route/Router.php - About 2 hrs to fix

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

        public function handle($path, $method = null)
        {
            try {
                $match = false;
                foreach ($this->routes as $route) {
    Severity: Minor
    Found in src/Route/Router.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 addRoute has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

            $method,
            $mount = null,
            $path = null,
            $handler = null,
            string $info = null
    Severity: Minor
    Found in src/Route/Router.php - About 35 mins to fix

      Avoid too many return statements within this method.
      Open

                  return $this->handleInternal("500", $e->getMessage());
      Severity: Major
      Found in src/Route/Router.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                    return $this->handleInternal("500", $e->getMessage());
        Severity: Major
        Found in src/Route/Router.php - About 30 mins to fix

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

              public function addRoutes(array $routes) : object
              {
                  if (!(isset($routes["routes"]) && is_array($routes["routes"]))) {
                      throw new ConfigurationException("No routes found, missing key 'routes' in configuration array.");
                  }
          Severity: Minor
          Found in src/Route/Router.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

          Avoid unused local variables such as '$match'.
          Open

                      $match = false;
          Severity: Minor
          Found in src/Route/Router.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

          There are no issues that match your filters.

          Category
          Status