Component   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 62
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A resolveFastRoute() 0 6 1
A files() 0 8 1
A binders() 0 8 1
A resolveCustom() 0 4 1
1
<?php
2
3
namespace Mosaic\Routing;
4
5
use Mosaic\Common\Components\AbstractComponent;
6
use Mosaic\Routing\Loaders\LoaderChain;
7
use Mosaic\Routing\Loaders\LoadRoutesFromBinders;
8
use Mosaic\Routing\Loaders\LoadRoutesFromFile;
9
use Mosaic\Routing\Providers\FastRouteProvider;
10
11
/**
12
 * @method static $this fastRoute(RouteLoader $loader = null)
13
 */
14
final class Component extends AbstractComponent
15
{
16
    /**
17
     * @var LoaderChain
18
     */
19
    private $loader;
20
21
    /**
22
     * @param string      $implementation
23
     * @param RouteLoader $loader
24
     */
25 7
    protected function __construct(string $implementation, RouteLoader $loader = null)
26
    {
27 7
        $this->loader = new LoaderChain($loader ? [$loader] : []);
28 7
        parent::__construct($implementation);
29 7
    }
30
31
    /**
32
     * @return array
33
     */
34 6
    public function resolveFastRoute()
35
    {
36
        return [
37 6
            new FastRouteProvider($this->loader)
38
        ];
39
    }
40
41
    /**
42
     * @param \string[] ...$paths
43
     * @return $this
44
     */
45 2
    public function files(string ...$paths)
46
    {
47 2
        $this->loader->add(
48 2
            new LoadRoutesFromFile(...$paths)
49
        );
50
51 2
        return $this;
52
    }
53
54
    /**
55
     * @param RouteBinder[] ...$binders
56
     * @return $this
57
     */
58 2
    public function binders(RouteBinder ...$binders)
59
    {
60 2
        $this->loader->add(
61 2
            new LoadRoutesFromBinders(...$binders)
62
        );
63
64 2
        return $this;
65
    }
66
67
    /**
68
     * @param  callable $callback
69
     * @return array
70
     */
71 1
    public function resolveCustom(callable $callback) : array
72
    {
73 1
        return $callback($this->loader);
74
    }
75
}
76