Passed
Push — master ( 138b71...c5c69e )
by Sebastian
04:58
created

Mailcode_Traits_Commands_IfNotEmpty   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validateSyntax_variable() 0 15 2
A getValidations() 0 4 1
A getVariable() 0 11 2
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Traits_Commands_IfEmpty} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Commands
7
 * @see Mailcode_Traits_Commands_IfEmpty
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Mailcode command: opening IF NOTEMPTY statement.
16
 *
17
 * @package Mailcode
18
 * @subpackage Commands
19
 * @author Sebastian Mordziol <[email protected]>
20
 * 
21
 * @property Mailcode_Parser_Statement $params
22
 * @property \AppUtils\OperationResult $validationResult
23
 */
24
trait Mailcode_Traits_Commands_IfNotEmpty
25
{
26
   /**
27
    * @var Mailcode_Parser_Statement_Tokenizer_Token_Variable|NULL
28
    */
29
    protected $variableToken;
30
31
    protected function getValidations() : array
32
    {
33
        return array(
34
            'variable'
35
        );
36
    }
37
    
38
    protected function validateSyntax_variable() : void
39
    {
40
        $info = $this->params->getInfo();
41
        
42
        $variable = $info->getVariableByIndex(0);
43
        
44
        if($variable !== null)
45
        {
46
            $this->variableToken = $variable;
47
            return;
48
        }
49
50
        $this->validationResult->makeError(
51
            t('No variable specified in the command.'),
52
            Mailcode_Commands_IfBase::VALIDATION_VARIABLE_MISSING
53
        );
54
    }
55
    
56
   /**
57
    * Retrieves the variable being compared.
58
    *
59
    * @return Mailcode_Variables_Variable
60
    */
61
    public function getVariable() : Mailcode_Variables_Variable
62
    {
63
        if($this->variableToken instanceof Mailcode_Parser_Statement_Tokenizer_Token_Variable)
64
        {
65
            return $this->variableToken->getVariable();
66
        }
67
        
68
        throw new Mailcode_Exception(
69
            'No variable available',
70
            null,
71
            Mailcode_Commands_IfBase::ERROR_NO_VARIABLE_AVAILABLE
72
        );
73
    }
74
}
75