Completed
Push — master ( 5eae2e...40f0f7 )
by Park Jong-Hun
02:53
created

ParameterMapper::setRouterMap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Core\ControllerDispatcher;
4
5
use Prob\Rewrite\Request;
6
use Prob\Handler\ParameterMap;
7
use Prob\Router\Map;
8
use Core\ViewModel;
9
use Prob\Router\Matcher;
10
11
class ParameterMapper
12
{
13
14
    /**
15
     * @var Request
16
     */
17
    private $request;
18
19
    /**
20
     * @var ViewModel
21
     */
22
    private $viewModel;
23
24
    /**
25
     * @var Map
26
     */
27
    private $routerMap;
28
29
    /**
30
     * @var ParameterMap
31
     */
32
    private $parameterMap;
33
34
35
    public function setRequest(Request $request)
36
    {
37
        $this->request = $request;
38
    }
39
40
    public function setViewModel(ViewModel $viewModel)
41
    {
42
        $this->viewModel = $viewModel;
43
    }
44
45
    public function setRouterMap(Map $routerMap)
46
    {
47
        $this->routerMap = $routerMap;
48
    }
49
50
    /**
51
     * @return ParameterMap
52
     */
53
    public function getParameterMap()
54
    {
55
        $this->parameterMap = new ParameterMap();
56
        
57
        $this->bindUrl();
58
        $this->bindViewModel();
59
60
        return $this->parameterMap;
61
    }
62
63
    private function bindUrl()
64
    {
65
        $url = $this->resolveUrl($this->request);
0 ignored issues
show
Unused Code introduced by
The call to ParameterMapper::resolveUrl() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
66
        $this->parameterMap->bindByNameWithType('array', 'url', $url);
67
68
        foreach ($url as $name => $value) {
69
            $this->parameterMap->bindByName($name, $value);
70
        }
71
    }
72
73
    private function bindViewModel()
74
    {
75
        $this->parameterMap->bindByType(ViewModel::class, $this->viewModel);
76
    }
77
78
79
    private function resolveUrl()
80
    {
81
        $matcher = new Matcher($this->routerMap);
82
        return $matcher->match($this->request)['urlNameMatching'] ?: [];
83
    }
84
}
85