UpdateUser::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 16
cts 16
cp 1
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Omatech\Mage\Core\Repositories\Users;
4
5
use Omatech\Mage\Core\Domains\Users\Contracts\UpdateUserInterface;
6
use Omatech\Mage\Core\Domains\Users\Contracts\UserInterface;
7
use Omatech\Mage\Core\Events\Users\UserUpdated;
8
use Omatech\Mage\Core\Repositories\UserBaseRepository;
9
10
class UpdateUser extends UserBaseRepository implements UpdateUserInterface
11
{
12
    /**
13
     * @param UserInterface $user
14
     * @return bool
15
     */
16 8
    public function update(UserInterface $user): bool
17
    {
18 8
        $updated = $this->query()->find($user->getId());
19
20 8
        $updated->fill([
21 8
                'name'              => $user->getName(),
22 8
                'language'          => $user->getLanguage(),
23 8
                'email'             => $user->getEmail(),
24 8
                'email_verified_at' => $user->getEmailVerifiedAt(),
25 8
                'password'          => $user->getPassword(),
26 8
                'remember_token'    => $user->getRememberToken(),
27 8
            ])->save();
28
29 8
        $user->setCreatedAt($updated->created_at);
30 8
        $user->setUpdatedAt($updated->updated_at);
31
32 8
        $this->syncPermissions($updated, $user);
0 ignored issues
show
Compatibility introduced by
$user of type object<Omatech\Mage\Core...ontracts\UserInterface> is not a sub-type of object<Omatech\Mage\Core\Domains\Users\User>. It seems like you assume a concrete implementation of the interface Omatech\Mage\Core\Domain...Contracts\UserInterface 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...
33 8
        $this->syncRoles($updated, $user);
0 ignored issues
show
Compatibility introduced by
$user of type object<Omatech\Mage\Core...ontracts\UserInterface> is not a sub-type of object<Omatech\Mage\Core\Domains\Users\User>. It seems like you assume a concrete implementation of the interface Omatech\Mage\Core\Domain...Contracts\UserInterface 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...
34
35 8
        event(new UserUpdated($user, count($updated->getChanges()) >= 1));
36
37 8
        return count($updated->getChanges()) >= 1;
38
    }
39
}
40