Total Complexity | 15 |
Total Lines | 130 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | class Mailcode_Commands_Command_SetVariable extends Mailcode_Commands_Command_Type_Standalone |
||
22 | { |
||
23 | const VALIDATION_MISSING_EQUALS_SIGN = 48501; |
||
24 | const VALIDATION_NOT_SINGLE_EQUALS_SIGN = 48502; |
||
25 | const VALIDATION_EMPTY_ASSIGNMENT = 48503; |
||
26 | const VALIDATION_VARIABLE_LEFT_UNRECOGNIZED = 48504; |
||
27 | const VALIDATION_ASSIGNMENT_STATEMENT_INVALID = 48505; |
||
28 | |||
29 | /** |
||
30 | * @var string[] |
||
31 | */ |
||
32 | protected $parts = array(); |
||
33 | |||
34 | /** |
||
35 | * @var Mailcode_Variables_Variable |
||
36 | */ |
||
37 | protected $leftVar; |
||
38 | |||
39 | /** |
||
40 | * @var Mailcode_Parser_Statement |
||
41 | */ |
||
42 | protected $statement; |
||
43 | |||
44 | public function getName() : string |
||
45 | { |
||
46 | return 'setvar'; |
||
47 | } |
||
48 | |||
49 | public function getLabel() : string |
||
50 | { |
||
51 | return t('Set variable value'); |
||
52 | } |
||
53 | |||
54 | public function supportsType(): bool |
||
55 | { |
||
56 | return false; |
||
57 | } |
||
58 | |||
59 | public function requiresParameters(): bool |
||
60 | { |
||
61 | return true; |
||
62 | } |
||
63 | |||
64 | protected function validateSyntax_equals_sign() |
||
65 | { |
||
66 | $amount = substr_count($this->paramsString, '='); |
||
67 | |||
68 | if($amount === 1) |
||
69 | { |
||
70 | return; |
||
71 | } |
||
72 | |||
73 | if($amount < 1) |
||
74 | { |
||
75 | $this->validationResult->makeError( |
||
76 | t('The quality operator (=) is missing.'), |
||
77 | self::VALIDATION_MISSING_EQUALS_SIGN |
||
78 | ); |
||
79 | } |
||
80 | else |
||
81 | { |
||
82 | $this->validationResult->makeError( |
||
83 | t('Only a single equality operator (=) should be used for variable assignment.'), |
||
84 | self::VALIDATION_NOT_SINGLE_EQUALS_SIGN |
||
85 | ); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | protected function validateSyntax_split_parts() |
||
90 | { |
||
91 | $this->parts = \AppUtils\ConvertHelper::explodeTrim('=', $this->paramsString); |
||
92 | |||
93 | if(count($this->parts) === 2) |
||
94 | { |
||
95 | return; |
||
96 | } |
||
97 | |||
98 | $this->validationResult->makeError( |
||
99 | t('Command has an empty assignment on either part of the equals sign.'), |
||
100 | self::VALIDATION_EMPTY_ASSIGNMENT |
||
101 | ); |
||
102 | } |
||
103 | |||
104 | protected function validateSyntax_left() |
||
118 | ); |
||
119 | } |
||
120 | |||
121 | protected function validateSyntax_right() |
||
135 | ); |
||
136 | } |
||
137 | |||
138 | protected function getValidations() : array |
||
145 | ); |
||
146 | } |
||
147 | |||
148 | public function generatesContent() : bool |
||
151 | } |
||
152 | } |
||
153 |