Passed
Push — master ( 4a62ef...fa5d77 )
by Mike
02:24
created

RoutingFactory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 88%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 80
ccs 22
cts 25
cp 0.88
rs 10
c 0
b 0
f 0
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A createMatcher() 0 5 1
A createContext() 0 4 1
A createRouteCollection() 0 4 1
A createRequestContext() 0 8 1
A createUrlMatcher() 0 5 1
A getRouteCollection() 0 7 2
A createRequest() 0 3 1
1
<?php
2
3
4
namespace Xervice\Routing;
5
6
7
use DataProvider\RoutingContextDataProvider;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\Routing\Matcher\UrlMatcher;
10
use Symfony\Component\Routing\RequestContext;
11
use Symfony\Component\Routing\RouteCollection as SymfonyRouteCollection;
12
use Xervice\Core\Factory\AbstractFactory;
13
use Xervice\Routing\Business\Matcher\MatchProvider;
14
use Xervice\Routing\Business\Matcher\MatchProviderInterface;
15
use Xervice\Routing\Business\Route\RouteCollection;
16
use Xervice\Routing\Business\Route\RouteCollectionInterface;
17
18
/**
19
 * @method \Xervice\Routing\RoutingConfig getConfig()
20
 */
21
class RoutingFactory extends AbstractFactory
22
{
23
    /**
24
     * @var \Xervice\Routing\Business\Route\RouteCollectionInterface
25
     */
26
    private $routeCollection;
27
28
    /**
29
     * @return \Xervice\Routing\Business\Matcher\MatchProvider
30
     */
31 3
    public function createMatcher(): MatchProviderInterface
32
    {
33 3
        return new MatchProvider(
34 3
            $this->createUrlMatcher(),
35 3
            $this->createRequest()
36
        );
37
    }
38
39
    /**
40
     * @return \Symfony\Component\Routing\Matcher\UrlMatcher
41
     */
42 3
    public function createUrlMatcher(): UrlMatcher
43
    {
44 3
        return new UrlMatcher(
45 3
            $this->getRouteCollection()->getRouteCollection(),
46 3
            $this->createRequestContext()
47
        );
48
    }
49
50
    /**
51
     * @return \Symfony\Component\Routing\RequestContext
52
     */
53 3
    public function createRequestContext(): RequestContext
54
    {
55 3
        $context = new RequestContext();
56 3
        $context->fromRequest(
57 3
            $this->createRequest()
58
        );
59
60 3
        return $context;
61
    }
62
63
    /**
64
     * @return \Symfony\Component\HttpFoundation\Request
65
     */
66 3
    public function createRequest(): Request
67
    {
68 3
        return Request::createFromGlobals();
69
    }
70
71
    /**
72
     * @return \DataProvider\RoutingContextDataProvider
73
     */
74
    public function createContext(): RoutingContextDataProvider
75
    {
76
        return (new RoutingContextDataProvider())->setContext(
77
            $this->getConfig()->getContext()
78
        );
79
    }
80
81
    /**
82
     * @return \Xervice\Routing\Business\Route\RouteCollectionInterface
83
     */
84 1
    public function createRouteCollection(): RouteCollectionInterface
85
    {
86 1
        return new RouteCollection(
87 1
            new SymfonyRouteCollection()
88
        );
89
    }
90
91
    /**
92
     * @return \Xervice\Routing\Business\Route\RouteCollectionInterface
93
     */
94 3
    public function getRouteCollection(): RouteCollectionInterface
95
    {
96 3
        if ($this->routeCollection === null) {
97 1
            $this->routeCollection = $this->createRouteCollection();
98
        }
99
100 3
        return $this->routeCollection;
101
    }
102
}