Completed
Push — feature/rewrite ( 4d09af...dad4c8 )
by Alexandre
03:40 queued 01:51
created

DoctrineMongoDBRepository   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 66
loc 66
wmc 8
c 1
b 0
f 0
lcom 0
cbo 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 12 12 2
A findBySlug() 12 12 2
A findAll() 4 4 1
A add() 5 5 1
A remove() 6 6 1
A update() 4 4 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
namespace Black\Page\Infrastructure\Persistence;
4
5
use Black\Bridge\Doctrine\Common\Persistence\MongoDB\MongoDBRepository;
6
use Black\Bridge\Doctrine\Common\Persistence\ORMRepository;
7
use Black\Page\Domain\Model\WebPage;
8
use Black\Page\Domain\Model\WebPageId;
9
use Black\Page\Domain\Model\WebPageRepository;
10
use Doctrine\ORM\NoResultException;
11
12
/**
13
 * Class DoctrineMongoDBRepository
14
 */
15 View Code Duplication
class DoctrineMongoDBRepository extends MongoDBRepository implements WebPageRepository
0 ignored issues
show
Bug introduced by
There is one abstract method getClassName in this class; you could implement it, or declare this class as abstract.
Loading history...
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
     * @param mixed $id
19
     * @return mixed
20
     * @throws \Doctrine\ORM\NoResultException
21
     * @throws \Doctrine\ORM\NonUniqueResultException
22
     */
23
    public function find(WebPageId $id)
24
    {
25
        $query = $this->getQueryBuilder()
26
            ->field('webPageId.value')->equals($id->getValue())
27
            ->getQuery();
28
29
        try {
30
            return $query->getSingleResult();
31
        } catch (NoResultException $exception) {
0 ignored issues
show
Bug introduced by
The class Doctrine\ORM\NoResultException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
32
            return null;
33
        }
34
    }
35
36
    public function findBySlug($slug)
37
    {
38
        $query = $this->getQueryBuilder()
39
            ->field('slug')->equals($slug)
40
            ->getQuery();
41
42
        try {
43
            return $query->getSingleResult();
44
        } catch (NoResultException $exception) {
0 ignored issues
show
Bug introduced by
The class Doctrine\ORM\NoResultException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
45
            return null;
46
        }
47
    }
48
49
    /**
50
     * @return mixed
51
     */
52
    public function findAll()
53
    {
54
        return $this->getQueryBuilder()->getQuery();
55
    }
56
57
    /**
58
     * @param WebPage $webpage
59
     */
60
    public function add(WebPage $webpage)
61
    {
62
        $this->manager->persist($webpage);
63
        $this->update($webpage);
64
    }
65
66
    /**
67
     * @param WebPage $webpage
68
     */
69
    public function remove(WebPage $webpage)
70
    {
71
        $this->manager->remove($webpage);
72
        $this->update($webpage);
73
74
    }
75
76
    public function update(WebPage $webpage)
77
    {
78
        $this->manager->flush();
79
    }
80
}
81