SimpleMachinesBridge::getPostEntity()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 12
loc 12
ccs 0
cts 9
cp 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Comrade42\PhpBBParser\Bridge;
4
5
use Comrade42\PhpBBParser\Entity\EntityInterface;
6
use Comrade42\PhpBBParser\Entity\SimpleMachines\BoardEntity;
7
use Comrade42\PhpBBParser\Entity\SimpleMachines\CategoryEntity;
8
use Comrade42\PhpBBParser\Entity\SimpleMachines\MemberEntity;
9
use Comrade42\PhpBBParser\Entity\SimpleMachines\MessageEntity;
10
use Comrade42\PhpBBParser\Entity\SimpleMachines\TopicEntity;
11
use Doctrine\ORM\EntityManager;
12
13
/**
14
 * Class SimpleMachinesBridge
15
 * @package Comrade42\PhpBBParser\Bridge
16
 */
17
class SimpleMachinesBridge implements BridgeInterface
18
{
19
    /**
20
     * @param EntityManager $entityManager
21
     * @param int|null $entityId
22
     * @return MemberEntity
23
     */
24 View Code Duplication
    public function getMemberEntity(EntityManager $entityManager, $entityId = null)
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...
25
    {
26
        /** @var \Comrade42\PhpBBParser\Entity\SimpleMachines\MemberEntity $entity */
27
        $entity = $entityManager->find('Comrade42\PhpBBParser\Entity\SimpleMachines\MemberEntity', $entityId);
28
29
        if (empty($entity)) {
30
            $entity = new MemberEntity();
31
            $entity->setId($entityId);
32
        }
33
34
        return $entity;
35
    }
36
37
    /**
38
     * @param EntityManager $entityManager
39
     * @param int|null $entityId
40
     * @return CategoryEntity
41
     */
42 View Code Duplication
    public function getCategoryEntity(EntityManager $entityManager, $entityId = null)
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
        /** @var \Comrade42\PhpBBParser\Entity\SimpleMachines\CategoryEntity $entity */
45
        $entity = $entityManager->find('Comrade42\PhpBBParser\Entity\SimpleMachines\CategoryEntity', $entityId);
46
47
        if (empty($entity)) {
48
            $entity = new CategoryEntity();
49
            $entity->idCat = $entityId;
50
        }
51
52
        return $entity;
53
    }
54
55
    /**
56
     * @param EntityManager $entityManager
57
     * @param int|null $entityId
58
     * @return BoardEntity
59
     */
60 View Code Duplication
    public function getForumEntity(EntityManager $entityManager, $entityId = null)
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...
61
    {
62
        /** @var \Comrade42\PhpBBParser\Entity\SimpleMachines\BoardEntity $entity */
63
        $entity = $entityManager->find('Comrade42\PhpBBParser\Entity\SimpleMachines\BoardEntity', $entityId);
64
65
        if (empty($entity)) {
66
            $entity = new BoardEntity();
67
            $entity->idBoard = $entityId;
68
        }
69
70
        return $entity;
71
    }
72
73
    /**
74
     * @param EntityManager $entityManager
75
     * @param int|null $entityId
76
     * @return TopicEntity
77
     */
78 View Code Duplication
    public function getTopicEntity(EntityManager $entityManager, $entityId = null)
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...
79
    {
80
        /** @var \Comrade42\PhpBBParser\Entity\SimpleMachines\TopicEntity $entity */
81
        $entity = $entityManager->find('Comrade42\PhpBBParser\Entity\SimpleMachines\TopicEntity', $entityId);
82
83
        if (empty($entity)) {
84
            $entity = new TopicEntity();
85
            $entity->setId($entityId);
86
        }
87
88
        return $entity;
89
    }
90
91
    /**
92
     * @param EntityManager $entityManager
93
     * @param int|null $entityId
94
     * @return MessageEntity
95
     */
96 View Code Duplication
    public function getPostEntity(EntityManager $entityManager, $entityId = null)
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...
97
    {
98
        /** @var \Comrade42\PhpBBParser\Entity\SimpleMachines\MessageEntity $entity */
99
        $entity = $entityManager->find('Comrade42\PhpBBParser\Entity\SimpleMachines\MessageEntity', $entityId);
100
101
        if (empty($entity)) {
102
            $entity = new MessageEntity();
103
            $entity->setId($entityId);
104
        }
105
106
        return $entity;
107
    }
108
109
    /**
110
     * @param EntityManager $entityManager
111
     * @return BoardEntity[]
112
     */
113
    public function getForumList(EntityManager $entityManager)
114
    {
115
        return $entityManager->getRepository('Comrade42\PhpBBParser\Entity\SimpleMachines\BoardEntity')->findAll();
116
    }
117
118
    /**
119
     * @param EntityInterface $entity
120
     * @param string $expectedClass
121
     * @throws \InvalidArgumentException
122
     */
123
    protected function validateEntityClass(EntityInterface $entity, $expectedClass)
124
    {
125
        if (!$entity instanceof $expectedClass) {
126
            $actualClass = get_class($entity);
127
            throw new \InvalidArgumentException(
128
                "Wrong entity '{$actualClass}' specified! Instance of '{$expectedClass}' expected."
129
            );
130
        }
131
    }
132
}
133