Completed
Pull Request — master (#33)
by Iakov
06:48
created

StrategyFactory::getStepObjects()

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 7
cp 0
c 0
b 0
f 0
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Kami\ApiCoreBundle\RequestProcessor;
4
5
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Kami\Component\RequestProcessor\Step\StepInterface;
8
use Kami\Component\RequestProcessor\AbstractStrategy;
9
10
class StrategyFactory
11
{
12
    /**
13
     * @var ArrayCollection
14
     */
15
    protected $availableSteps;
16
17
    /**
18
     * StrategyFactory constructor.
19
     */
20
    public function __construct()
21
    {
22
        $this->availableSteps = new ArrayCollection();
23
    }
24
25
    /**
26
     * @param array $steps
27
     * @return AbstractStrategy
28
     */
29
    public function create(array $steps)
30
    {
31
        $stepObjects = $this->getStepObjects($steps);
32
        return new class($stepObjects) extends AbstractStrategy {};
33
    }
34
35
    public function addStep(string $shortcut, StepInterface $step) : void
36
    {
37
        $this->availableSteps->set($shortcut, $step);
38
    }
39
40
    private function getStepObjects($steps) : array
41
    {
42
43
        $strategySteps = [];
44
        foreach ($steps as $step) {
45
            $strategySteps[] = $this->availableSteps->get($step);
46
        }
47
48
        return $strategySteps;
49
    }
50
51
}