Configurator::execute()   A
last analyzed

Complexity

Conditions 5
Paths 7

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 23
ccs 13
cts 13
cp 1
rs 9.5555
c 0
b 0
f 0
cc 5
nc 7
nop 1
crap 5
1
<?php declare(strict_types=1);
2
3
4
namespace Xervice\Configurator\Business\Model\Engine;
5
6
7
use DataProvider\StepDataDataProvider;
0 ignored issues
show
Bug introduced by
The type DataProvider\StepDataDataProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Xervice\Configurator\Business\Model\Exception\ConfiguratorException;
9
use Xervice\Configurator\Business\Model\Step\StepCollection;
10
11
class Configurator implements ConfiguratorInterface
12
{
13
    /**
14
     * @var \Xervice\Configurator\Business\Model\Step\StepCollection
15
     */
16
    private $stepCollection;
17
18
    /**
19
     * Configurator constructor.
20
     *
21
     * @param \Xervice\Configurator\Business\Model\Step\StepCollection $stepCollection
22
     */
23 2
    public function __construct(StepCollection $stepCollection)
24
    {
25 2
        $this->stepCollection = $stepCollection;
26 2
    }
27
28
    /**
29
     * @param \DataProvider\StepDataDataProvider $dataProvider
30
     *
31
     * @return \DataProvider\StepDataDataProvider
32
     * @throws \Xervice\Configurator\Business\Model\Exception\ConfiguratorException
33
     */
34 2
    public function execute(StepDataDataProvider $dataProvider): StepDataDataProvider
35
    {
36 2
        $step = null;
37
38 2
        foreach ($this->stepCollection as $step) {
39 2
            $step->setData($dataProvider);
40
41 2
            if (!$step->done()) {
42 2
                if (!$step->ready()) {
43 1
                    throw new ConfiguratorException(
44 1
                        sprintf(
45 1
                            'Step %s is not ready, but all previous steps are done',
46 1
                            \get_class($step)
47
                        )
48
                    );
49
                }
50
51 1
                $step->execute();
52 1
                $this->execute($step->getData());
53
            }
54
        }
55
56 1
        return $step ? $step->getData() : $dataProvider;
57
    }
58
}