Completed
Push — master ( e40024...27a431 )
by ARCANEDEV
03:09
created

PermissionsRoutes::map()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 39
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 2.0104

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
dl 0
loc 39
ccs 25
cts 29
cp 0.8621
rs 8.8571
cc 2
eloc 23
nc 1
nop 1
crap 2.0104
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
        $this->group([
28 24
            'prefix'    => 'permissions',
29 18
            'as'        => 'permissions.',
30
        ], function () {
31 24
            $this->get('/', [
32 24
                'as'   => 'index', // auth::foundation.permissions.index
33 18
                'uses' => 'PermissionsController@index',
34 18
            ]);
35
36 24
            $this->get('group/{perms_group_id}', [
37 24
                'as'   => 'group', // auth::foundation.permissions.group
38 18
                'uses' => 'PermissionsController@group',
39 18
            ]);
40
41 24
            $this->get('{permission_id}/show', [
42 24
                'as'   => 'show',  // auth::foundation.permissions.show
43 18
                'uses' => 'PermissionsController@show',
44 18
            ]);
45
46 24
            $this->delete('{permission_id}/roles/{role_id}/detach', [
47 24
                'as'   => 'roles.detach',  // auth::foundation.permissions.roles.detach
48 18
                'uses' => 'PermissionsController@detachRole',
49 18
            ]);
50 24
        });
51
52
        $router->bind('permission_id', function($hashedId) {
53
            return Permission::firstHashedOrFail($hashedId);
54 24
        });
55
56 24
        $router->bind('perms_group_id', function($hashedId) {
57
            if (head(hasher()->decode($hashedId)) === 0) {
58
                return null;
59
            }
60
61
            return PermissionsGroup::firstHashedOrFail($hashedId);
62 24
        });
63 24
    }
64
}
65