Oauth2EncryptionController::actions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\controllers\console;
4
5
use rhertogh\Yii2Oauth2Server\controllers\console\base\Oauth2BaseConsoleController;
6
use rhertogh\Yii2Oauth2Server\controllers\console\encryption\Oauth2RotateEncryptionKeysAction;
7
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\encryption\Oauth2EncryptionKeyUsageActionInterface;
8
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\encryption\Oauth2GenerateSecretActionInterface;
9
use rhertogh\Yii2Oauth2Server\interfaces\controllers\console\Oauth2EncryptionControllerInterface;
10
use yii\helpers\ArrayHelper;
11
12
/**
13
 * Manage Oauth2 Server encryption keys.
14
 */
15
class Oauth2EncryptionController extends Oauth2BaseConsoleController implements Oauth2EncryptionControllerInterface
16
{
17
    /**
18
     * @var string|null
19
     */
20
    public $keyName = null;
21
22
    /**
23
     * @var int
24
     */
25
    public $secretLength = 32;
26
27
    /**
28
     * @inheritDoc
29
     */
30
    public function options($actionID)
31
    {
32
        $options = parent::options($actionID);
33
        if (in_array($actionID, ['key-usage', 'rotate-keys', 'generate-secret'])) {
34
            $options = ArrayHelper::merge($options, [
35
                'keyName',
36
            ]);
37
        }
38
        if ($actionID === 'generate-secret') {
39
            $options = ArrayHelper::merge($options, [
40
                'secretLength',
41
            ]);
42
        }
43
        return $options;
44
    }
45
46
    public function optionAliases()
47
    {
48
        return ArrayHelper::merge(parent::optionAliases(), [
49
            'k' => 'keyName',
50
            'l' => 'secretLength',
51
        ]);
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57
    public function actions()
58
    {
59
        return [
60
            'key-usage' => Oauth2EncryptionKeyUsageActionInterface::class,
61
            'rotate-keys' => Oauth2RotateEncryptionKeysAction::class,
62
            'generate-secret' => Oauth2GenerateSecretActionInterface::class,
63
        ];
64
    }
65
}
66