Completed
Push — master ( 01653d...13c111 )
by Matthew
06:19
created

CommonTrait::removeOlderThan()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.0054

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 8
cts 9
cp 0.8889
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 4
crap 2.0054
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 ObjectManager $objectManager
12
     * @param string        $objectName
13
     * @param string        $field
14
     * @param \DateTime     $olderThan
15
     *
16
     * @return int
17
     */
18 2
    protected function removeOlderThan(ObjectManager $objectManager, $objectName, $field, \DateTime $olderThan)
19
    {
20
        /** @var DocumentManager $objectManager */
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
     * @param string $objectName
37
     */
38 12
    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...
39
    {
40
        // Not needed for ODM
41 12
    }
42
43 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...
44
    {
45
        // Not needed for ODM
46 1
    }
47
}
48