ModelPermit::routeAction()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
1
<?php namespace Mascame\Artificer\Permit;
2
3
use App;
4
use Mascame\Artificer\Model\Model;
5
use Mascame\Artificer\Options\AdminOption;
6
use Mascame\Artificer\Options\ModelOption;
7
8
class ModelPermit extends Permit
9
{
10
11
    protected static $actions = array('create', 'update', 'delete', 'view');
12
13 View Code Duplication
    public static function access($model = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
    {
15
        if (!$model) {
16
            $model = Model::getCurrent();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $model is correct as \Mascame\Artificer\Model\Model::getCurrent() (which targets Mascame\Artificer\Model\Model::getCurrent()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
17
        }
18
19
        $model_permissions = ModelOption::get('permissions', $model);
20
21
        return self::hasPermission($model_permissions);
22
    }
23
24 View Code Duplication
    public static function to($action)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        $model = Model::getCurrent();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $model is correct as \Mascame\Artificer\Model\Model::getCurrent() (which targets Mascame\Artificer\Model\Model::getCurrent()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
27
28
        $model_permissions = ModelOption::get('action_permissions.' . $action, $model);
29
30
        return self::hasPermission($model_permissions, self::getRole());
31
    }
32
33
    public static function routeAction($route)
34
    {
35
        $route_permission = AdminOption::get('models.route_permission');
36
37
        if (in_array($route, array_keys($route_permission))) {
38
            if (!ModelPermit::to($route_permission[$route])) {
39
                App::abort('403', 'Insufficient privileges');
40
            }
41
        }
42
    }
43
44
}