Project   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 94.74%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 2
cbo 4
dl 0
loc 62
ccs 18
cts 19
cp 0.9474
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A onUpdatedProposeUpdateTask() 0 13 1
A onInstalledOrUpdatedAddShmop() 0 9 2
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
namespace AnimeDb\Bundle\AppBundle\Event\Listener;
10
11
use AnimeDb\Bundle\AppBundle\Command\ProposeUpdateCommand;
12
use AnimeDb\Bundle\AnimeDbBundle\Manipulator\Composer;
13
use AnimeDb\Bundle\AppBundle\Entity\Task;
14
use AnimeDb\Bundle\AppBundle\Service\CacheClearer;
15
use Doctrine\ORM\EntityManagerInterface;
16
17
class Project
18
{
19
    /**
20
     * @var EntityManagerInterface
21
     */
22
    protected $em;
23
24
    /**
25
     * @var CacheClearer
26
     */
27
    protected $cache_clearer;
28
29
    /**
30
     * @var Composer
31
     */
32
    protected $composer;
33
34
    /**
35
     * @param EntityManagerInterface $em
36
     * @param CacheClearer $cache_clearer
37
     * @param Composer $composer
38
     */
39 2
    public function __construct(
40
        EntityManagerInterface $em,
41
        CacheClearer $cache_clearer,
42
        Composer $composer
43
    ) {
44 2
        $this->em = $em;
45 2
        $this->cache_clearer = $cache_clearer;
46 2
        $this->composer = $composer;
47 2
    }
48
49
    /**
50
     * Update next run date for the propose update task.
51
     */
52 1
    public function onUpdatedProposeUpdateTask()
53
    {
54
        /* @var $task Task */
55 1
        $task = $this->em
56 1
            ->getRepository('AnimeDbAppBundle:Task')
57 1
            ->findOneBy(['command' => 'animedb:propose-update']);
58
59 1
        $next_run = new \DateTime();
60 1
        $next_run->modify(sprintf('+%s seconds  01:00:00', ProposeUpdateCommand::INERVAL_UPDATE));
61
62 1
        $this->em->persist($task->setNextRun($next_run));
63 1
        $this->em->flush();
64 1
    }
65
66
    /**
67
     * On installed or updated try add a Shmop package.
68
     */
69 1
    public function onInstalledOrUpdatedAddShmop()
70
    {
71
        // if the extension shmop is installed, can use the appropriate driver for store the key cache
72 1
        if (extension_loaded('shmop')) {
73 1
            $this->composer->addPackage('anime-db/shmop', '1.0.*');
74
        } else {
75
            $this->composer->removePackage('anime-db/shmop');
76
        }
77 1
    }
78
}
79