Completed
Push — master ( f40498...e3ae3a )
by ARCANEDEV
03:17
created

PermissionsRoutes::map()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 41
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 2.0095

Importance

Changes 5
Bugs 0 Features 0
Metric Value
c 5
b 0
f 0
dl 0
loc 41
ccs 26
cts 30
cp 0.8667
rs 8.8571
cc 2
eloc 24
nc 1
nop 1
crap 2.0095
1
<?php namespace Arcanesoft\Auth\Http\Routes\Foundation;
2
3
use Arcanedev\Support\Bases\RouteRegister;
4
use Arcanesoft\Auth\Models\Permission;
5
use Arcanesoft\Auth\Models\PermissionsGroup;
6
use Illuminate\Contracts\Routing\Registrar;
7
8
/**
9
 * Class     PermissionsRoutes
10
 *
11
 * @package  Arcanesoft\Auth\Http\Routes\Foundation
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class PermissionsRoutes extends RouteRegister
15
{
16
    /* ------------------------------------------------------------------------------------------------
17
     |  Main Functions
18
     | ------------------------------------------------------------------------------------------------
19
     */
20
    /**
21
     * Map routes.
22
     *
23
     * @param  \Illuminate\Contracts\Routing\Registrar  $router
24
     */
25 24
    public function map(Registrar $router)
26
    {
27 24
        parent::map($router);
28
29 24
        $this->group([
30 24
            'prefix'    => 'permissions',
31 18
            'as'        => 'permissions.',
32
        ], function () {
33 24
            $this->get('/', [
34 24
                'as'   => 'index', // auth::foundation.permissions.index
35 18
                'uses' => 'PermissionsController@index',
36 18
            ]);
37
38 24
            $this->get('group/{perms_group_id}', [
39 24
                'as'   => 'group', // auth::foundation.permissions.group
40 18
                'uses' => 'PermissionsController@group',
41 18
            ]);
42
43 24
            $this->get('{permission_id}/show', [
44 24
                'as'   => 'show',  // auth::foundation.permissions.show
45 18
                'uses' => 'PermissionsController@show',
46 18
            ]);
47
48 24
            $this->delete('{permission_id}/roles/{role_id}/detach', [
49 24
                'as'   => 'roles.detach',  // auth::foundation.permissions.roles.detach
50 18
                'uses' => 'PermissionsController@detachRole',
51 18
            ]);
52 24
        });
53
54
        $router->bind('permission_id', function($hashedId) {
55
            return Permission::firstHashedOrFail($hashedId);
56 24
        });
57
58 24
        $router->bind('perms_group_id', function($hashedId) {
59
            if (head(hasher()->decode($hashedId)) === 0) {
60
                return null;
61
            }
62
63
            return PermissionsGroup::firstHashedOrFail($hashedId);
64 24
        });
65 24
    }
66
}
67