ClientRepository::delete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace OAuth\Repository;
4
5
use Doctrine\ORM\UnitOfWork;
6
use OAuth\Client;
7
use Doctrine\ORM\EntityRepository;
8
use League\OAuth2\Server\Entities\ClientEntityInterface;
9
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
10
use OAuth\OAuthUser;
11
12
class ClientRepository extends EntityRepository implements ClientRepositoryInterface
13
{
14
    /**
15
     * @param string $clientIdentifier
16
     * @param null|string $grantType
17
     * @param null|string|null $clientSecret
18
     * @param bool $mustValidateSecret
19
     *
20
     * @return ClientEntityInterface|null
21
     */
22 7
    public function getClientEntity($clientIdentifier, $grantType = null, $clientSecret = null, $mustValidateSecret = true)
23
    {
24
        /** @var Client $client */
25 7
        $client = $this->findOneBy([
26 7
            'identifier' => $clientIdentifier
27
        ]);
28
29 7
        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...
30 1
            return null;
31
        }
32
33 6
        if ($mustValidateSecret === true && $client->isConfidential() === true && $clientSecret != $client->getSecret()) {
34 1
            return null;
35
        }
36
37 5
        return $client;
38
    }
39
40
    /**
41
     * @param Client $client
42
     * @return Client
43
     * @throws \Doctrine\ORM\OptimisticLockException
44
     */
45
    public function create(Client $client)
46
    {
47
        $em = $this->getEntityManager();
48
        $user = $client->getUser();
49
        if ($em->getUnitOfWork()->getEntityState($user) !== UnitOfWork::STATE_MANAGED) {
50
            /** @var OAuthUser $user */
51
            $user = $em->merge($user);
52
            $client->setUser($user);
53
        }
54
        $em->persist($client);
55
        $em->flush();
56
        return $client;
57
    }
58
59
    /**
60
     * @param Client $client
61
     * @return Client
62
     * @throws \Doctrine\ORM\OptimisticLockException
63
     */
64
    public function save(Client $client)
65
    {
66
        $this->_em->flush($client);
67
        return $client;
68
    }
69
70
    /**
71
     * @param Client $client
72
     * @throws \Doctrine\ORM\OptimisticLockException
73
     */
74
    public function delete(Client $client)
75
    {
76
        $this->_em->remove($client);
77
        $this->_em->flush($client);
78
    }
79
}