SpyRouteCollection   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addCallSiteInfo() 0 7 2
A addToCollections() 0 12 4
A isItSelf() 0 4 1
A _getDomainAndUrl() 0 10 2
1
<?php
2
3
namespace Imanghafoori\LaravelMicroscope\SpyClasses;
4
5
use Illuminate\Routing\RouteCollection;
6
use Imanghafoori\LaravelMicroscope\ErrorTypes\RouteDefinitionConflict;
7
8
class SpyRouteCollection extends RouteCollection
9
{
10
    public $routesInfo;
11
12
    public function addCallSiteInfo($route, $info)
13
    {
14
        $domainAndUri = $this->_getDomainAndUrl($route);
15
        foreach ($route->methods() as $method) {
16
            $this->routesInfo[$method][$domainAndUri][] = $info;
17
        }
18
    }
19
20
    /**
21
     * Add the given route to the arrays of routes.
22
     *
23
     * @param  \Illuminate\Routing\Route  $route
24
     * @return void
25
     */
26
    protected function addToCollections($route)
27
    {
28
        $domainAndUri = $this->_getDomainAndUrl($route);
29
        foreach ($route->methods() as $method) {
30
            if (isset($this->routes[$method][$domainAndUri])) {
31
                if (! $this->isItSelf($this->routesInfo[$method][$domainAndUri])) {
32
                    event(new RouteDefinitionConflict($this->routes[$method][$domainAndUri], $route, $this->routesInfo[$method][$domainAndUri]));
33
                }
34
            }
35
        }
36
        parent::addToCollections($route);
37
    }
38
39
    private function isItSelf($info)
40
    {
41
        return $info[0] == $info[1];
42
    }
43
44
    private function _getDomainAndUrl($route)
45
    {
46
        if (version_compare(app()->version(), '5.5.0', '<')) {
47
            $getDomain = 'domain';
48
        } else {
49
            $getDomain = 'getDomain';
50
        }
51
52
        return $route->$getDomain().$route->uri();
53
    }
54
}
55