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

DoctrineORMRepository::findBySlug()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 13
loc 13
c 1
b 0
f 0
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
namespace Black\Page\Infrastructure\Persistence;
4
5
use Black\Bridge\Doctrine\Common\Persistence\ORMRepository;
6
use Black\Page\Domain\Model\WebPage;
7
use Black\Page\Domain\Model\WebPageId;
8
use Black\Page\Domain\Model\WebPageRepository;
9
use Doctrine\ORM\NoResultException;
10
11
/**
12
 * Class DoctrineORMRepository
13
 */
14 View Code Duplication
class DoctrineORMRepository extends ORMRepository 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...
15
{
16
    /**
17
     * @param mixed $id
18
     * @return mixed
19
     * @throws \Doctrine\ORM\NoResultException
20
     * @throws \Doctrine\ORM\NonUniqueResultException
21
     */
22
    public function find(WebPageId $id)
23
    {
24
        $query = $this->getQueryBuilder()
25
            ->where('p.webPageId.value = :id')
26
            ->setParameter('id', $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
    /**
37
     * @param $slug
38
     * @return mixed|null
39
     */
40
    public function findBySlug($slug)
41
    {
42
        $query = $this->getQueryBuilder()
43
            ->where('p.slug = :slug')
44
            ->setParameter('slug', $slug)
45
            ->getQuery();
46
47
        try {
48
            return $query->getSingleResult();
49
        } 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...
50
            return null;
51
        }
52
    }
53
54
    /**
55
     * @return mixed
56
     */
57
    public function findAll()
58
    {
59
        return $this->getQueryBuilder()->getQuery()->execute();
60
    }
61
62
    /**
63
     * @param WebPage $webpage
64
     */
65
    public function add(WebPage $webpage)
66
    {
67
        $this->manager->persist($webpage);
68
        $this->update($webpage);
69
    }
70
71
    /**
72
     * @param WebPage $webpage
73
     */
74
    public function remove(WebPage $webpage)
75
    {
76
        $this->manager->remove($webpage);
77
        $this->update($webpage);
78
79
    }
80
81
    public function update(WebPage $webpage)
82
    {
83
        $this->manager->flush();
84
    }
85
}
86