Completed
Push — master ( aac029...31bfbf )
by Iman
03:02
created

RouteAuthorizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A authorizeMatchedRoutes() 0 11 1
A performClosures() 0 5 3
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
            $matchedRoute = [
15 44
                $eventObj->route->getName(),
16 44
                $eventObj->route->getActionName(),
17 44
                $eventObj->request->method().$eventObj->route->uri,
18
            ];
19
20 44
            $closures = app(RouterEventManager::class)->findMatchingCallbacks($matchedRoute);
21 44
            $this->performClosures($closures);
22 87
        });
23 87
    }
24
25
    /**
26
     * @param $closures
27
     */
28 44
    private function performClosures($closures)
29
    {
30 44
        foreach ($closures as $closure) {
31 40
            foreach ($closure as $c) {
32 40
                $c();
33
            }
34
        }
35 24
    }
36
}
37