UserDatatable::applyFilters()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 3
1
<?php namespace Distilleries\Expendable\Http\Datatables\User;
2
3
use Distilleries\Expendable\Http\Datatables\BaseDatatable;
4
use Distilleries\Expendable\Helpers\StaticLabel;
5
use Distilleries\Expendable\Helpers\UserUtils;
6
use Distilleries\Expendable\Models\Role;
7
8
class UserDatatable extends BaseDatatable {
9
10 6
    public function build()
11
    {
12 6
        $this->add('id');
13 6
        $this->add('email');
14 6
        $this->addDefaultAction('expendable::admin.user.datatable.action');
15
    }
16
17 4
    public function applyFilters()
18
    {
19 4
        parent::applyFilters();
20 4
        if (UserUtils::isNotSuperAdmin())
21
        {
22 4
            $super_admin = Role::where('initials', '=', '@sa')->get()->last();
23
24 4
            if (!empty($super_admin))
25
            {
26 2
                $this->model = $this->model->where('role_id', '!=', $super_admin->id);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->model->where('rol...'!=', $super_admin->id) of type Illuminate\Database\Eloquent\Builder is incompatible with the declared type Illuminate\Database\Eloquent\Model of property $model.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
            }
28
        }
29
30
    }
31
32 2
    public function filters()
33
    {
34 2
        $this->form->add('status', 'choice', [
0 ignored issues
show
Bug introduced by
The method add() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        $this->form->/** @scrutinizer ignore-call */ 
35
                     add('status', 'choice', [

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35 2
            'choices'     => StaticLabel::status(),
36 2
            'empty_value' => '-',
37 2
            'validation'  => 'required',
38 2
            'label'       => trans('expendable::datatable.status')
39
        ]);
40
41
    }
42
}