Move   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 35
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 15 3
A getCode() 0 4 1
1
<?php
2
3
namespace Maketok\DataMigration\Action\Type;
4
5
use Maketok\DataMigration\Action\ActionInterface;
6
use Maketok\DataMigration\Action\Exception\WrongContextException;
7
use Maketok\DataMigration\Unit\ImportDbUnitInterface;
8
use Maketok\DataMigration\Unit\ImportFileUnitInterface;
9
use Maketok\DataMigration\Unit\UnitBagInterface;
10
use Maketok\DataMigration\Workflow\ResultInterface;
11
12
/**
13
 * Move data data from tmp table to main table
14
 */
15
class Move extends AbstractDbAction implements ActionInterface
16
{
17
    /**
18
     * @var UnitBagInterface|ImportDbUnitInterface[]|ImportFileUnitInterface[]
19
     */
20
    protected $bag;
21
22
    /**
23
     * {@inheritdoc}
24
     * @throws WrongContextException
25
     */
26 7
    public function process(ResultInterface $result)
27
    {
28 7
        $result->setActionStartTime($this->getCode(), new \DateTime());
29 7
        foreach ($this->bag as $unit) {
30 7
            if ($unit->getTmpTable() === null) {
31 1
                throw new WrongContextException(sprintf(
32 1
                    "Action can not be used for current unit %s. Tmp table is missing.",
33 1
                    $unit->getCode()
34 1
                ));
35
            }
36 6
            $moved = $this->resource->move($unit->getTmpTable(), $unit->getTable(), array_keys($unit->getMapping()));
37 6
            $result->incrementActionProcessed($this->getCode(), $moved);
38 6
        }
39 6
        $result->setActionEndTime($this->getCode(), new \DateTime());
40 6
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 8
    public function getCode()
46
    {
47 8
        return 'move';
48
    }
49
}
50