GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Permissions::update()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 3
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Afrittella\BackProject\Repositories;
3
4
class Permissions extends Base
5
{
6
    public function model()
7
    {
8
        return config('laravel-permission.models.permission');
9
    }
10
11
    public function create(array $data)
12
    {
13
        $permission = $this->model->create($data);
0 ignored issues
show
Bug introduced by
The method create() does not exist on Illuminate\Database\Eloquent\Model. Did you maybe mean created()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
14
15
        if (!empty($data['roles'])) {
16
            $permission->roles()->sync($data['roles']);
17
        }
18
19
        return $permission;
20
    }
21
22 View Code Duplication
    public function update(array $data, $id, $attribute = 'id')
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...
23
    {
24
        $model_data = $this->findBy($attribute, $id);
25
        if (!empty($data['roles'])) {
26
            $model_data->roles()->sync($data['roles']);
27
        }
28
        return $model_data->update($data);
29
    }
30
31
    public function firstOrCreate($data)
32
    {
33
        // If permissions are in format permission1,permission2...
34
        if (!is_array($data)) {
35
            $perms = explode(',', $data);
36
        } else {
37
            $perms = $data;
38
        }
39
40
        foreach ($perms as $perm):
41
            $this->model->firstOrCreate([
42
                'name' => trim(strtolower($perm))
43
            ]);
44
        endforeach;
45
    }
46
47
    /**
48
     * Transform data in a table array for view
49
     * @param $data
50
     * @param array $options
51
     * @return array
52
     */
53 View Code Duplication
    public function transform($data = [], $options = [])
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
54
    {
55
        if (empty($data)) {
56
            $data = $this->all();
57
        }
58
59
        // Table header
60
        $head = [
61
            'columns' => [
62
                trans('back-project::permissions.name'),
63
                trans('back-project::permissions.roles'),
64
                trans('back-project::crud.actions'),
65
            ]
66
        ];
67
68
        $body = [];
69
70
        foreach ($data as $row):
71
            $actions = [];
72
73
            if ($row->name !== 'administration' and $row->name !== 'backend') {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
74
                $actions = [
75
                    'edit' => ['url' => route('bp.permissions.edit', [$row['id']])],
76
                    'delete' => ['url' => route('bp.permissions.delete', [$row['id']])]
77
                ];
78
            }
79
80
            $body[] = [
81
                'columns' => [
82
                    ['content' => $row->name],
83
                    ['content' => implode('<br>', $row->roles->pluck('name')->toArray())],
84
                    ['content' => false, 'actions' => $actions],
85
                ]
86
            ];
87
        endforeach;
88
89
        return [
90
            'head' => $head,
91
            'body' => $body
92
        ];
93
    }
94
95
}