MemberService::createMember()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 10
cts 10
cp 1
rs 9.6
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
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\Parking;
12
13
use App\Entity\Access\User;
14
use App\Entity\Parking\Member;
15
use App\Enum\Functional\PermissionEnum;
16
use App\Enum\Functional\RoleEnum;
17
use App\Repository\Entity\Parking\MemberRepository;
18
use App\Traits\AssertTrait;
19
use Symfony\Component\Security\Core\Security;
20
use Symfony\Component\Validator\Validator\ValidatorInterface;
21
22
class MemberService
23
{
24
    use AssertTrait;
25
26
    /** @var MemberRepository */
27
    private $memberRepository;
28
    /** @var ValidatorInterface */
29
    private $validator;
30
    /** @var Security */
31
    private $security;
32
33 16
    public function __construct(MemberRepository $memberRepository, ValidatorInterface $validator, Security $security)
34
    {
35 16
        $this->memberRepository = $memberRepository;
36 16
        $this->validator = $validator;
37 16
        $this->security = $security;
38 16
    }
39
40 2
    public function updateMember(
41
        Member $member,
42
        string $name,
43
        RoleEnum $memberRoleEnum
44
    ): Member {
45 2
        $member->setName($name);
46 2
        $member->setRole($memberRoleEnum);
47 2
        $this->assertIsValidObject($this->validator, $member, null, ['put']);
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...
48 2
        $this->assertIsGranted($this->security, PermissionEnum::PARKING_MEMBER_UPDATE, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<App\Entity\Parking\Member>, but the function expects a null|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...
49
50 2
        $this->memberRepository->saveAll($member);
51
52 2
        return $member;
53
    }
54
55 10
    public function createMember(
56
        string $name,
57
        string $email,
58
        RoleEnum $memberRoleEnum
59
    ): Member {
60 10
        $user = new User();
61 10
        $user->setEmail($email);
62 10
        $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...
63 9
        $member = new Member(
64 9
            $name,
65
            $memberRoleEnum,
66
            $user
67
        );
68 9
        $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...
69 9
        $this->assertIsGranted($this->security, PermissionEnum::PARKING_MEMBER_CREATE, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<App\Entity\Parking\Member>, but the function expects a null|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...
70
71 9
        $this->memberRepository->saveAllInTransaction($user, $member);
72
73 9
        return $member;
74
    }
75
76
    public function deleteMember(
77
        Member $member
78
    ): Member {
79
        $this->assertIsGranted($this->security, PermissionEnum::PARKING_MEMBER_DELETE, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<App\Entity\Parking\Member>, but the function expects a null|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...
80
81
        $this->memberRepository->deleteAll($member);
82
83
        return $member;
84
    }
85
}
86