Completed
Pull Request — master (#30)
by Matthew
48:21 queued 02:09
created

DoctrineJobTimingManager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 40
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
removeOlderThan() 0 1 ?
A pruneJobTimings() 0 4 1
A getObjectManager() 0 4 1
A performRecording() 0 13 2
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 19
    public function __construct(ObjectManager $objectManager, $jobTimingClass, $recordTimings)
15
    {
16 19
        $this->objectManager = $objectManager;
17 19
        parent::__construct($jobTimingClass, $recordTimings);
18 19
    }
19
20
    /**
21
     * @return ObjectManager
22
     */
23 1
    public function getObjectManager()
24
    {
25 1
        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
        $this->objectManager->persist($jobTiming);
39 44
        $this->objectManager->flush();
40 44
    }
41
42
    abstract protected function removeOlderThan($objectName, $field, \DateTime $olderThan);
43
44
    public function pruneJobTimings(\DateTime $olderThan)
45
    {
46
        return $this->removeOlderThan($this->getJobTimingClass(), 'createdAt', $olderThan);
47
    }
48
}
49