divineniiquaye/flight-routing

View on GitHub

Showing 59 of 59 total issues

Function resolveParameters has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

    protected function resolveParameters(array $refParameters, array $arguments): array
    {
        $parameters = [];
        $nullable = 0;

Severity: Minor
Found in src/Handlers/RouteInvoker.php - About 6 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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    public function piped(string ...$to): self
    {
        if ($this->asRoute) {
            foreach ($to as $middleware) {
                $this->routes[$this->defaultIndex]['middlewares'][$middleware] = true;
Severity: Major
Found in src/Traits/PrototypeTrait.php and 1 other location - About 5 hrs to fix
src/Traits/PrototypeTrait.php on lines 340..361

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 184.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    public function scheme(string ...$schemes): self
    {
        if ($this->asRoute) {
            foreach ($schemes as $scheme) {
                $this->routes[$this->defaultIndex]['schemes'][$scheme] = true;
Severity: Major
Found in src/Traits/PrototypeTrait.php and 1 other location - About 5 hrs to fix
src/Traits/PrototypeTrait.php on lines 437..458

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 184.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

File PrototypeTrait.php has 323 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php declare(strict_types=1);

/*
 * This file is part of Flight Routing.
 *
Severity: Minor
Found in src/Traits/PrototypeTrait.php - About 3 hrs to fix

    Function load has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

        public function load(array $annotations): RouteCollection
        {
            foreach ($annotations as $annotation) {
                $reflection = $annotation['type'];
                $attributes = $annotation['attributes'] ?? [];
    Severity: Minor
    Found in src/Annotation/Listener.php - About 3 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 buildCache has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function buildCache(RouteCollection $collection, bool $doCache): string
        {
            $dynamicRoutes = $dynamicVar = $staticRoutes = [];
            $dynamicString = ":static function (string \$path): ?array {\n      ";
    
    
    Severity: Minor
    Found in src/Traits/CacheTrait.php - About 3 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 addRoute has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function addRoute(RouteCollection $collection, Route $route, mixed $handler): RouteCollection
        {
            if (true !== $handler) {
                if (empty($route->path)) {
                    throw new InvalidAnnotationException('Attributed method route path empty');
    Severity: Minor
    Found in src/Annotation/Listener.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

    RouteCollection has 22 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class RouteCollection implements \Countable, \ArrayAccess
    {
        use Traits\PrototypeTrait;
    
        /**
    Severity: Minor
    Found in src/RouteCollection.php - About 2 hrs to fix

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

          private static function interpolate(string $uriRoute, array $uriVars, array $parameters): string
          {
              $required = []; // Parameters required which are missing.
              $replaces = self::URI_FIXERS;
      
      
      Severity: Minor
      Found in src/RouteCompiler.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

      Method resolveParameters has 48 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function resolveParameters(array $refParameters, array $arguments): array
          {
              $parameters = [];
              $nullable = 0;
      
      
      Severity: Minor
      Found in src/Handlers/RouteInvoker.php - About 1 hr to fix

        Function __invoke has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            public function __invoke(mixed $handler, array $arguments): mixed
            {
                if (\is_string($handler)) {
                    $handler = \ltrim($handler, '\\');
        
        
        Severity: Minor
        Found in src/Handlers/RouteInvoker.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 domain has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            public function domain(string ...$domains): self
            {
                $resolver = static function (array &$route, array $domains): void {
                    foreach ($domains as $domain) {
                        if (1 === \preg_match('/^(?:([a-z]+)\:\/{2})?([^\/]+)?$/u', $domain, $m, \PREG_UNMATCHED_AS_NULL)) {
        Severity: Minor
        Found in src/Traits/PrototypeTrait.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 export has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function export(mixed $value, string $indent = ''): string
            {
                switch (true) {
                    case [] === $value:
                        return '[]';
        Severity: Minor
        Found in src/Traits/CacheTrait.php - About 1 hr to fix

          Method buildCache has 44 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function buildCache(RouteCollection $collection, bool $doCache): string
              {
                  $dynamicRoutes = $dynamicVar = $staticRoutes = [];
                  $dynamicString = ":static function (string \$path): ?array {\n      ";
          
          
          Severity: Minor
          Found in src/Traits/CacheTrait.php - About 1 hr to fix

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                public function placeholder(string $variable, string|array $regexp): self
                {
                    if ($this->asRoute) {
                        $this->routes[$this->defaultIndex]['placeholders'][$variable] = $regexp;
                    } elseif (-1 === $this->defaultIndex && empty($this->groups)) {
            Severity: Major
            Found in src/Traits/PrototypeTrait.php and 1 other location - About 1 hr to fix
            src/Traits/PrototypeTrait.php on lines 162..176

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 116.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                public function default(string $variable, mixed $default): self
                {
                    if ($this->asRoute) {
                        $this->routes[$this->defaultIndex]['defaults'][$variable] = $default;
                    } elseif (-1 === $this->defaultIndex && empty($this->groups)) {
            Severity: Major
            Found in src/Traits/PrototypeTrait.php and 1 other location - About 1 hr to fix
            src/Traits/PrototypeTrait.php on lines 201..216

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 116.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Function injectGroups has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                private function injectGroups(string $prefix, array &$collection, int &$count): void
                {
                    $unnamedRoutes = [];
            
                    foreach ($this->groups as $group) {
            Severity: Minor
            Found in src/RouteCollection.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 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function addRoute(RouteCollection $collection, Route $route, mixed $handler): RouteCollection
                {
                    if (true !== $handler) {
                        if (empty($route->path)) {
                            throw new InvalidAnnotationException('Attributed method route path empty');
            Severity: Minor
            Found in src/Annotation/Listener.php - About 1 hr to fix

              Method interpolate has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private static function interpolate(string $uriRoute, array $uriVars, array $parameters): string
                  {
                      $required = []; // Parameters required which are missing.
                      $replaces = self::URI_FIXERS;
              
              
              Severity: Minor
              Found in src/RouteCompiler.php - About 1 hr to fix

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

                    protected function resolveHandler(mixed $handler, string $namespace = null): mixed
                    {
                        if (empty($namespace)) {
                            return $handler;
                        }
                Severity: Minor
                Found in src/Traits/PrototypeTrait.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

                Severity
                Category
                Status
                Source
                Language