Completed
Push — wip/steps ( b2c91c...6fd1d1 )
by Romain
02:28
created

SubstepDefinition   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 2

Importance

Changes 0
Metric Value
wmc 13
lcom 3
cbo 2
dl 0
loc 119
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubstep() 0 9 1
A getActivation() 0 4 1
A hasActivation() 0 4 1
A isLast() 0 5 2
A hasNextSubstep() 0 4 1
A getNextSubstep() 0 8 2
A getDivergenceSubsteps() 0 4 1
A hasDivergence() 0 4 1
A getLevel() 0 18 3
1
<?php
2
/*
3
 * 2017 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 FormZ project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\Form\Definition\Step\Step\Substep;
15
16
use Romm\Formz\Form\Definition\AbstractFormDefinitionComponent;
17
use Romm\Formz\Form\Definition\Condition\Activation;
18
use Romm\Formz\Form\Definition\Condition\ActivationInterface;
19
use Romm\Formz\Form\Definition\Step\Step\Step;
20
21
class SubstepDefinition extends AbstractFormDefinitionComponent
22
{
23
    /**
24
     * @var string
25
     * @validate NotEmpty
26
     */
27
    protected $substep;
28
29
    /**
30
     * @var \Romm\Formz\Form\Definition\Condition\Activation
31
     * @validate Romm.Formz:Internal\ConditionIsValid
32
     */
33
    protected $activation;
34
35
    /**
36
     * @var \Romm\Formz\Form\Definition\Step\Step\Substep\SubstepDefinition
37
     */
38
    protected $next;
39
40
    /**
41
     * @var \Romm\Formz\Form\Definition\Step\Step\Substep\DivergenceSubstepDefinition[]
42
     */
43
    protected $divergence;
44
45
    /**
46
     * @return Substep
47
     */
48
    public function getSubstep()
49
    {
50
        return $this->withFirstParent(
51
            Substeps::class,
52
            function (Substeps $substeps) {
53
                return $substeps->getEntry($this->substep);
54
            }
55
        );
56
    }
57
58
    /**
59
     * @return Activation
60
     */
61
    public function getActivation()
62
    {
63
        return $this->activation;
64
    }
65
66
    /**
67
     * @return bool
68
     */
69
    public function hasActivation()
70
    {
71
        return $this->activation instanceof ActivationInterface;
72
    }
73
74
    public function getLevel()
75
    {
76
        $level = 1;
77
78
        $this->alongParents(function ($parent) use (&$level) {
79
            if ($parent instanceof self) {
80
                $level++;
81
            }
82
83
            if ($parent instanceof Step) {
84
                return false;
85
            }
86
87
            return true;
88
        });
89
90
        return $level;
91
    }
92
93
    /**
94
     * @todo
95
     *
96
     * @return bool
97
     */
98
    public function isLast()
99
    {
100
        return false === $this->hasNextSubstep()
101
            && false === $this->hasDivergence();
102
    }
103
104
    /**
105
     * @return bool
106
     */
107
    public function hasNextSubstep()
108
    {
109
        return null !== $this->next;
110
    }
111
112
    /**
113
     * @return SubstepDefinition
114
     */
115
    public function getNextSubstep()
116
    {
117
        if (false === $this->hasNextSubstep()) {
118
            throw new \Exception('todo'); // @todo
119
        }
120
121
        return $this->next;
122
    }
123
124
    /**
125
     * @return DivergenceSubstepDefinition[]
126
     */
127
    public function getDivergenceSubsteps()
128
    {
129
        return $this->divergence;
130
    }
131
132
    /**
133
     * @return bool
134
     */
135
    public function hasDivergence()
136
    {
137
        return false === empty($this->divergence);
138
    }
139
}
140