NodeVersionLockRepository::getExpiredLocks()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 10
Ratio 90.91 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 10
loc 11
ccs 0
cts 10
cp 0
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Kunstmaan\NodeBundle\Repository;
4
5
use Kunstmaan\AdminBundle\Entity\BaseUser;
6
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
7
use Kunstmaan\NodeBundle\Entity\NodeVersionLock;
8
9
/**
10
 * NodeVersionLockRepository
11
 *
12
 * This class was generated by the Doctrine ORM. Add your own custom
13
 * repository methods below.
14
 */
15 View Code Duplication
class NodeVersionLockRepository extends \Doctrine\ORM\EntityRepository
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
    /**
18
     * Check if there is a nodetranslation lock that's not passed the 30 minute threshold.
19
     *
20
     * @param NodeTranslation $nodeTranslation
21
     * @param bool            $isPublicVersion
22
     * @param int             $threshold
23
     * @param BaseUser        $userToExclude
0 ignored issues
show
Documentation introduced by
Should the type for parameter $userToExclude not be null|BaseUser?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
24
     *
25
     * @return NodeVersionLock[]
26
     */
27
    public function getLocksForNodeTranslation(NodeTranslation $nodeTranslation, $isPublicVersion, $threshold, BaseUser $userToExclude = null)
28
    {
29
        $qb = $this->createQueryBuilder('nvl')
30
            ->select('nvl')
31
            ->where('nvl.nodeTranslation = :nt')
32
            ->andWhere('nvl.publicVersion = :pub')
33
            ->andWhere('nvl.createdAt > :date')
34
            ->setParameter('nt', $nodeTranslation)
35
            ->setParameter('pub', $isPublicVersion)
36
            ->setParameter('date', new \DateTime(sprintf('-%s seconds', $threshold)))
37
        ;
38
39
        if (!\is_null($userToExclude)) {
40
            $qb->andWhere('nvl.owner <> :owner')
41
                ->setParameter('owner', $userToExclude->getUsername())
42
            ;
43
        }
44
45
        return $qb->getQuery()->getResult();
46
    }
47
48
    /**
49
     * Get locks that are passed the threshold.
50
     *
51
     * @param NodeTranslation $nodeTranslation
52
     * @param int             $threshold
53
     *
54
     * @return mixed
55
     */
56
    public function getExpiredLocks(NodeTranslation $nodeTranslation, $threshold)
57
    {
58
        $qb = $this->createQueryBuilder('nvl')
59
            ->select('nvl')
60
            ->where('nvl.nodeTranslation = :nt')
61
            ->andWhere('nvl.createdAt < :date')
62
            ->setParameter('nt', $nodeTranslation)
63
            ->setParameter('date', new \DateTime(sprintf('-%s seconds', $threshold)));
64
65
        return $qb->getQuery()->getResult();
66
    }
67
}
68