Completed
Push — master ( 72b000...20c83d )
by Derek Stephen
02:27
created

PassportControl::createNewRole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Del\Passport;
4
5
use Del\Passport\Entity\Passport;
6
use Del\Passport\Entity\Role;
7
use Doctrine\ORM\EntityManager;
8
9
class PassportControl
10
{
11
    /** @var EntityManager */
12
    private $entityManager;
13
14
    /**
15
     * PassportControl constructor.
16
     * @param EntityManager $entityManager
17
     */
18
    public function __construct(EntityManager $entityManager)
19
    {
20
        $this->entityManager = $entityManager;
21
    }
22
23
    /**
24
     * @param PassportInterface $passport
25
     * @param ActionInterface $action
26
     * @param ResourceInterface $resource
27
     * @return bool
28
     */
29
    public function isAuthorized(PassportInterface $passport, ActionInterface $action, ResourceInterface $resource): bool
0 ignored issues
show
Unused Code introduced by
The parameter $passport is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $action is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $resource is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
    {
31
        return true;
32
    }
33
34
    /**
35
     * @param PassportInterface $passport
36
     * @param RoleInterface $role
37
     * @param ResourceInterface $resource
38
     * @return bool
39
     */
40
    public function grantEntitlement(PassportInterface $passport, RoleInterface $role, ResourceInterface $resource): bool
0 ignored issues
show
Unused Code introduced by
The parameter $passport is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $role is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $resource is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
    {
42
        return true;
43
    }
44
45
    /**
46
     * @param PassportInterface $passport
47
     * @param RoleInterface $role
48
     * @param ResourceInterface $resource
49
     * @return bool
50
     */
51
    public function revokeEntitlement(PassportInterface $passport, RoleInterface $role, ResourceInterface $resource): bool
0 ignored issues
show
Unused Code introduced by
The parameter $passport is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $role is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $resource is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53
        return true;
54
    }
55
56
    /**
57
     * @param int $userId
58
     * @return PassportInterface
59
     */
60
    public function createNewPassport(int $userId): PassportInterface
0 ignored issues
show
Unused Code introduced by
The parameter $userId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
    {
62
        $passport = new Passport();
63
64
        return $passport;
65
    }
66
67
    /**
68
     * @param int $userId
0 ignored issues
show
Bug introduced by
There is no parameter named $userId. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
69
     * @return PassportInterface
70
     */
71
    public function createNewRole(RoleInterface $role): RoleInterface
72
    {
73
        $this->entityManager->persist($role);
74
        $this->entityManager->flush($role);
75
76
        return $role;
77
    }
78
79
    /**
80
     * @param int $userId
0 ignored issues
show
Bug introduced by
There is no parameter named $userId. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
81
     * @return PassportInterface
82
     */
83
    public function removeRole(RoleInterface $role): void
84
    {
85
        $this->entityManager->remove($role);
86
        $this->entityManager->flush($role);
87
    }
88
89
    /**
90
     * @param string $name
91
     * @return Role|null
92
     */
93
    public function findRole(string $name): ?Role
94
    {
95
        return $this->entityManager->getRepository(Role::class)->findOneBy([
96
            'roleName' => $name,
97
        ]);
98
    }
99
}
100