ApplicationInitializeService::createSystemMember()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 12
cts 12
cp 1
rs 9.6333
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the zibios/sharep.
7
 *
8
 * (c) Zbigniew Ślązak
9
 */
10
11
namespace App\Service\Functional;
12
13
use App\Entity\Access\User;
14
use App\Entity\Parking\Member;
15
use App\Enum\Functional\ApplicationEnum;
16
use App\Enum\Functional\RoleEnum;
17
use App\Repository\Entity\Account\UserRepository;
18
use App\Traits\AssertTrait;
19
use Symfony\Component\Validator\Validator\ValidatorInterface;
20
21
class ApplicationInitializeService
22
{
23
    use AssertTrait;
24
25
    /** @var UserRepository */
26
    private $userRepository;
27
    /** @var ValidatorInterface */
28
    private $validator;
29
30 4
    public function __construct(UserRepository $userRepository, ValidatorInterface $validator)
31
    {
32 4
        $this->userRepository = $userRepository;
33 4
        $this->validator = $validator;
34 4
    }
35
36 6
    public function createSystemMember(): Member
37
    {
38 6
        if ($this->userRepository->isAny()) {
39 2
            throw new \OverflowException('Already Initialized');
40
        }
41 4
        $user = new User();
42 4
        $user->setEmail(ApplicationEnum::SYSTEM_MEMBER_EMAIL);
43 4
        $this->assertIsValidObject($this->validator, $user);
0 ignored issues
show
Documentation introduced by
$user is of type object<App\Entity\Access\User>, but the function expects a object<App\Traits\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
44 4
        $member = new Member(
45 4
            ApplicationEnum::SYSTEM_MEMBER_NAME,
46 4
            RoleEnum::SYSTEM(),
47
            $user
48
        );
49 4
        $this->assertIsValidObject($this->validator, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<App\Entity\Parking\Member>, but the function expects a object<App\Traits\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
51 4
        $this->userRepository->saveAllInTransaction($user, $member);
52
53 4
        return $member;
54
    }
55
}
56