canax/router

View on GitHub

Showing 66 of 66 total issues

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

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

class RouteHandler
{
    /**
     * @var ContainerInterface $di the dependency/service container.
     */
Severity: Minor
Found in src/Route/RouteHandler.php by phpmd

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

    File RouteHandler.php has 270 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    namespace Anax\Route;
    
    use Anax\Commons\ContainerInjectableInterface;
    Severity: Minor
    Found in src/Route/RouteHandler.php - About 2 hrs to fix

      Method handleAsControllerAction has 54 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function handleAsControllerAction(array $callable)
          {
              $class = $callable[0];
              $action = $callable[1];
              $args = $callable[2];
      Severity: Major
      Found in src/Route/RouteHandler.php - About 2 hrs to fix

        Function handleAsControllerAction has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function handleAsControllerAction(array $callable)
            {
                $class = $callable[0];
                $action = $callable[1];
                $args = $callable[2];
        Severity: Minor
        Found in src/Route/RouteHandler.php - About 2 hrs 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 handleAsInvocableClass has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function handleAsInvocableClass(string $class)
            {
                $obj = new $class();
                // $class = $callable[0];
                $action = "__invoke";
        Severity: Minor
        Found in src/Route/RouteHandler.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 handleAsInvocableClass has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function handleAsInvocableClass(string $class)
            {
                $obj = new $class();
                // $class = $callable[0];
                $action = "__invoke";
        Severity: Minor
        Found in src/Route/RouteHandler.php - About 1 hr to fix

          Avoid excessively long variable names like $matchedQueryToMountPath. Keep variable name length under 20.
          Open

                  $matchedQueryToMountPath = strncmp($query, $mount, $charsToMatch) === 0 ? true : false;
          Severity: Minor
          Found in src/Route/RouteMatcher.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

          Method match has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function match(
                  ?string $mount,
                  ?string $relativePath,
                  ?string $absolutePath,
                  ?string $query,
          Severity: Minor
          Found in src/Route/RouteMatcher.php - About 1 hr to fix

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

                public function match(
                    ?string $mount,
                    ?string $relativePath,
                    ?string $absolutePath,
                    ?string $query,
            Severity: Minor
            Found in src/Route/RouteMatcher.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 handle has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                public function handle(
                    ?string $method,
                    ?string $path,
                    $action,
                    array $arguments = [],
            Severity: Minor
            Found in src/Route/RouteHandler.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 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 handle has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function handle(
                    ?string $method,
                    ?string $path,
                    $action,
                    array $arguments = [],
            Severity: Minor
            Found in src/Route/RouteHandler.php - About 1 hr to fix

              Method isControllerAction has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function isControllerAction(
                      ?string $method,
                      ?string $path,
                      string $class
                  ) {
              Severity: Minor
              Found in src/Route/RouteHandler.php - About 1 hr to fix

                Function isControllerAction has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function isControllerAction(
                        ?string $method,
                        ?string $path,
                        string $class
                    ) {
                Severity: Minor
                Found in src/Route/RouteHandler.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

                Consider simplifying this complex logical expression.
                Open

                        if ($di
                            && is_array($action)
                            && isset($action[0])
                            && isset($action[1])
                            && is_string($action[0])
                Severity: Major
                Found in src/Route/RouteHandler.php - About 1 hr to fix

                  Avoid variables with short names like $di. Configured minimum length is 3.
                  Open

                      public function getHandlerType(ContainerInterface $di = null) : string
                  Severity: Minor
                  Found in src/Route/Route.php by phpmd

                  ShortVariable

                  Since: 0.2

                  Detects when a field, local, or parameter has a very short name.

                  Example

                  class Something {
                      private $q = 15; // VIOLATION - Field
                      public static function main( array $as ) { // VIOLATION - Formal
                          $r = 20 + $this->q; // VIOLATION - Local
                          for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                              $r += $this->q;
                          }
                      }
                  }

                  Source https://phpmd.org/rules/naming.html#shortvariable

                  Avoid variables with short names like $di. Configured minimum length is 3.
                  Open

                      protected $di;
                  Severity: Minor
                  Found in src/Route/RouteHandler.php by phpmd

                  ShortVariable

                  Since: 0.2

                  Detects when a field, local, or parameter has a very short name.

                  Example

                  class Something {
                      private $q = 15; // VIOLATION - Field
                      public static function main( array $as ) { // VIOLATION - Formal
                          $r = 20 + $this->q; // VIOLATION - Local
                          for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                              $r += $this->q;
                          }
                      }
                  }

                  Source https://phpmd.org/rules/naming.html#shortvariable

                  Avoid variables with short names like $di. Configured minimum length is 3.
                  Open

                          ContainerInterface $di = null
                  Severity: Minor
                  Found in src/Route/RouteHandler.php by phpmd

                  ShortVariable

                  Since: 0.2

                  Detects when a field, local, or parameter has a very short name.

                  Example

                  class Something {
                      private $q = 15; // VIOLATION - Field
                      public static function main( array $as ) { // VIOLATION - Formal
                          $r = 20 + $this->q; // VIOLATION - Local
                          for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                              $r += $this->q;
                          }
                      }
                  }

                  Source https://phpmd.org/rules/naming.html#shortvariable

                  Severity
                  Category
                  Status
                  Source
                  Language