Completed
Pull Request — master (#30)
by Matthew
23:29 queued 08:10
created

DoctrineJobTimingManager::pruneJobTimings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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