Passed
Push — master ( 2f714f...1c67eb )
by Sebastian
02:15
created

validateSyntax_equals_sign()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 21
rs 9.9

1 Method

Rating   Name   Duplication   Size   Complexity  
A Mailcode_Commands_Command_SetVariable::getVariableName() 0 3 1
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Commands_Command_SetVariable} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Commands
7
 * @see Mailcode_Commands_Command_SetVariable
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Mailcode command: set a variable value.
16
 *
17
 * @package Mailcode
18
 * @subpackage Commands
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Mailcode_Commands_Command_SetVariable extends Mailcode_Commands_Command_Type_Standalone
22
{
23
    const ERROR_NO_VARIABLE_AVAILABLE = 49401;
24
    const ERROR_NO_VARIABLE_IN_ASSIGNMENT = 49403;
25
    
26
    const VALIDATION_NOT_ASSIGNMENT_STATEMENT = 48501;
27
    
28
    public function getName() : string
29
    {
30
        return 'setvar';
31
    }
32
    
33
    public function getLabel() : string
34
    {
35
        return t('Set variable value');
36
    }
37
    
38
    public function supportsType(): bool
39
    {
40
        return false;
41
    }
42
    
43
    public function requiresParameters(): bool
44
    {
45
        return true;
46
    }
47
    
48
    /**
49
     * Retrieves the variable to show.
50
     *
51
     * NOTE: Only available once the command has been
52
     * validated. Always use isValid() first.
53
     *
54
     * @throws Mailcode_Exception
55
     * @return Mailcode_Variables_Variable
56
     */
57
    public function getVariable() : Mailcode_Variables_Variable
58
    {
59
        $variable = $this->params->getInfo()->getVariableByIndex(0);
60
        
61
        if($variable)
62
        {
63
            return $variable->getVariable();
64
        }
65
        
66
        throw new Mailcode_Exception(
67
            'No variable at position #0 in statement.',
68
            'This signifies an error in the statement handling: a variable assignment should have a variable in the first token.',
69
            self::ERROR_NO_VARIABLE_IN_ASSIGNMENT
70
        );
71
    }
72
    
73
    /**
74
     * Retrieves the full name of the variable to show.
75
     *
76
     * NOTE: Only available once the command has been
77
     * validated. Always use isValid() first.
78
     *
79
     * @throws Mailcode_Exception
80
     * @return string
81
     */
82
    public function getVariableName() : string
83
    {
84
        return $this->getVariable()->getFullName();
85
    }
86
    
87
    protected function validateSyntax_assignment() : void
88
    {
89
        if($this->params->getInfo()->isVariableAssignment())
90
        {
91
            return;
92
        }
93
        
94
        $this->validationResult->makeError(
95
            t('Not a variable assignment.').' '.t('Is the equality sign (=) present?'),
96
            self::VALIDATION_NOT_ASSIGNMENT_STATEMENT
97
        );
98
    }
99
    
100
    protected function getValidations() : array
101
    {
102
        return array(
103
            'assignment', 
104
        );
105
    }
106
    
107
    public function generatesContent() : bool
108
    {
109
        return false;
110
    }
111
}
112