Completed
Push — master ( d4f4f0...01653d )
by Matthew
04:03
created

CommonTrait::stopIdGenerator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 2
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 2
     *
16
     * @return int
17 2
     */
18
    protected function removeOlderThan(ObjectManager $objectManager, $objectName, $field, \DateTime $olderThan)
19 2
    {
20 2
        /** @var DocumentManager $objectManager */
21
        $qb = $objectManager->createQueryBuilder($objectName);
22 2
        $qb
23 2
            ->remove()
24 2
            ->field($field)->lt($olderThan);
25 2
26
        $query = $qb->getQuery();
27
        $result = $query->execute();
28
        if (isset($result['n'])) {
29
            return $result['n'];
30
        }
31
32
        return 0;
33
    }
34
35
    /**
36
     * @param string $objectName
37
     */
38
    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
    }
42
43
    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
    }
47
}
48