Completed
Push — master ( f30a66...783f1c )
by Matthew
08:20 queued 39s
created

CommonTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 45
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A removeOlderThan() 0 17 2
getObjectManager() 0 1 ?
A stopIdGenerator() 0 4 1
A restoreIdGenerator() 0 4 1
1
<?php
2
3
namespace Dtc\QueueBundle\ODM;
4
5
use Doctrine\Common\Persistence\ObjectManager;
6
use Doctrine\ODM\MongoDB\DocumentManager;
7
8
trait CommonTrait
9
{
10
    /**
11
     * @param string    $objectName
12
     * @param string    $field
13
     * @param \DateTime $olderThan
14
     *
15
     * @return int
16
     */
17 2
    protected function removeOlderThan($objectName, $field, \DateTime $olderThan)
18
    {
19
        /** @var DocumentManager $objectManager */
20 2
        $objectManager = $this->getObjectManager();
21 2
        $qb = $objectManager->createQueryBuilder($objectName);
22
        $qb
23 2
            ->remove()
24 2
            ->field($field)->lt($olderThan);
25
26 2
        $query = $qb->getQuery();
27 2
        $result = $query->execute();
28 2
        if (isset($result['n'])) {
29 2
            return $result['n'];
30
        }
31
32
        return 0;
33
    }
34
35
    /**
36
     * @return ObjectManager
37
     */
38
    abstract public function getObjectManager();
39
40
    /**
41
     * @param string $objectName
42
     */
43 1
    public function stopIdGenerator($objectName)
0 ignored issues
show
Unused Code introduced by
The parameter $objectName 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...
44
    {
45
        // Not needed for ODM
46 1
    }
47
48 1
    public function restoreIdGenerator($objectName)
0 ignored issues
show
Unused Code introduced by
The parameter $objectName 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...
49
    {
50
        // Not needed for ODM
51 1
    }
52
}
53