AbstractAction::getTmpFileName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 9.9332
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Maketok\DataMigration\Action\Type;
4
5
use Maketok\DataMigration\Action\ConfigInterface;
6
use Maketok\DataMigration\Unit\UnitBagInterface;
7
use Maketok\DataMigration\Unit\UnitInterface;
8
9
class AbstractAction
10
{
11
    /**
12
     * @var UnitBagInterface|UnitInterface[]
13
     */
14
    protected $bag;
15
    /**
16
     * @var ConfigInterface
17
     */
18
    protected $config;
19
    /**
20
     * @var \DateTime
21
     */
22
    protected $date;
23
24
25
    /**
26
     * @param UnitBagInterface $bag
27
     * @param ConfigInterface $config
28
     */
29 48
    public function __construct(
30
        UnitBagInterface $bag,
31
        ConfigInterface $config
32
    ) {
33 48
        $this->bag = $bag;
34 48
        $this->config = $config;
35 48
        $this->date = new \DateTime();
36 48
    }
37
38
    /**
39
     * @param UnitInterface $unit
40
     * @return string
41
     */
42 16
    public function getTmpFileName(UnitInterface $unit)
43
    {
44 16
        return rtrim($this->config->offsetGet('tmp_folder'), '/') .
45 16
        '/' .
46 16
        ltrim(sprintf(
47 16
            $this->config->offsetGet('tmp_file_mask'),
48 16
            $unit->getCode(),
49 16
            $this->getDate()
50 16
        ), '/');
51
    }
52
53
    /**
54
     * @return string
55
     */
56 16
    protected function getDate()
57
    {
58 16
        return $this->date->format('Y-m-d_H:i:s');
59
    }
60
61
    /**
62
     * @return int
63
     */
64 9
    protected function getStamp()
65
    {
66 9
        return $this->date->getTimestamp();
67
    }
68
69
    /**
70
     * @param UnitInterface $unit
71
     * @return string
72
     */
73 9
    public function getTmpTableName(UnitInterface $unit)
74
    {
75 9
        return sprintf(
76 9
            $this->config->offsetGet('tmp_table_mask'),
77 9
            $unit->getCode(),
78 9
            $this->getStamp()
79 9
        );
80
    }
81
}
82