Completed
Push — master ( 7a08de...9ce2ea )
by Daniel
04:39
created

TaskEntityRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 4
dl 0
loc 44
ccs 0
cts 12
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findAllTerminated() 0 9 1
A findNext() 0 7 1
A findNextByCommandline() 0 4 1
1
<?php
2
/**
3
 * This file is part of the Commander project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Commander\ORM;
9
10
use Doctrine\ORM\EntityRepository;
11
12
/**
13
 * Task entity repository class.
14
 *
15
 * @package GravityMedia\Commander\ORM
16
 **/
17
class TaskEntityRepository extends EntityRepository
18
{
19
    /**
20
     * Finds all terminated entities.
21
     *
22
     * @return TaskEntity[]
23
     */
24
    public function findAllTerminated()
25
    {
26
        $queryBuilder = $this->createQueryBuilder('task');
27
        $queryBuilder->where(
28
            $queryBuilder->expr()->isNotNull('task.exitCode')
29
        );
30
31
        return $queryBuilder->getQuery()->getResult();
32
    }
33
34
    /**
35
     * Find next entity.
36
     *
37
     * @param array $criteria
38
     *
39
     * @return TaskEntity|null
40
     */
41
    public function findNext(array $criteria = [])
42
    {
43
        $criteria = array_merge($criteria, ['pid' => null]);
44
        $orderBy = ['priority' => 'ASC', 'createdAt' => 'ASC', 'updatedAt' => 'ASC'];
45
46
        return $this->findOneBy($criteria, $orderBy);
47
    }
48
49
    /**
50
     * Find next entity by commandline.
51
     *
52
     * @param string $commandline
53
     *
54
     * @return TaskEntity|null
55
     */
56
    public function findNextByCommandline($commandline)
57
    {
58
        return $this->findNext(['commandline' => $commandline]);
59
    }
60
}
61