Completed
Push — master ( 3d485f...407dff )
by Paweł
66:49
created

RevisionRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 46.34 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 19
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPublishedRevision() 10 10 1
A getWorkingRevision() 9 9 1
A getByKey() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the Superdesk Publisher Revision Bundle.
5
 *
6
 * Copyright 2017 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\RevisionBundle\Repository;
16
17
use Doctrine\ORM\QueryBuilder;
18
use SWP\Component\Common\Criteria\Criteria;
19
use SWP\Bundle\StorageBundle\Doctrine\ORM\EntityRepository;
20
use SWP\Component\Revision\Model\RevisionInterface;
21
use SWP\Component\Revision\Repository\RevisionRepositoryInterface;
22
23
class RevisionRepository extends EntityRepository implements RevisionRepositoryInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 View Code Duplication
    public function getPublishedRevision(): QueryBuilder
0 ignored issues
show
Duplication introduced by
This method 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...
29
    {
30
        $qb = $this->getQueryByCriteria(new Criteria(), [], 'r')
31
            ->where('r.status = :status')
32
            ->setParameter('status', RevisionInterface::STATE_PUBLISHED)
33
            ->orderBy('r.publishedAt', 'desc')
34
            ->setMaxResults(1);
35
36
        return $qb;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 View Code Duplication
    public function getWorkingRevision(): QueryBuilder
0 ignored issues
show
Duplication introduced by
This method 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...
43
    {
44
        $qb = $this->getQueryByCriteria(new Criteria(), [], 'r')
45
            ->where('r.status = :status')
46
            ->setParameter('status', RevisionInterface::STATE_NEW)
47
            ->setMaxResults(1);
48
49
        return $qb;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function getByKey($key): QueryBuilder
56
    {
57
        $qb = $this->getQueryByCriteria(new Criteria(), [], 'r')
58
            ->where('r.uniqueKey = :key')
59
            ->setParameter('key', $key);
60
61
        return $qb;
62
    }
63
}
64