QueueWorkflow::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Maketok\DataMigration;
4
5
use Maketok\DataMigration\Action\ActionInterface;
6
use Maketok\DataMigration\Action\ConfigInterface;
7
use Maketok\DataMigration\Workflow\ResultInterface;
8
9
class QueueWorkflow implements WorkflowInterface
10
{
11
    /**
12
     * @var \SplQueue
13
     */
14
    protected $queue;
15
    /**
16
     * @var ResultInterface
17
     */
18
    protected $result;
19
    /**
20
     * @var ConfigInterface
21
     */
22
    protected $config;
23
24
    /**
25
     * @param ConfigInterface $config
26
     * @param ResultInterface $result
27
     */
28 10
    public function __construct(ConfigInterface $config, ResultInterface $result)
29 5
    {
30 10
        $this->config = $config;
31 10
        $this->result = $result;
32 10
        $this->queue = new \SplQueue();
33 10
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 10
    public function add(ActionInterface $action)
39
    {
40 10
        $this->queue->enqueue($action);
41 10
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 9
    public function execute()
47
    {
48 9
        $this->result->setStartTime(new \DateTime());
49 9
        while (!$this->queue->isEmpty()) {
50
            /** @var ActionInterface $action */
51 9
            $action = $this->queue->dequeue();
52 9
            $action->process($this->result);
53 9
        }
54 9
        $this->result->setEndTime(new \DateTime());
55 9
    }
56
}
57