Passed
Push — master ( c28222...9253d7 )
by Sebastian
02:41
created

Mailcode_Commands_Command_ShowVariable   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 11
Bugs 0 Features 0
Metric Value
eloc 24
c 11
b 0
f 0
dl 0
loc 63
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getLabel() 0 3 1
A getName() 0 3 1
A getValidations() 0 7 1
A resolveActiveTokens() 0 17 3
A validateSyntax_no_other_tokens() 0 11 2
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
/**
15
 * Mailcode command: show a variable value.
16
 *
17
 * @package Mailcode
18
 * @subpackage Commands
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Mailcode_Commands_Command_ShowVariable extends Mailcode_Commands_ShowBase
22
{
23
    const VALIDATION_TOO_MANY_PARAMETERS = 69701;
24
25
    public function getName() : string
26
    {
27
        return 'showvar';
28
    }
29
    
30
    public function getLabel() : string
31
    {
32
        return t('Show variable');
33
    }
34
    
35
    protected function getValidations() : array
36
    {
37
        return array(
38
            'variable',
39
            'urlencode',
40
            'urldecode',
41
            'no_other_tokens'
42
        );
43
    }
44
    
45
    protected function validateSyntax_no_other_tokens() : void
46
    {
47
        $tokens = $this->params->getInfo()->getTokens();
48
        $allowed = $this->resolveActiveTokens();
49
50
        if(count($tokens) > count($allowed))
51
        {
52
            $this->validationResult->makeError(
53
                t('Unknown parameters found:').' '.
54
                t('Only the variable name and keywords should be specified.'),
55
                self::VALIDATION_TOO_MANY_PARAMETERS
56
            );
57
        }
58
    }
59
60
    /**
61
     * Gets all validated tokens that the command supports
62
     * (namely the variable, and keywords).
63
     *
64
     * @return Mailcode_Parser_Statement_Tokenizer_Token[]
65
     * @throws Mailcode_Exception
66
     */
67
    protected function resolveActiveTokens() : array
68
    {
69
        $allowed = array($this->getVariableToken());
70
71
        $token = $this->getURLEncodeToken();
72
        if($token)
73
        {
74
            $allowed[] = $token;
75
        }
76
77
        $token = $this->getURLDecodeToken();
78
        if($token)
79
        {
80
            $allowed[] = $token;
81
        }
82
83
        return $allowed;
84
    }
85
}
86