Passed
Pull Request — master (#831)
by Maxim
06:08
created

RoutesBootloader   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
eloc 9
c 2
b 0
f 0
dl 0
loc 46
ccs 11
cts 11
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configureRouteGroups() 0 2 1
A init() 0 4 2
A defineRoutes() 0 2 1
A registerMiddlewareForRouteGroups() 0 5 3
A boot() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Bootloader\Http;
6
7
use Psr\Http\Server\MiddlewareInterface;
8
use Spiral\Boot\Bootloader\Bootloader;
9
use Spiral\Core\BinderInterface;
10
use Spiral\Router\GroupRegistry;
11
use Spiral\Router\Loader\Configurator\RoutingConfigurator;
12
13
abstract class RoutesBootloader extends Bootloader
14
{
15 267
    public function init(HttpBootloader $http): void
16
    {
17 267
        foreach ($this->globalMiddleware() as $middleware) {
18 267
            $http->addMiddleware($middleware);
19
        }
20
    }
21
22 267
    public function boot(RoutingConfigurator $routes, BinderInterface $binder, GroupRegistry $groups): void
0 ignored issues
show
Unused Code introduced by
The parameter $binder is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

22
    public function boot(RoutingConfigurator $routes, /** @scrutinizer ignore-unused */ BinderInterface $binder, GroupRegistry $groups): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
    {
24 267
        $this->registerMiddlewareForRouteGroups($groups, $this->middlewareGroups());
25
26 267
        $this->configureRouteGroups($groups);
27 267
        $this->defineRoutes($routes);
28
    }
29
30
    /**
31
     * Override this method to configure application routes
32
     */
33
    protected function defineRoutes(RoutingConfigurator $routes): void
34
    {
35
    }
36
37
    /**
38
     * Override this method to configure route groups
39
     */
40
    protected function configureRouteGroups(GroupRegistry $groups): void
0 ignored issues
show
Unused Code introduced by
The parameter $groups is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

40
    protected function configureRouteGroups(/** @scrutinizer ignore-unused */ GroupRegistry $groups): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
    {
42
    }
43
44
    /**
45
     * @return array<MiddlewareInterface|class-string<MiddlewareInterface>>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<MiddlewareInterfac...g<MiddlewareInterface>> at position 4 could not be parsed: Unknown type name 'class-string' at position 4 in array<MiddlewareInterface|class-string<MiddlewareInterface>>.
Loading history...
46
     */
47
    abstract protected function globalMiddleware(): array;
48
49
    /**
50
     * @return array<string,array<MiddlewareInterface|class-string<MiddlewareInterface>>>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string,array<Middl...<MiddlewareInterface>>> at position 8 could not be parsed: Unknown type name 'class-string' at position 8 in array<string,array<MiddlewareInterface|class-string<MiddlewareInterface>>>.
Loading history...
51
     */
52
    abstract protected function middlewareGroups(): array;
53
54 267
    private function registerMiddlewareForRouteGroups(GroupRegistry $registry, array $groups): void
55
    {
56 267
        foreach ($groups as $group => $middlewares) {
57 267
            foreach ($middlewares as $middleware) {
58 267
                $registry->getGroup($group)->addMiddleware($middleware);
59
            }
60
        }
61
    }
62
}
63