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

RouteAuthorizer::setGuardFor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
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