Completed
Push — master ( 936cb2...f0f25e )
by Iakov
12:25 queued 06:29
created

StrategyFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 39
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
create() 0 4 ?
A hp$0 ➔ addStep() 0 3 1
A hp$0 ➔ create() 0 4 1
A __construct() 0 3 1
A hp$0 ➔ getStepObjects() 0 9 2
addStep() 0 3 ?
getStepObjects() 0 9 ?
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
}