Test Failed
Push — master ( f51294...9c5f94 )
by Sebastian
03:08
created

supportsLogicKeywords()   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_ShowSnippet} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Commands
7
 * @see Mailcode_Commands_Command_ShowSnippet
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_ShowSnippet extends Mailcode_Commands_Command implements Mailcode_Commands_Command_Type_Standalone
22
{
23
    const ERROR_NO_VARIABLE_AVAILABLE = 51901;
24
    
25
    const VALIDATION_VARIABLE_MISSING = 52001;
26
    
27
   /**
28
    * @var Mailcode_Variables_Variable|NULL
29
    */
30
    protected $variable;
31
    
32
    public function getName() : string
33
    {
34
        return 'showsnippet';
35
    }
36
    
37
    public function getLabel() : string
38
    {
39
        return t('Show text snippet');
40
    }
41
    
42
    public function supportsType(): bool
43
    {
44
        return false;
45
    }
46
    
47
    public function getDefaultType() : string
48
    {
49
        return '';
50
    }
51
52
    public function requiresParameters(): bool
53
    {
54
        return true;
55
    }
56
    
57
    public function supportsLogicKeywords() : bool
58
    {
59
        return false;
60
    }
61
    
62
   /**
63
    * Retrieves the variable to show, provided the command
64
    * is valid.
65
    * 
66
    * @throws Mailcode_Exception
67
    * @return Mailcode_Variables_Variable
68
    */
69
    public function getVariable() : Mailcode_Variables_Variable
70
    {
71
        $this->validate();
72
        
73
        if($this->variable instanceof Mailcode_Variables_Variable)
74
        {
75
            return $this->variable;
76
        }
77
        
78
        throw new Mailcode_Exception(
79
            'No variable available.',
80
            'No variable is present at this time, or the validation failed.',
81
            self::ERROR_NO_VARIABLE_AVAILABLE
82
        );
83
    }
84
    
85
   /**
86
    * Retrieves the full name of the variable to show,
87
    * provided the command is valid.
88
    * 
89
    * @throws Mailcode_Exception
90
    * @return string
91
    */
92
    public function getVariableName() : string
93
    {
94
        return $this->getVariable()->getFullName();
95
    }
96
97
    protected function validateSyntax_require_variable() : void
98
    {
99
        $info = $this->params->getInfo();
100
        
101
        $var = $info->getVariableByIndex(0);
102
        
103
        if($var)
104
        {
105
            $this->variable = $var->getVariable();
106
            return;
107
        }
108
        
109
        $this->validationResult->makeError(
110
            t('No variable specified in the command.'),
111
            self::VALIDATION_VARIABLE_MISSING
112
        );
113
    }
114
    
115
    protected function getValidations() : array
116
    {
117
        return array('require_variable');
118
    }
119
    
120
    public function generatesContent() : bool
121
    {
122
        return true;
123
    }
124
}
125