Completed
Push — middleware-wip ( dac6b8...b0158b )
by Romain
05:23
created

StepDefinition   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 3
cbo 4
dl 0
loc 73
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getStep() 0 9 1
A hasNextSteps() 0 4 1
A getNextSteps() 0 8 2
A hasPreviousDefinition() 0 4 1
A getPreviousDefinition() 0 11 2
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;
15
16
use Romm\ConfigurationObject\Service\Items\Parents\ParentsTrait;
17
use Romm\Formz\Configuration\AbstractFormzConfiguration;
18
use Romm\Formz\Form\Definition\Step\Steps;
19
use Romm\Formz\Exceptions\EntryNotFoundException;
20
21
class StepDefinition extends AbstractFormzConfiguration
22
{
23
    use ParentsTrait;
24
25
    /**
26
     * @var string
27
     * @validate NotEmpty
28
     */
29
    protected $step;
30
31
    /**
32
     * @var \Romm\Formz\Form\Definition\Step\Step\NextSteps
33
     */
34
    protected $next;
35
36
    /**
37
     * @return Step
38
     */
39
    public function getStep()
40
    {
41
        return $this->withFirstParent(
42
            Steps::class,
43
            function (Steps $steps) {
44
                return $steps->getEntry($this->step);
45
            }
46
        );
47
    }
48
49
    /**
50
     * @return bool
51
     */
52
    public function hasNextSteps()
53
    {
54
        return null !== $this->next;
55
    }
56
57
    /**
58
     * @return NextSteps
59
     * @throws EntryNotFoundException
60
     */
61
    public function getNextSteps()
62
    {
63
        if (false === $this->hasNextSteps()) {
64
            throw EntryNotFoundException::nextStepsNotFound($this);
65
        }
66
67
        return $this->next;
68
    }
69
70
    /**
71
     * @return bool
72
     */
73
    public function hasPreviousDefinition()
74
    {
75
        return $this->hasParent(self::class);
76
    }
77
78
    /**
79
     * @return StepDefinition
80
     * @throws EntryNotFoundException
81
     */
82
    public function getPreviousDefinition()
83
    {
84
        if (false === $this->hasPreviousDefinition()) {
85
            throw EntryNotFoundException::previousDefinitionNotFound($this);
86
        }
87
88
        /** @var StepDefinition $previousStepDefinition */
89
        $previousStepDefinition = $this->getFirstParent(self::class);
90
91
        return $previousStepDefinition;
92
    }
93
}
94