UpdateRole   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 4
dl 0
loc 25
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A update() 0 18 1
1
<?php
2
3
namespace Omatech\Mage\Core\Repositories\Roles;
4
5
use Omatech\Mage\Core\Domains\Roles\Contracts\RoleInterface;
6
use Omatech\Mage\Core\Domains\Roles\Contracts\UpdateRoleInterface;
7
use Omatech\Mage\Core\Events\Roles\RoleUpdated;
8
use Omatech\Mage\Core\Repositories\RoleBaseRepository;
9
10
class UpdateRole extends RoleBaseRepository implements UpdateRoleInterface
11
{
12
    /**
13
     * @param RoleInterface $role
14
     * @return bool
15
     */
16 4
    public function update(RoleInterface $role): bool
17
    {
18 4
        $updated = $this->query()->find($role->getId());
19
20 4
        $updated->fill([
21 4
                'name'       => $role->getName(),
22 4
                'guard_name' => $role->getGuardName(),
23 4
            ])->save();
24
25 4
        $role->setCreatedAt($updated->created_at);
26 4
        $role->setUpdatedAt($updated->updated_at);
27
28 4
        $this->syncPermissions($updated, $role);
0 ignored issues
show
Compatibility introduced by
$role of type object<Omatech\Mage\Core...ontracts\RoleInterface> is not a sub-type of object<Omatech\Mage\Core\Domains\Roles\Role>. It seems like you assume a concrete implementation of the interface Omatech\Mage\Core\Domain...Contracts\RoleInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
29
30 4
        event(new RoleUpdated($role, count($updated->getChanges()) >= 1));
31
32 4
        return count($updated->getChanges()) >= 1;
33
    }
34
}
35