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

CommonTrait::stopIdGenerator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 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