Completed
Push — master ( fbe46c...fa1c37 )
by Max
02:21
created

AbstractParser::getCacheManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MidasSoft\DominicanBankParser\Parsers;
4
5
use DateTime;
6
use DateTimeZone;
7
use MidasSoft\DominicanBankParser\Collections\DepositCollection;
8
use MidasSoft\DominicanBankParser\Exceptions\EmptyFileException;
9
use MidasSoft\DominicanBankParser\Exceptions\InvalidArgumentException;
10
use MidasSoft\DominicanBankParser\Interfaces\CacheInterface;
11
use MidasSoft\DominicanBankParser\Interfaces\ParserInterface;
12
13
abstract class AbstractParser implements ParserInterface
14
{
15
    /**
16
     * CacheInterface instance.
17
     *
18
     * @var \MidasSoft\DominicanBankParser\Interfaces\CacheInterface
19
     */
20
    protected $cacheManager;
21
22
    /**
23
     * Sends a value to the cache manager.
24
     *
25
     * @return void
26
     */
27 8
    public function cache($data)
28
    {
29 8
        if (!is_null($this->cacheManager)) {
30 8
            $timezone = $this->cacheManager->getConfigKey('timezone') ?? 'America/Santo_Domingo';
0 ignored issues
show
Bug introduced by
The method getConfigKey() does not exist on MidasSoft\DominicanBankP...terfaces\CacheInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to MidasSoft\DominicanBankP...terfaces\CacheInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
            $timezone = $this->cacheManager->/** @scrutinizer ignore-call */ getConfigKey('timezone') ?? 'America/Santo_Domingo';
Loading history...
31 8
            $key = (new DateTime('now', new DateTimeZone($timezone)))->format('Y-m-d H:i:s');
32
33 8
            $this->cacheManager->add($key, $data);
34
        }
35 8
    }
36
37
    /**
38
     * Validates that a file has data to parse.
39
     *
40
     * @param \MidasSoft\DominicanBankParser\Collections\DepositCollection $fileData
41
     *
42
     * @throws \MidasSoft\DominicanBankParser\Exceptions\EmptyFileException
43
     *
44
     * @return void
45
     */
46 12
    protected function failIfParsedFileIsEmpty(DepositCollection $fileData)
47
    {
48 12
        if (count($fileData) == 0) {
49 4
            throw new EmptyFileException('You\'re trying to parse an empty file.');
50
        }
51 8
    }
52
53
    /**
54
     * Returns the cacheManager property.
55
     *
56
     * @return \MidasSoft\DominicanBankParser\Interfaces\CacheInterface
57
     */
58 4
    public function getCacheManager()
59
    {
60 4
        return $this->cacheManager;
61
    }
62
63
    /**
64
     * Returns the cacheManager property.
65
     *
66
     * @param \MidasSoft\DominicanBankParser\Interfaces\CacheInterface
67
     *
68
     * @return void
69
     */
70 12
    public function setCacheManager(CacheInterface $cacheManager)
71
    {
72 12
        $this->cacheManager = $cacheManager;
73 12
    }
74
}
75