Completed
Push — master ( 24ab37...36f73c )
by Derek Stephen
01:35
created

ClientRepository::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
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
     * @return ClientEntityInterface
18
     */
19 View Code Duplication
    public function getClientEntity($clientIdentifier, $grantType, $clientSecret = null, $mustValidateSecret = true)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    {
21
        $qb = $this->createQueryBuilder('c');
22
        $qb->where('c.identifier = :id');
23
        $qb->setParameter('id', $clientIdentifier);
24
        $query = $qb->getQuery();
25
        $result = $query->getResult();
26
        return empty($result) ? null : $result[0];
27
    }
28
29
    /**
30
     * @param Client $client
31
     * @return Client
32
     * @throws \Doctrine\ORM\OptimisticLockException
33
     */
34
    public function save(Client $client)
35
    {
36
        if (!$client->getClientIdentifier()) {
0 ignored issues
show
Bug introduced by
The method getClientIdentifier() does not seem to exist on object<OAuth\Client>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
            $this->_em->persist($client);
38
        }
39
        $this->_em->flush($client);
40
        return $client;
41
    }
42
43
    /**
44
     * @param Client $client
45
     * @throws \Doctrine\ORM\OptimisticLockException
46
     */
47
    public function delete(Client $client)
48
    {
49
        $this->_em->remove($client);
50
        $this->_em->flush($client);
51
    }
52
}