Completed
Pull Request — master (#15)
by Wachter
07:53
created

TaskExecutionRepository::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Task\TaskBundle\Entity;
4
5
use Doctrine\ORM\EntityRepository;
6
use Doctrine\ORM\NoResultException;
7
use Task\Execution\TaskExecutionInterface;
8
use Task\TaskInterface;
9
use Task\TaskStatus;
10
11
class TaskExecutionRepository extends EntityRepository
12
{
13
    public function findByStartTime(TaskInterface $task, \DateTime $scheduleTime)
14
    {
15
        try {
16
            return $this->createQueryBuilder('e')
17
                ->innerJoin('e.task', 't')
18
                ->where('t.uuid = :uuid')
19
                ->andWhere('e.scheduleTime = :scheduleTime')
20
                ->setParameter('uuid', $task->getUuid())
21
                ->setParameter('scheduleTime', $scheduleTime)
22
                ->getQuery()
23
                ->getSingleResult();
24
        } catch (NoResultException $e) {
25
            return;
26
        }
27
    }
28
29
    public function findScheduled(\DateTime $dateTime = null)
30
    {
31
        if ($dateTime === null) {
32
            $dateTime = new \DateTime();
33
        }
34
35
        return $this->createQueryBuilder('e')
36
            ->innerJoin('e.task', 't')
37
            ->where('e.status = :status AND e.scheduleTime < :dateTime')
38
            ->setParameter('status', TaskStatus::PLANNED)
39
            ->setParameter('dateTime', $dateTime)
40
            ->getQuery()
41
            ->getResult();
42
    }
43
44
    public function save(TaskExecutionInterface $execution)
0 ignored issues
show
Unused Code introduced by
The parameter $execution is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
    {
46
        $this->_em->flush();
47
    }
48
49
    public function add(TaskExecutionInterface $execution)
50
    {
51
        $this->_em->persist($execution);
52
        $this->_em->flush();
53
    }
54
}
55