ConsoleListener::onTerminate()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
cc 3
eloc 3
nc 2
nop 1
crap 3
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2014, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
10
namespace AnimeDb\Bundle\CacheTimeKeeperBundle\Event\Listener;
11
12
use AnimeDb\Bundle\CacheTimeKeeperBundle\Service\Keeper;
13
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
14
15
class ConsoleListener
16
{
17
    /**
18
     * @var Keeper
19
     */
20
    private $keeper;
21
22
    /**
23
     * @var bool
24
     */
25
    private $track_clear_cache;
26
27
    /**
28
     * @var array
29
     */
30
    private $commands = [
31
        'cache:clear',
32
        'cache:warmup',
33
    ];
34
35
    /**
36
     * @param Keeper $keeper
37
     * @param bool $track_clear_cache
38
     */
39 3
    public function __construct(Keeper $keeper, $track_clear_cache)
40
    {
41 3
        $this->keeper = $keeper;
42 3
        $this->track_clear_cache = $track_clear_cache;
43 3
    }
44
45
    /**
46
     * @param ConsoleTerminateEvent $event
47
     */
48 3
    public function onTerminate(ConsoleTerminateEvent $event)
49
    {
50 3
        if ($this->track_clear_cache && in_array($event->getCommand()->getName(), $this->commands)) {
51 1
            $this->keeper->set(Keeper::LAST_UPDATE_KEY, new \DateTime());
52 1
        }
53 3
    }
54
}
55