CreateUser::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 15
cts 15
cp 1
rs 9.568
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\CreateUserInterface;
6
use Omatech\Mage\Core\Domains\Users\Contracts\UserInterface;
7
use Omatech\Mage\Core\Events\Users\UserCreated;
8
use Omatech\Mage\Core\Repositories\UserBaseRepository;
9
10
class CreateUser extends UserBaseRepository implements CreateUserInterface
11
{
12
    /**
13
     * @param UserInterface $user
14
     * @return bool
15
     */
16 19
    public function create(UserInterface $user): bool
17
    {
18 19
        $created = $this->query()->create([
19 19
                'name'              => $user->getName(),
20 19
                'language'          => $user->getLanguage(),
21 19
                'email'             => $user->getEmail(),
22 19
                'email_verified_at' => $user->getEmailVerifiedAt(),
23 19
                'password'          => $user->getPassword(),
24 19
                'remember_token'    => $user->getRememberToken(),
25
            ]);
26
27 19
        $user->setId($created->id);
28 19
        $user->setCreatedAt($created->created_at);
29 19
        $user->setUpdatedAt($created->updated_at);
30
31 19
        $this->syncPermissions($created, $user);
0 ignored issues
show
Bug introduced by
It seems like $created defined by $this->query()->create(a...r->getRememberToken())) on line 18 can also be of type object<Illuminate\Database\Eloquent\Builder>; however, Omatech\Mage\Core\Reposi...tory::syncPermissions() does only seem to accept object<Omatech\Mage\Core\Models\User>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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...
32 19
        $this->syncRoles($created, $user);
0 ignored issues
show
Bug introduced by
It seems like $created defined by $this->query()->create(a...r->getRememberToken())) on line 18 can also be of type object<Illuminate\Database\Eloquent\Builder>; however, Omatech\Mage\Core\Reposi...Repository::syncRoles() does only seem to accept object<Omatech\Mage\Core\Models\User>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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
34 19
        event(new UserCreated($user, $created->wasRecentlyCreated));
35
36 19
        return $created->wasRecentlyCreated;
37
    }
38
}
39