Completed
Push — master ( fa7a2a...0b2176 )
by Matthew
08: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 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 ObjectManager $objectManager
0 ignored issues
show
Bug introduced by
There is no parameter named $objectManager. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
12
     * @param string        $objectName
13
     * @param string        $field
14
     * @param \DateTime     $olderThan
15
     *
16
     * @return int
17
     */
18 2
    protected function removeOlderThan($objectName, $field, \DateTime $olderThan)
19
    {
20
        /** @var DocumentManager $objectManager */
21 2
        $objectManager = $this->getObjectManager();
0 ignored issues
show
Bug introduced by
It seems like getObjectManager() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
22 2
        $qb = $objectManager->createQueryBuilder($objectName);
23
        $qb
24 2
            ->remove()
25 2
            ->field($field)->lt($olderThan);
26
27 2
        $query = $qb->getQuery();
28 2
        $result = $query->execute();
29 2
        if (isset($result['n'])) {
30 2
            return $result['n'];
31
        }
32
33
        return 0;
34
    }
35
36
    /**
37
     * @param string $objectName
38
     */
39 14
    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...
40
    {
41
        // Not needed for ODM
42 14
    }
43
44 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...
45
    {
46
        // Not needed for ODM
47 1
    }
48
}
49