ModelPermit   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 48.65 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 6
c 2
b 1
f 0
lcom 1
cbo 4
dl 18
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A access() 10 10 2
A to() 8 8 1
A routeAction() 0 10 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}