Test Setup Failed
Push — master ( e4f8c2...f9e497 )
by Sebastian
03:34
created

Mailcode_Commands_Command_Break::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Commands_Command_Break} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Commands
7
 * @see Mailcode_Commands_Command_Break
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Mailcode command: A BREAK command to stop in loops.
16
 *
17
 * @package Mailcode
18
 * @subpackage Commands
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Mailcode_Commands_Command_Break extends Mailcode_Commands_Command implements Mailcode_Commands_Command_Type_Standalone
22
{
23
    const VALIDATION_NO_PARENT_FOR = 75701;
24
25
    public function getName() : string
26
    {
27
        return 'break';
28
    }
29
    
30
    public function getLabel() : string
31
    {
32
        return t('Loop break');
33
    }
34
    
35
    public function supportsType(): bool
36
    {
37
        return false;
38
    }
39
40
    public function supportsURLEncoding(): bool
41
    {
42
        return false;
43
    }
44
    
45
    public function getDefaultType() : string
46
    {
47
        return '';
48
    }
49
50
    public function requiresParameters(): bool
51
    {
52
        return false;
53
    }
54
    
55
    public function supportsLogicKeywords() : bool
56
    {
57
        return false;
58
    }
59
60
    public function generatesContent(): bool
61
    {
62
        return false;
63
    }
64
65
    protected function getValidations(): array
66
    {
67
        return array();
68
    }
69
70
    protected function _validateNesting() : void
71
    {
72
        if($this->findParentFor($this))
73
        {
74
            return;
75
        }
76
77
        $this->validationResult->makeError(
78
            t('A break command must only be used within a %1$s command.', 'FOR'),
79
            self::VALIDATION_NO_PARENT_FOR
80
        );
81
    }
82
83
    protected function findParentFor(Mailcode_Commands_Command $command) : bool
84
    {
85
        $parent = $command->getParent();
86
87
        if($parent === null)
88
        {
89
            return false;
90
        }
91
92
        if($parent instanceof Mailcode_Commands_Command_For)
93
        {
94
            return true;
95
        }
96
97
        return $this->findParentFor($parent);
98
    }
99
}
100