Completed
Push — middleware-wip ( 1f2854...9da264 )
by Romain
03:01
created

SubstepDefinition::getNextSteps()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
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\AbstractFormDefinition;
17
use Romm\Formz\Form\Definition\Step\Step\Step;
18
19
class SubstepDefinition extends AbstractFormDefinition
20
{
21
    /**
22
     * @var string
23
     * @validate NotEmpty
24
     */
25
    protected $substep;
26
27
    /**
28
     * @var \Romm\Formz\Form\Definition\Step\Step\Substep\SubstepDefinition
29
     */
30
    protected $next;
31
32
    /**
33
     * @var \Romm\Formz\Form\Definition\Step\Step\Substep\ConditionalSubstepDefinition[]
34
     */
35
    protected $detour;
36
37
    /**
38
     * @var \Romm\Formz\Form\Definition\Step\Step\Substep\ConditionalSubstepDefinition[]
39
     */
40
    protected $divergence;
41
42
    /**
43
     * @return Substep
44
     */
45
    public function getSubstep()
46
    {
47
        return $this->withFirstParent(
48
            Substeps::class,
49
            function (Substeps $substeps) {
50
                return $substeps->getEntry($this->substep);
51
            }
52
        );
53
    }
54
55
    public function getUniqueIdentifier()
56
    {
57
        $level = 1;
58
59
        $this->alongParents(function ($parent) use (&$level) {
0 ignored issues
show
Documentation Bug introduced by
The method alongParents does not exist on object<Romm\Formz\Form\D...step\SubstepDefinition>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
60
            if ($parent instanceof self) {
61
                $level++;
62
            }
63
64
            if ($parent instanceof Step) {
65
                return false;
66
            }
67
68
            return true;
69
        });
70
71
        return $this->getSubstep()->getIdentifier() . '-' . $level;
72
    }
73
74
    /**
75
     * @todo
76
     *
77
     * @return bool
78
     */
79
    public function isLast()
80
    {
81
        return false === $this->hasNextSubsteps()
82
            && false === $this->hasDetour()
83
            && false === $this->hasDivergence();
84
    }
85
86
    /**
87
     * @return bool
88
     */
89
    public function hasNextSubsteps()
90
    {
91
        return null !== $this->next;
92
    }
93
94
    /**
95
     * @return SubstepDefinition
96
     */
97
    public function getNextSubsteps()
98
    {
99
        if (false === $this->hasNextSubsteps()) {
100
            throw new \Exception('todo'); // @todo
101
        }
102
103
        return $this->next;
104
    }
105
106
    /**
107
     * @return ConditionalSubstepDefinition[]
108
     */
109
    public function getDetourSubsteps()
110
    {
111
        return $this->detour;
112
    }
113
114
    /**
115
     * @return bool
116
     */
117
    public function hasDetour()
118
    {
119
        return false === empty($this->detour);
120
    }
121
122
    /**
123
     * @return ConditionalSubstepDefinition[]
124
     */
125
    public function getDivergenceSubsteps()
126
    {
127
        return $this->divergence;
128
    }
129
130
    /**
131
     * @return bool
132
     */
133
    public function hasDivergence()
134
    {
135
        return false === empty($this->divergence);
136
    }
137
}
138