Completed
Push — master ( 745336...aadd5d )
by Matthew
06:17
created

CommonTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 26
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A removeOlderThan() 0 15 2
1
<?php
2
3
namespace Dtc\QueueBundle\ODM;
4
5
trait CommonTrait
6
{
7
    /**
8
     * @param \Doctrine\ODM\MongoDB\DocumentManager $documentManager
9
     * @param string                                $objectName
10
     * @param string                                $field
11
     * @param \DateTime                             $olderThan
12
     *
13
     * @return int
14
     */
15 2
    protected function removeOlderThan(\Doctrine\ODM\MongoDB\DocumentManager $documentManager, $objectName, $field, \DateTime $olderThan)
16
    {
17 2
        $qb = $documentManager->createQueryBuilder($objectName);
18
        $qb
19 2
            ->remove()
20 2
            ->field($field)->lt($olderThan);
21
22 2
        $query = $qb->getQuery();
23 2
        $result = $query->execute();
24 2
        if (isset($result['n'])) {
25 2
            return $result['n'];
26
        }
27
28
        return 0;
29
    }
30
}
31