Completed
Pull Request — master (#53)
by Matthew
12:05
created

DoctrineJobTimingManager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 41
ccs 16
cts 18
cp 0.8889
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getObjectManager() 0 4 1
A performRecording() 0 14 2
removeOlderThan() 0 1 ?
A pruneJobTimings() 0 4 1
1
<?php
2
3
namespace Dtc\QueueBundle\Doctrine;
4
5
use Doctrine\Common\Persistence\ObjectManager;
6
use Dtc\QueueBundle\Model\JobTiming;
7
use Dtc\QueueBundle\Manager\JobTimingManager;
8
9
abstract class DoctrineJobTimingManager extends JobTimingManager
10
{
11
    /** @var ObjectManager */
12
    protected $objectManager;
13
14 18
    public function __construct(ObjectManager $objectManager, $jobTimingClass, $recordTimings)
15
    {
16 18
        $this->objectManager = $objectManager;
17 18
        parent::__construct($jobTimingClass, $recordTimings);
18 18
    }
19
20
    /**
21
     * @return ObjectManager
22
     */
23 44
    public function getObjectManager()
24
    {
25 44
        return $this->objectManager;
26
    }
27
28 44
    public function performRecording($status, \DateTime $finishedAt = null)
29
    {
30 44
        if (null === $finishedAt) {
31 43
            $finishedAt = \Dtc\QueueBundle\Util\Util::getMicrotimeDateTime();
32
        }
33
34
        /** @var JobTiming $jobTiming */
35 44
        $jobTiming = new $this->jobTimingClass();
36 44
        $jobTiming->setFinishedAt($finishedAt);
37 44
        $jobTiming->setStatus($status);
38 44
        $objectManager = $this->getObjectManager();
39 44
        $objectManager->persist($jobTiming);
40 44
        $objectManager->flush();
41 44
    }
42
43
    abstract protected function removeOlderThan($objectName, $field, \DateTime $olderThan);
44
45
    public function pruneJobTimings(\DateTime $olderThan)
46
    {
47
        return $this->removeOlderThan($this->getJobTimingClass(), 'createdAt', $olderThan);
48
    }
49
}
50