Completed
Push — master ( 56dc59...f8231d )
by Derek Stephen
01:51
created

ClientRepository::getClientEntity()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 21
ccs 0
cts 10
cp 0
rs 8.7624
cc 5
eloc 11
nc 3
nop 4
crap 30
1
<?php
2
3
namespace OAuth\Repository;
4
5
use OAuth\Client;
6
use Doctrine\ORM\EntityRepository;
7
use League\OAuth2\Server\Entities\ClientEntityInterface;
8
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
9
10
class ClientRepository extends EntityRepository implements ClientRepositoryInterface
11
{
12
    /**
13
     * @param string $clientIdentifier
14
     * @param string $grantType
15
     * @param null|string|null $clientSecret
16
     * @param bool $mustValidateSecret
17
     *
18
     * @return ClientEntityInterface|null
19
     */
20
    public function getClientEntity($clientIdentifier, $grantType, $clientSecret = null, $mustValidateSecret = true)
21
    {
22
        /** @var Client $client */
23
        $client = $this->findOneBy([
24
            'identifier' => $clientIdentifier
25
        ]);
26
27
        if ($client instanceof Client == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
28
            return null;
29
        }
30
31
        if (
32
            $mustValidateSecret === true
33
            && $client['is_confidential'] === true
34
            && $clientSecret != $client->getSecret()
35
        ) {
36
            return null;
37
        }
38
39
        return $client;
40
    }
41
42
    /**
43
     * @param Client $client
44
     * @return Client
45
     * @throws \Doctrine\ORM\OptimisticLockException
46
     */
47
    public function create(Client $client)
48
    {
49
        $this->_em->persist($client);
50
        $this->_em->flush($client);
51
        return $client;
52
    }
53
54
    /**
55
     * @param Client $client
56
     * @return Client
57
     * @throws \Doctrine\ORM\OptimisticLockException
58
     */
59
    public function save(Client $client)
60
    {
61
        $this->_em->flush($client);
62
        return $client;
63
    }
64
65
    /**
66
     * @param Client $client
67
     * @throws \Doctrine\ORM\OptimisticLockException
68
     */
69
    public function delete(Client $client)
70
    {
71
        $this->_em->remove($client);
72
        $this->_em->flush($client);
73
    }
74
}