Passed
Pull Request — master (#13)
by Sebastian
04:18
created

getDefaultDecryptionKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Commands_Command_ShowVariable} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Commands
7
 * @see Mailcode_Commands_Command_ShowVariable
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
use Mailcode\Interfaces\Commands\Validation\DecryptInterface;
15
use Mailcode\Interfaces\Commands\Validation\IDNEncodingInterface;
16
use Mailcode\Traits\Commands\Validation\DecryptTrait;
17
use Mailcode\Traits\Commands\Validation\IDNDecodeTrait;
18
use Mailcode\Traits\Commands\Validation\IDNEncodeTrait;
19
20
/**
21
 * Mailcode command: show a variable value.
22
 *
23
 * @package Mailcode
24
 * @subpackage Commands
25
 * @author Sebastian Mordziol <[email protected]>
26
 */
27
class Mailcode_Commands_Command_ShowVariable
28
    extends Mailcode_Commands_ShowBase
29
    implements
30
    IDNEncodingInterface, DecryptInterface
31
{
32
    public const VALIDATION_TOO_MANY_PARAMETERS = 69701;
33
34
    use IDNEncodeTrait;
35
    use IDNDecodeTrait;
36
    use DecryptTrait;
37
38
    /**
39
     * @var string|NULL
40
     */
41
    private static ?string $defaultDecryptionKey = null;
42
43
    public function getName(): string
44
    {
45
        return 'showvar';
46
    }
47
48
    public function getLabel(): string
49
    {
50
        return t('Show variable');
51
    }
52
53
    protected function getValidations(): array
54
    {
55
        return array(
56
            Mailcode_Interfaces_Commands_Validation_Variable::VALIDATION_NAME_VARIABLE,
57
            DecryptInterface::VALIDATION_DECRYPT_NAME
58
        );
59
    }
60
61
    /**
62
     * Gets all validated tokens that the command supports
63
     * (namely the variable, and keywords).
64
     *
65
     * @return Mailcode_Parser_Statement_Tokenizer_Token[]
66
     * @throws Mailcode_Exception
67
     */
68
    protected function resolveActiveTokens(): array
69
    {
70
        $allowed = array($this->getVariableToken());
71
72
        $encodings = $this->getSupportedEncodings();
73
74
        foreach ($encodings as $keyword) {
75
            $token = $this->getEncodingToken($keyword);
76
            if ($token) {
77
                $allowed[] = $token;
78
79
                $parameter = $this->requireParams()->getInfo()->getTokenForKeyWord($token->getKeyword());
80
                if ($parameter) {
81
                    $allowed[] = $parameter;
82
                }
83
            }
84
        }
85
86
        return $allowed;
87
    }
88
89
    /**
90
     * @param string|NULL $decryptionKey A decryption key
91
     * @return void
92
     */
93
    public static function setDefaultDecryptionKey(?string $decryptionKey): void
94
    {
95
        self::$defaultDecryptionKey = $decryptionKey;
96
    }
97
98
    /**
99
     * Gets the default decryption key for decryption. If not set via
100
     * {@see self::setDefaultDecryptionKey()}, this defaults to "default".
101
     *
102
     * @return string
103
     */
104
    public static function getDefaultDecryptionKey(): string
105
    {
106
        return self::$defaultDecryptionKey ?? "default";
107
    }
108
}
109