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

Oauth2BaseClientAction   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 1
b 0
f 0
dl 0
loc 23
ccs 0
cts 9
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A findByIdOrIdentifier() 0 21 4
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