Completed
Push — master ( bd6f51...8be215 )
by Park Jong-Hun
02:30
created

ParameterMapper::bindProc()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Core\ControllerDispatcher;
4
5
use Prob\Rewrite\Request;
6
use Prob\Handler\ParameterMap;
7
use Prob\Handler\Parameter\Typed;
8
use Prob\Handler\Parameter\Named;
9
use Prob\Handler\Parameter\TypedAndNamed;
10
use Prob\Handler\ProcInterface;
11
use Prob\Router\Map;
12
use Core\ViewModel;
13
use Prob\Router\Matcher;
14
15
class ParameterMapper
16
{
17
18
    /**
19
     * @var Request
20
     */
21
    private $request;
22
23
    /**
24
     * @var ViewModel
25
     */
26
    private $viewModel;
27
28
    /**
29
     * @var Map
30
     */
31
    private $routerMap;
32
33
    /**
34
     * @var ParameterMap
35
     */
36
    private $parameterMap;
37
38
39
    public function setRequest(Request $request)
40
    {
41
        $this->request = $request;
42
    }
43
44
    public function setViewModel(ViewModel $viewModel)
45
    {
46
        $this->viewModel = $viewModel;
47
    }
48
49
    public function setRouterMap(Map $routerMap)
50
    {
51
        $this->routerMap = $routerMap;
52
    }
53
54
    /**
55
     * @return ParameterMap
56
     */
57
    public function getParameterMap()
58
    {
59
        $this->parameterMap = new ParameterMap();
60
61
        $this->bindRequest();
62
        $this->bindPatternedUrl();
63
64
        $this->bindNamedUrl();
65
        $this->bindViewModel();
66
67
        $this->bindProc();
68
69
        return $this->parameterMap;
70
    }
71
72
    private function bindRequest()
73
    {
74
        $this->parameterMap->bindBy(new Typed(Request::class), $this->request);
0 ignored issues
show
Bug introduced by
The method bindBy() does not exist on Prob\Handler\ParameterMap. Did you maybe mean bindByName()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
75
    }
76
77 View Code Duplication
    private function bindPatternedUrl()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $matcher = new Matcher($this->routerMap);
80
        $urlPattern = $matcher->match($this->request)['urlPattern'];
81
82
        $this->parameterMap->bindBy(new Named('urlPattern'), $urlPattern);
0 ignored issues
show
Bug introduced by
The method bindBy() does not exist on Prob\Handler\ParameterMap. Did you maybe mean bindByName()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
83
    }
84
85
    private function bindNamedUrl()
86
    {
87
        $urlVariable = $this->resolveUrl();
88
        $this->parameterMap->bindBy(new TypedAndNamed('array', 'urlVariable'), $urlVariable);
0 ignored issues
show
Bug introduced by
The method bindBy() does not exist on Prob\Handler\ParameterMap. Did you maybe mean bindByName()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
89
90
        foreach ($urlVariable as $name => $value) {
91
            $this->parameterMap->bindBy(new Named($name), $value);
0 ignored issues
show
Bug introduced by
The method bindBy() does not exist on Prob\Handler\ParameterMap. Did you maybe mean bindByName()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
92
        }
93
    }
94
95 View Code Duplication
    private function bindProc()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
    {
97
        $matcher = new Matcher($this->routerMap);
98
        $proc = $matcher->match($this->request)['handler'];
99
100
        $this->parameterMap->bindBy(new Typed(ProcInterface::class), $proc);
0 ignored issues
show
Bug introduced by
The method bindBy() does not exist on Prob\Handler\ParameterMap. Did you maybe mean bindByName()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
101
    }
102
103
    private function bindViewModel()
104
    {
105
        $this->parameterMap->bindBy(new Typed(ViewModel::class), $this->viewModel);
0 ignored issues
show
Bug introduced by
The method bindBy() does not exist on Prob\Handler\ParameterMap. Did you maybe mean bindByName()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
106
    }
107
108
109
    private function resolveUrl()
110
    {
111
        $matcher = new Matcher($this->routerMap);
112
        return $matcher->match($this->request)['urlNameMatching'] ?: [];
113
    }
114
}
115