Adventure   A
last analyzed

Complexity

Total Complexity 26

Size/Duplication

Total Lines 224
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 26
lcom 2
cbo 2
dl 0
loc 224
rs 10
c 0
b 0
f 0

21 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getId() 0 4 1
A setTitle() 0 6 1
A getTitle() 0 4 1
A setDescription() 0 6 1
A getDescription() 0 4 1
A setRewardPoint() 0 6 1
A getRewardPoint() 0 4 1
A setIsStepLinked() 0 6 1
A isStepLinked() 0 4 1
A setBadge() 0 6 1
A getBadge() 0 4 1
A addStep() 0 7 1
A removeStep() 0 6 1
A setSteps() 0 8 2
A getSteps() 0 4 1
A setTags() 0 4 1
A getTags() 0 4 1
A addTag() 0 6 1
A countAllNuts() 0 10 2
A countAllBadges() 0 10 4
1
<?php
2
3
namespace Badger\Bundle\GameBundle\Entity;
4
5
use Badger\Component\Game\Model\AdventureInterface;
6
use Badger\Component\Game\Model\AdventureStepInterface;
7
use Badger\Component\Game\Model\BadgeInterface;
8
use Badger\Component\Game\Model\TagInterface;
9
use Doctrine\Common\Collections\ArrayCollection;
10
11
/**
12
 * Adventure
13
 *
14
 * @author  Marie Bochu <[email protected]>
15
 * @license http://opensource.org/licenses/MIT The MIT License (MIT)
16
 */
17
class Adventure implements AdventureInterface
18
{
19
    /** @var int */
20
    private $id;
21
22
    /** @var string */
23
    private $title;
24
25
    /** @var string */
26
    private $description;
27
28
    /** @var int */
29
    private $rewardPoint;
30
31
    /** @var bool */
32
    private $isStepLinked;
33
34
    /** @var Badge */
35
    private $badge;
36
37
    /** @var ArrayCollection */
38
    private $steps;
39
40
    /** @var ArrayCollection */
41
    private $tags;
42
43
    public function __construct()
44
    {
45
        $this->steps = new ArrayCollection();
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getId()
52
    {
53
        return $this->id;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function setTitle($title)
60
    {
61
        $this->title = $title;
62
63
        return $this;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function getTitle()
70
    {
71
        return $this->title;
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function setDescription($description)
78
    {
79
        $this->description = $description;
80
81
        return $this;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function getDescription()
88
    {
89
        return $this->description;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function setRewardPoint($rewardPoint)
96
    {
97
        $this->rewardPoint = $rewardPoint;
98
99
        return $this;
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function getRewardPoint()
106
    {
107
        return $this->rewardPoint;
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    public function setIsStepLinked($isStepLinked)
114
    {
115
        $this->isStepLinked = $isStepLinked;
116
117
        return $this;
118
    }
119
120
    /**
121
     * {@inheritdoc}
122
     */
123
    public function isStepLinked()
124
    {
125
        return $this->isStepLinked;
126
    }
127
128
    /**
129
     * {@inheritdoc}
130
     */
131
    public function setBadge(BadgeInterface $badge)
132
    {
133
        $this->badge = $badge;
0 ignored issues
show
Documentation Bug introduced by
$badge is of type object<Badger\Component\...e\Model\BadgeInterface>, but the property $badge was declared to be of type object<Badger\Bundle\GameBundle\Entity\Badge>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
134
135
        return $this;
136
    }
137
138
    /**
139
     * {@inheritdoc}
140
     */
141
    public function getBadge()
142
    {
143
        return $this->badge;
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149
    public function addStep(AdventureStepInterface $step)
150
    {
151
        $step->setAdventure($this);
152
        $this->steps[] = $step;
153
154
        return $this;
155
    }
156
157
    /**
158
     * {@inheritdoc}
159
     */
160
    public function removeStep(AdventureStepInterface $step)
161
    {
162
        $this->steps->removeElement($step);
163
164
        return $this;
165
    }
166
167
    /**
168
     * {@inheritdoc}
169
     */
170
    public function setSteps($steps)
171
    {
172
        foreach ($steps as $step) {
173
            $this->addStep($step);
174
        }
175
176
        return $this;
177
    }
178
179
    /**
180
     * {@inheritdoc}
181
     */
182
    public function getSteps()
183
    {
184
        return $this->steps;
185
    }
186
187
    /**
188
     * {@inheritdoc}
189
     */
190
    public function setTags(ArrayCollection $tags)
191
    {
192
        $this->tags = $tags;
193
    }
194
195
    /**
196
     * {@inheritdoc}
197
     */
198
    public function getTags()
199
    {
200
        return $this->tags;
201
    }
202
203
    /**
204
     * {@inheritdoc}
205
     */
206
    public function addTag(TagInterface $tag)
207
    {
208
        $this->tags[] = $tag;
209
210
        return $this;
211
    }
212
213
    /**
214
     * @return int
215
     */
216
    public function countAllNuts()
217
    {
218
        $nuts = $this->getRewardPoint();
219
220
        foreach ($this->steps as $step) {
221
            $nuts += $step->getRewardPoint();
222
        }
223
224
        return $nuts;
225
    }
226
227
    /**
228
     * @return int
229
     */
230
    public function countAllBadges()
231
    {
232
        $badgesCount = (null === $this->getBadge()) ? 0 : 1;
233
234
        foreach ($this->steps as $step) {
235
            $badgesCount += (null === $step->getBadge()) ? 0 : 1;
236
        }
237
238
        return $badgesCount;
239
    }
240
}
241
242