Completed
Push — master ( 36f73c...56dc59 )
by Derek Stephen
04:32
created

ClientRepository::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
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 create(Client $client)
35
    {
36
        $this->_em->persist($client);
37
        $this->_em->flush($client);
38
        return $client;
39
    }
40
41
    /**
42
     * @param Client $client
43
     * @return Client
44
     * @throws \Doctrine\ORM\OptimisticLockException
45
     */
46
    public function save(Client $client)
47
    {
48
        $this->_em->flush($client);
49
        return $client;
50
    }
51
52
    /**
53
     * @param Client $client
54
     * @throws \Doctrine\ORM\OptimisticLockException
55
     */
56
    public function delete(Client $client)
57
    {
58
        $this->_em->remove($client);
59
        $this->_em->flush($client);
60
    }
61
}