Passed
Push — master ( f52d5c...0b49e9 )
by Rutger
03:13
created

Oauth2ClientRepository::getModelClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\components\repositories;
4
5
use rhertogh\Yii2Oauth2Server\components\repositories\base\Oauth2BaseRepository;
6
use rhertogh\Yii2Oauth2Server\components\repositories\traits\Oauth2ModelRepositoryTrait;
7
use rhertogh\Yii2Oauth2Server\helpers\DiHelper;
8
use rhertogh\Yii2Oauth2Server\interfaces\components\repositories\Oauth2ClientRepositoryInterface;
9
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2ClientInterface;
10
use yii\base\InvalidConfigException;
11
12
class Oauth2ClientRepository extends Oauth2BaseRepository implements Oauth2ClientRepositoryInterface
13
{
14
    use Oauth2ModelRepositoryTrait;
15
16
    /**
17
     * @inheritDoc
18
     * @return class-string<Oauth2ClientInterface>
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<Oauth2ClientInterface> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<Oauth2ClientInterface>.
Loading history...
19
     */
20 12
    public function getModelClass()
21
    {
22 12
        return Oauth2ClientInterface::class;
23
    }
24
25
    /**
26
     * @inheritDoc
27
     * @throws InvalidConfigException
28
     */
29 5
    public function getClientEntity($clientIdentifier)
30
    {
31 5
        return $this->findModelByIdentifier($clientIdentifier);
32
    }
33
34
    /**
35
     * @inheritDoc
36
     */
37 7
    public function validateClient($clientIdentifier, $clientSecret, $grantType)
38
    {
39
        /** @var Oauth2ClientInterface $client */
40 7
        $client = $this->findModelByIdentifier($clientIdentifier);
41
42
        if (
43 7
            $client
44 7
            && $client->isEnabled()
45 7
            && $client->validateGrantType($grantType)
46 7
            && (!$client->isConfidential() || $client->validateSecret($clientSecret, $this->_module->getEncryptor()))
0 ignored issues
show
Bug introduced by
The method getEncryptor() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
            && (!$client->isConfidential() || $client->validateSecret($clientSecret, $this->_module->/** @scrutinizer ignore-call */ getEncryptor()))

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...
47
        ) {
48 3
            return true;
49
        }
50
51 4
        return false;
52
    }
53
54
    public function getAllClients($filter = [])
55
    {
56
        $class = $this->getModelClass();
57
        /** @var class-string<Oauth2ClientInterface> $className */
58
        $className = DiHelper::getValidatedClassName($class);
59
60
        return $className::find()
61
            ->andFilterWhere($filter)
62
            ->all();
63
    }
64
65
}
66