Passed
Push — feature/permission-manager ( 41e93d )
by
unknown
09:00
created

GroupRepository   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 19
c 2
b 0
f 0
dl 0
loc 52
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getFormFields() 0 7 1
A afterSave() 0 5 1
A bulkDelete() 0 11 2
A delete() 0 7 2
A filter() 0 5 1
1
<?php
2
3
namespace A17\Twill\Repositories;
4
5
use A17\Twill\Models\Group;
6
use A17\Twill\Repositories\Behaviors\HandleGroupPermissions;
7
8
class GroupRepository extends ModuleRepository
9
{
10
    use HandleGroupPermissions;
0 ignored issues
show
introduced by
The trait A17\Twill\Repositories\B...\HandleGroupPermissions requires some properties which are not provided by A17\Twill\Repositories\GroupRepository: $name, $id
Loading history...
11
12
    public function __construct(Group $model)
13
    {
14
        $this->model = $model;
0 ignored issues
show
Documentation Bug introduced by
It seems like $model of type A17\Twill\Models\Group is incompatible with the declared type A17\Twill\Models\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...
15
    }
16
17
    public function getFormFields($group)
18
    {
19
        $fields = parent::getFormFields($group);
20
21
        $fields['browsers']['users'] = $this->getFormFieldsForBrowser($group, 'users');
22
23
        return $fields;
24
    }
25
26
    public function afterSave($group, $fields)
27
    {
28
        $this->updateBrowser($group, $fields, 'users');
29
30
        parent::afterSave($group, $fields);
31
    }
32
33
    public function delete($id)
34
    {
35
        if ($this->model->find($id)->is_everyone_group) {
0 ignored issues
show
Bug introduced by
The property is_everyone_group does not seem to exist on A17\Twill\Models\Model. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
36
            return false;
37
        }
38
39
        return parent::delete($id);
40
    }
41
42
    public function bulkDelete($ids)
43
    {
44
        $includes_everyone_group = $this->model->whereIn('id', $ids)
45
            ->where('is_everyone_group', true)
46
            ->first();
47
48
        if ($includes_everyone_group) {
49
            return false;
50
        }
51
52
        return parent::bulkDelete($ids);
53
    }
54
55
    public function filter($query, array $scopes = [])
56
    {
57
        $this->searchIn($query, $scopes, 'search', ['name']);
58
59
        return parent::filter($query, $scopes);
60
    }
61
}
62