Code Duplication    Length = 66-72 lines in 2 locations

src/Page/Infrastructure/Persistence/DoctrineMongoDBRepository.php 1 location

@@ 15-80 (lines=66) @@
12
/**
13
 * Class DoctrineMongoDBRepository
14
 */
15
class DoctrineMongoDBRepository extends MongoDBRepository implements WebPageRepository
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) {
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) {
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

src/Page/Infrastructure/Persistence/DoctrineORMRepository.php 1 location

@@ 14-85 (lines=72) @@
11
/**
12
 * Class DoctrineORMRepository
13
 */
14
class DoctrineORMRepository extends ORMRepository implements WebPageRepository
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) {
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) {
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