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

validateSyntax_statement()   A

Complexity

Conditions 5
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 9
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 16
rs 9.6111
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Commands_Command_For} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Commands
7
 * @see Mailcode_Commands_Command_For
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Mailcode command: opening FOR statement.
16
 *
17
 * @package Mailcode
18
 * @subpackage Commands
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Mailcode_Commands_Command_For extends Mailcode_Commands_Command_Type_Opening
22
{
23
    const VALIDATION_INVALID_FOR_STATEMENT = 49701;
24
    
25
    public function getName() : string
26
    {
27
        return 'for';
28
    }
29
    
30
    public function getLabel() : string
31
    {
32
        return t('FOR loop');
33
    }
34
    
35
    public function supportsType(): bool
36
    {
37
        return false;
38
    }
39
    
40
    public function requiresParameters(): bool
41
    {
42
        return true;
43
    }
44
    
45
    protected function getValidations() : array
46
    {
47
        return array(
48
            'statement'
49
        );
50
    }
51
    
52
    public function generatesContent() : bool
53
    {
54
        return false;
55
    }
56
    
57
    protected function validateSyntax_statement() : void
58
    {
59
        $info = $this->params->getInfo();
60
        
61
        $variable = $info->getVariableByIndex(0);
62
        $keyword = $info->getKeywordByIndex(1);
63
        $container = $info->getVariableByIndex(2);
64
        
65
        if($variable && $keyword && $container && $keyword->isForIn())
66
        {
67
            return;
68
        }
69
        
70
        $this->validationResult->makeError(
71
            t('Not a valid for loop.').' '.t('Is the %1$s keyword missing?', 'in:'),
72
            self::VALIDATION_INVALID_FOR_STATEMENT
73
        );
74
    }
75
}
76