Completed
Push — master ( b3f90f...c5536c )
by Daniel
03:02
created

TaskEntityRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findAllWithNoExitCode() 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 entities with no exit code.
21
     *
22
     * @return TaskEntity[]
23
     */
24 2
    public function findAllWithNoExitCode()
25
    {
26 2
        $queryBuilder = $this->createQueryBuilder('task');
27 2
        $queryBuilder->where(
28 2
            $queryBuilder->expr()->isNotNull('task.exitCode')
29 1
        );
30
31 2
        return $queryBuilder->getQuery()->getResult();
32
    }
33
34
    /**
35
     * Find next entity.
36
     *
37
     * @param array $criteria
38
     *
39
     * @return TaskEntity|null
40
     */
41 4
    public function findNext(array $criteria = [])
42
    {
43 4
        $criteria = array_merge($criteria, ['pid' => null]);
44 4
        $orderBy = ['priority' => 'ASC', 'createdAt' => 'ASC', 'updatedAt' => 'ASC'];
45
46 4
        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 2
    public function findNextByCommandline($commandline)
57
    {
58 2
        return $this->findNext(['commandline' => $commandline]);
59
    }
60
}
61