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

RouteAuthorizer::authorizeMatchedRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
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