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

Oauth2BaseClientAction::findByIdOrIdentifier()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 21
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 21
ccs 0
cts 9
cp 0
rs 9.9666
cc 4
nc 8
nop 1
crap 20
1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\controllers\console\client\base;
4
5
use rhertogh\Yii2Oauth2Server\models\Oauth2Client;
6
use yii\base\Action;
7
use yii\console\Exception;
8
9
class Oauth2BaseClientAction extends Action
10
{
11
    protected function findByIdOrIdentifier($id)
12
    {
13
        $module = $this->controller->module;
14
15
        try {
16
            /** @var Oauth2Client $client */
17
            $client = $module->getClientRepository()->findModelByPk($id);
18
        } catch (\Exception $e) {
19
            // Silently ignore
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
20
        }
21
22
        if (empty($client)) {
23
            // try to find by `identifier`
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
24
            $client = $module->getClientRepository()->findModelByIdentifier($id);
25
        }
26
27
        if (empty($client)) {
28
            throw new Exception('No client with id or identifier "' . $id . '" found.' . PHP_EOL);
29
        }
30
31
        return $client;
32
    }
33
}
34