GenerateClientsTableTrait::generateClientsTable()   A
last analyzed

Complexity

Conditions 5
Paths 9

Size

Total Lines 30
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
eloc 22
c 0
b 0
f 0
dl 0
loc 30
ccs 0
cts 27
cp 0
rs 9.2568
cc 5
nc 9
nop 1
crap 30
1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\controllers\console\base\traits;
4
5
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2ClientInterface;
6
use rhertogh\Yii2Oauth2Server\Oauth2Module;
7
use yii\console\widgets\Table;
8
9
trait GenerateClientsTableTrait
10
{
11
    /**
12
     * @param Oauth2ClientInterface[] $clients
13
     * @return string
14
     * @throws \Throwable
15
     */
16
    public function generateClientsTable($clients)
17
    {
18
        $rows = [];
19
        foreach ($clients as $client) {
20
            $redirectUris = $client->getRedirectUri();
21
            $rows[] = [
22
                'id' => $client->getPrimaryKey(),
23
                'identifier' => $client->getIdentifier(),
24
                'type' => $client->isConfidential() ? 'Confidential' : 'Public',
25
                'redirect_uris' => $redirectUris
26
                    ? (
27
                        $redirectUris[0]
28
                        . (count($redirectUris) > 1
29
                            ? ' +' . (count($redirectUris) - 1) . ' more'
30
                            : '')
31
                    )
32
                    : '',
33
                'grant_types' => implode(', ', Oauth2Module::getGrantTypeIdentifiers($client->getGrantTypes())),
34
            ];
35
        }
36
37
        return Table::widget([
38
            'headers' => [
39
                'ID',
40
                'Identifier',
41
                'Type',
42
                'Redirect URIs',
43
                'Grant Types',
44
            ],
45
            'rows' => $rows,
46
        ]);
47
    }
48
}
49