Completed
Pull Request — master (#20)
by Wachter
08:56
created

TaskRepository::flush()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of php-task library.
5
 *
6
 * (c) php-task
7
 *
8
 * This source file is subject to the MIT license that is bundled
9 6
 * with this source code in the file LICENSE.
10
 */
11 6
12 6
namespace Task\TaskBundle\Entity;
13 6
14 6
use Doctrine\ORM\EntityRepository;
15 6
use Task\Storage\TaskRepositoryInterface;
16 6
use Task\TaskInterface;
17
18 6
/**
19
 * Repository for task.
20
 */
21
class TaskRepository extends EntityRepository implements TaskRepositoryInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26 3
    public function create($handlerClass, $workload = null)
27
    {
28 3
        return new Task($handlerClass, $workload);
29 3
    }
30 3
31 3
    /**
32
     * {@inheritdoc}
33 3
     */
34
    public function persist(TaskInterface $task)
35
    {
36 6
        $this->_em->persist($task);
37
38 6
        return $this;
39 6
    }
40 6
41
    /**
42 6
     * {@inheritdoc}
43 6
     */
44
    public function flush()
45
    {
46
        $this->_em->flush();
47
48
        return $this;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function findEndBeforeNow()
55
    {
56
        return $this->findEndBefore(new \DateTime());
57
    }
58
59
    /**
60
     * Returns task where last-execution is before given date-time.
61
     *
62
     * @param \DateTime $dateTime
63
     *
64
     * @return TaskInterface[]
65
     */
66
    public function findEndBefore(\DateTime $dateTime)
67
    {
68
        return $this->createQueryBuilder('t')
69
            ->where('t.lastExecution IS NULL OR t.lastExecution >= :dateTime')
70
            ->setParameter('dateTime', $dateTime)
71
            ->getQuery()
72
            ->getResult();
73
    }
74
}
75