Completed
Push — master ( 0f4d98...a134be )
by Wachter
04:39
created

TaskRepository   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 15.38 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 80.77%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 2
cbo 5
dl 12
loc 78
ccs 21
cts 26
cp 0.8077
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A findByUuid() 0 4 1
A persist() 0 6 1
A flush() 0 6 1
A findAll() 12 12 2
A findEndBeforeNow() 0 4 1
A findEndBefore() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Task\TaskBundle\Entity;
13
14
use Doctrine\ORM\EntityRepository;
15
use Task\Storage\TaskRepositoryInterface;
16
use Task\TaskInterface;
17
18
/**
19
 * Repository for task.
20
 */
21
class TaskRepository extends EntityRepository implements TaskRepositoryInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26 9
    public function create($handlerClass, $workload = null)
27
    {
28 9
        return new Task($handlerClass, $workload);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function findByUuid($uuid)
35
    {
36
        return $this->find($uuid);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 9
    public function persist(TaskInterface $task)
43
    {
44 9
        $this->_em->persist($task);
45
46 9
        return $this;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 9
    public function flush()
53
    {
54 9
        $this->_em->flush();
55
56 9
        return $this;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 5 View Code Duplication
    public function findAll($page = 1, $pageSize = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64 5
        $query = $this->createQueryBuilder('t')
65 5
            ->getQuery();
66
67 5
        if ($pageSize) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $pageSize of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
68
            $query->setMaxResults($pageSize);
69
            $query->setFirstResult(($page - 1) * $pageSize);
70
        }
71
72 5
        return $query->getResult();
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 2
    public function findEndBeforeNow()
79
    {
80 2
        return $this->findEndBefore(new \DateTime());
81
    }
82
83
    /**
84
     * Returns task where last-execution is before given date-time.
85
     *
86
     * @param \DateTime $dateTime
87
     *
88
     * @return TaskInterface[]
89
     */
90 2
    public function findEndBefore(\DateTime $dateTime)
91
    {
92 2
        return $this->createQueryBuilder('t')
93 2
            ->where('t.lastExecution IS NULL OR t.lastExecution > :dateTime')
94 2
            ->setParameter('dateTime', $dateTime)
95 2
            ->getQuery()
96 2
            ->getResult();
97
    }
98
}
99