GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

InMemoryRouteManager   B
last analyzed

Complexity

Total Complexity 36

Size/Duplication

Total Lines 206
Duplicated Lines 20.87 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 6.74%

Importance

Changes 0
Metric Value
wmc 36
lcom 1
cbo 4
dl 43
loc 206
c 0
b 0
f 0
ccs 6
cts 89
cp 0.0674
rs 8.8

15 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findAllNameAndPattern() 0 4 1
A findByName() 0 8 2
A findVisibleByName() 0 10 3
A findByNames() 0 13 3
A findVisibleByNames() 13 13 4
A findByRoutePattern() 0 10 3
A findByRoutePatterns() 15 15 4
B findVisibleByRoutePatterns() 15 15 5
A all() 0 11 3
A add() 0 9 2
A remove() 0 7 2
A save() 0 4 1
A clear() 0 5 1
A getClass() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the Tadcka package.
5
 *
6
 * (c) Tadas Gliaubicas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tadcka\Component\Routing\Manager;
13
14
use Tadcka\Component\Routing\Exception\RoutingRuntimeException;
15
use Tadcka\Component\Routing\Model\Manager\RouteManager;
16
use Tadcka\Component\Routing\Model\Manager\RouteManagerInterface;
17
use Tadcka\Component\Routing\Model\RouteInterface;
18
19
/**
20
 * @author Tadas Gliaubicas <[email protected]>
21
 *
22
 * @since 9/1/14 8:30 PM
23
 */
24
class InMemoryRouteManager extends RouteManager
25
{
26
    /**
27
     * @var RouteManagerInterface
28
     */
29
    private $routeManager;
30
31
    /**
32
     * @var array|RouteInterface[]
33
     */
34
    private $routes = array();
35
36
    /**
37
     * Constructor.
38
     *
39
     * @param RouteManagerInterface $routeManager
40
     */
41 1
    public function __construct(RouteManagerInterface $routeManager)
42
    {
43 1
        $this->routeManager = $routeManager;
44 1
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function findAllNameAndPattern()
50
    {
51
        return $this->routeManager->findAllNameAndPattern();
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function findByName($name)
58
    {
59
        if (isset($this->routes[$name])) {
60
            return $this->routes[$name];
61
        }
62
63
        return $this->routeManager->findByName($name);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function findVisibleByName($name)
70
    {
71
        if (isset($this->routes[$name])) {
72
            $route = $this->routes[$name];
73
74
            return $route->isVisible() ? $route : null;
75
        }
76
77
        return $this->routeManager->findVisibleByName($name);
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function findByNames(array $names)
84
    {
85
        $routes = array();
86
        $diffNames = array_diff($names, array_keys($this->routes));
87
88
        foreach ($this->routes as $name => $route) {
89
            if (in_array($name, $names)) {
90
                $routes[] = $route;
91
            }
92
        }
93
94
        return array_merge($routes, $this->routeManager->findByNames($diffNames));
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100 View Code Duplication
    public function findVisibleByNames(array $names)
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...
101
    {
102
        $routes = array();
103
        $diffNames = array_diff($names, array_keys($this->routes));
104
105
        foreach ($this->routes as $name => $route) {
106
            if (in_array($name, $names) && $route->isVisible()) {
107
                $routes[] = $route;
108
            }
109
        }
110
111
        return array_merge($routes, $this->routeManager->findVisibleByNames($diffNames));
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function findByRoutePattern($routePattern)
118
    {
119
        foreach ($this->routes as $route) {
120
            if ($routePattern === $route->getRoutePattern()) {
121
                return $route;
122
            }
123
        }
124
125
        return $this->routeManager->findByRoutePattern($routePattern);
126
    }
127
128
    /**
129
     * {@inheritdoc}
130
     */
131 View Code Duplication
    public function findByRoutePatterns(array $routePatterns)
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...
132
    {
133
        $result = array();
134
        foreach ($routePatterns as $routePattern) {
135
            foreach ($this->routes as $route) {
136
                if ($routePattern === $route->getRoutePattern()) {
137
                    $result[$routePattern] = $route;
138
                }
139
            }
140
        }
141
142
        $diffRoutePatterns = array_diff($routePatterns, array_keys($result));
143
144
        return array_merge(array_values($result), $this->routeManager->findByRoutePatterns($diffRoutePatterns));
145
    }
146
147
    /**
148
     * {@inheritdoc}
149
     */
150 View Code Duplication
    public function findVisibleByRoutePatterns(array $routePatterns)
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...
151
    {
152
        $result = array();
153
        foreach ($routePatterns as $routePattern) {
154
            foreach ($this->routes as $route) {
155
                if (($routePattern === $route->getRoutePattern()) && $route->isVisible()) {
156
                    $result[$routePattern] = $route;
157
                }
158
            }
159
        }
160
161
        $diffRoutePatterns = array_diff($routePatterns, array_keys($result));
162
163
        return array_merge(array_values($result), $this->routeManager->findVisibleByRoutePatterns($diffRoutePatterns));
164
    }
165
166
    /**
167
     * {@inheritdoc}
168
     */
169
    public function all()
170
    {
171
        $routes = $this->routes;
172
        foreach ($this->routeManager->all() as $route) {
173
            if (false === isset($routes[$route->getName()])) {
174
                $routes[$route->getName()] = $route;
175
            }
176
        }
177
178
        return array_values($routes);
179
    }
180
181
    /**
182
     * {@inheritdoc}
183
     */
184 1
    public function add(RouteInterface $route, $save = false)
185
    {
186 1
        if (!$route->getName()) {
187 1
            throw new RoutingRuntimeException('Route name is empty!');
188
        }
189
190
        $this->routes[$route->getName()] = $route;
191
        $this->routeManager->add($route, $save);
192
    }
193
194
    /**
195
     * {@inheritdoc}
196
     */
197
    public function remove(RouteInterface $route, $save = false)
198
    {
199
        if (isset($this->routes[$route->getName()])) {
200
            unset($this->routes[$route->getName()]);
201
        }
202
        $this->routeManager->remove($route, $save);
203
    }
204
205
    /**
206
     * {@inheritdoc}
207
     */
208
    public function save()
209
    {
210
        $this->routeManager->save();
211
    }
212
213
    /**
214
     * {@inheritdoc}
215
     */
216
    public function clear()
217
    {
218
        $this->routes = array();
219
        $this->routeManager->clear();
220
    }
221
222
    /**
223
     * {@inheritdoc}
224
     */
225
    public function getClass()
226
    {
227
        return $this->routeManager->getClass();
228
    }
229
}
230