ExecutionProvider::getRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
4
namespace Xervice\Web\Business\Model\Executor;
5
6
7
use Symfony\Component\HttpFoundation\Request;
8
use Xervice\Routing\Business\RoutingFacade;
9
use Xervice\Web\Business\Model\Executor\ResponseHandler\ResponseHandlerInterface;
10
use Xervice\Web\Business\Model\Executor\Validator\ValidatorInterface;
11
12
class ExecutionProvider implements ExecutionProviderInterface
13
{
14
    /**
15
     * @var \Xervice\Routing\Business\RoutingFacade
16
     */
17
    private $routeFacade;
18
19
    /**
20
     * @var \Xervice\Web\Business\Model\Executor\ResponseHandler\ResponseHandlerInterface
21
     */
22
    private $responseHandler;
23
24
    /**
25
     * @var \Xervice\Web\Business\Model\Executor\Validator\ValidatorInterface
26
     */
27
    private $validator;
28
29
    /**
30
     * ExecutionProvider constructor.
31
     *
32
     * @param \Xervice\Routing\Business\RoutingFacade $routeFacade
33
     * @param \Xervice\Web\Business\Model\Executor\ResponseHandler\ResponseHandlerInterface $responseHandler
34
     * @param \Xervice\Web\Business\Model\Executor\Validator\ValidatorInterface $validator
35
     */
36 2
    public function __construct(
37
        RoutingFacade $routeFacade,
38
        ResponseHandlerInterface $responseHandler,
39
        ValidatorInterface $validator
40
    ) {
41 2
        $this->routeFacade = $routeFacade;
42 2
        $this->responseHandler = $responseHandler;
43 2
        $this->validator = $validator;
44 2
    }
45
46
    public function execute(): void
47
    {
48
        $this->executeRequest(
49
            $this->getRequest()
50
        );
51
    }
52
53
    /**
54
     * @param string $url
55
     */
56 2
    public function executeUrl(string $url): void
57
    {
58 2
        $this->handleData(
59 2
            $this->routeFacade->matchUrl($url)
60
        );
61 2
    }
62
63
    /**
64
     * @param \Symfony\Component\HttpFoundation\Request $request
65
     */
66
    public function executeRequest(Request $request): void
67
    {
68
        $this->handleData(
69
            $this->routeFacade->matchRequest($request)
70
        );
71
    }
72
73
    /**
74
     * @return \Symfony\Component\HttpFoundation\Request
75
     */
76
    private function getRequest(): Request
77
    {
78
        return Request::createFromGlobals();
79
    }
80
81
    /**
82
     * @param array $executionData
83
     */
84 2
    private function handleData(array $executionData): void
85
    {
86 2
        $this->validator->validateExecutionData($executionData);
87 2
        $this->responseHandler->handleResponse($executionData);
88
    }
89
}