CreateRole   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
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 24
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 17 1
1
<?php
2
3
namespace Omatech\Mage\Core\Repositories\Roles;
4
5
use Omatech\Mage\Core\Domains\Roles\Contracts\CreateRoleInterface;
6
use Omatech\Mage\Core\Domains\Roles\Contracts\RoleInterface;
7
use Omatech\Mage\Core\Events\Roles\RoleCreated;
8
use Omatech\Mage\Core\Repositories\RoleBaseRepository;
9
10
class CreateRole extends RoleBaseRepository implements CreateRoleInterface
11
{
12
    /**
13
     * @param RoleInterface $role
14
     * @return bool
15
     */
16 21
    public function create(RoleInterface $role): bool
17
    {
18 21
        $created = $this->query()->create([
19 21
            'name'       => $role->getName(),
20 21
            'guard_name' => $role->getGuardName(),
21
        ]);
22
23 21
        $role->setId($created->id);
24 21
        $role->setCreatedAt($created->created_at);
25 21
        $role->setUpdatedAt($created->updated_at);
26
27 21
        $this->syncPermissions($created, $role);
0 ignored issues
show
Bug introduced by
It seems like $created defined by $this->query()->create(a...$role->getGuardName())) 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\Role>, 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
$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...
28
29 21
        event(new RoleCreated($role, $created->wasRecentlyCreated));
30
31 21
        return $created->wasRecentlyCreated;
32
    }
33
}
34