UpdateRole::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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