Passed
Push — master ( 62880d...2f714f )
by Sebastian
07:50
created

Mailcode_Commands_Command_If   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 23
c 2
b 0
f 0
dl 0
loc 69
rs 10
wmc 11

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getValidations() 0 10 2
A validateSyntax_require_variable() 0 12 2
A generatesContent() 0 3 1
A getSiblings() 0 5 1
A getSupportedTypes() 0 5 1
A getName() 0 3 1
A supportsType() 0 3 1
A requiresParameters() 0 3 1
A getLabel() 0 3 1
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Commands_Command_If} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Commands
7
 * @see Mailcode_Commands_Command_If
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Mailcode command: opening IF statement.
16
 *
17
 * @package Mailcode
18
 * @subpackage Commands
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Mailcode_Commands_Command_If extends Mailcode_Commands_Command_Type_Opening
22
{
23
    const VALIDATION_VARIABLE_COUNT_MISMATCH = 49201;
24
    
25
    public function getName() : string
26
    {
27
        return 'if';
28
    }
29
    
30
    public function getLabel() : string
31
    {
32
        return t('IF condition');
33
    }
34
    
35
    public function supportsType(): bool
36
    {
37
        return true;
38
    }
39
    
40
    public function requiresParameters(): bool
41
    {
42
        return true;
43
    }
44
    
45
    protected function validateSyntax_require_variable()
46
    {
47
        $amount = $this->getVariables()->countVariables();
48
        
49
        if($amount >= 1)
50
        {
51
            return;
52
        }
53
        
54
        $this->validationResult->makeError(
55
            t('Command has %1$s variables, %2$s expected.', $amount, 1),
56
            self::VALIDATION_VARIABLE_COUNT_MISMATCH
57
        );
58
    }
59
    
60
    protected function getValidations() : array
61
    {
62
        $validations = array();
63
        
64
        if($this->getType() === 'variable')
65
        {
66
            $validations[] = 'require_variable';
67
        }
68
        
69
        return $validations;
70
    }
71
    
72
    public function generatesContent() : bool
73
    {
74
        return false;
75
    }
76
    
77
    public function getSupportedTypes() : array
78
    {
79
        return array(
80
            'variable',
81
            'command'
82
        );
83
    }
84
    
85
    public function getSiblings() : array
86
    {
87
        return array(
88
            'else',
89
            'elseif'
90
        );
91
    }
92
}
93