Passed
Push — master ( 3991b6...e9cdac )
by Gabriel
02:46
created

Clients   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
eloc 10
c 1
b 0
f 1
dl 0
loc 41
ccs 0
cts 11
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generateTable() 0 3 1
A getClientEntity() 0 17 5
A validateClient() 0 3 1
1
<?php
2
3
namespace ByTIC\Hello\Models\Clients;
4
5
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
6
use Nip\Records\Collections\Collection;
7
use Nip\Utility\Traits\SingletonTrait;
8
9
/**
10
 * Class Tokens
11
 * @package ByTIC\Hello\Models\Clients
12
 *
13
 * @method Client getNew()
14
 * @method Client findOneByIdentifier(string $clientIdentifier)
15
 * @method Client findOne(string $clientIdentifier)
16
 *
17
 * @method Client[]|Collection findByRedirect(string $uri)
18
 */
19
class Clients extends \Nip\Records\RecordManager implements ClientRepositoryInterface
20
{
21
    use SingletonTrait;
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function getClientEntity(
27
        $clientIdentifier,
28
        $grantType = null,
29
        $clientSecret = null,
30
        $mustValidateSecret = true
31
    ) {
32
        // First, we will verify that the client exists
33
        $client = $this->findOneByIdentifier($clientIdentifier);
34
35
        if (!$client || !$client->handlesGrant($grantType)) {
0 ignored issues
show
introduced by
$client is of type ByTIC\Hello\Models\Clients\Client, thus it always evaluated to true.
Loading history...
36
            return;
37
        }
38
39
        if ($mustValidateSecret && !$client->validateSecret($clientSecret)) {
40
            return;
41
        }
42
        return $client;
43
    }
44
45
    /** @noinspection PhpMissingParentCallCommonInspection
46
     * @inheritDoc
47
     */
48
    protected function generateTable()
49
    {
50
        return 'oauth_clients';
51
    }
52
53
    /**
54
     * @inheritDoc
55
     * @TODO add some validation logic
56
     */
57
    public function validateClient($clientIdentifier, $clientSecret, $grantType)
58
    {
59
        return true;
60
    }
61
}
62