Completed
Push — master ( f1eae3...bf73f1 )
by Iman
12:13 queued 08:59
created

RouteAuthorizer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 20
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A authorizeMatchedRoutes() 0 7 1
A setGuardFor() 0 5 2
1
<?php
2
3
namespace Imanghafoori\HeyMan;
4
5
use Illuminate\Routing\Events\RouteMatched;
6
use Illuminate\Support\Facades\Route;
7
use Imanghafoori\HeyMan\WatchingStrategies\RouterEventManager;
8
9
class RouteAuthorizer
10
{
11 87
    public function authorizeMatchedRoutes()
12
    {
13
        Route::matched(function (RouteMatched $eventObj) {
14 44
            $route = $eventObj->route;
15 44
            $this->setGuardFor($eventObj->request->method().$route->uri);
16 28
            $this->setGuardFor($route->getName());
17 26
            $this->setGuardFor($route->getActionName());
18 87
        });
19 87
    }
20
21
    /**
22
     * @param $url
23
     */
24 44
    private function setGuardFor($url)
25
    {
26 44
        $closures = app(RouterEventManager::class)->resolveCallbacks($url);
27 44
        foreach ($closures as $cb) {
28 44
            $cb();
29
        }
30 28
    }
31
}
32