Player::getAverage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace OSS\CoreBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
/**
8
 * @ORM\Entity
9
 */
10
class Player implements PlayerSkillsAverageInterface
11
{
12
    /**
13
     * @var int
14
     *
15
     * @ORM\Id
16
     * @ORM\GeneratedValue
17
     * @ORM\Column(type="integer")
18
     */
19
    private $id;
20
21
    /**
22
     * @var string
23
     *
24
     * @ORM\Column(type="string")
25
     */
26
    private $name;
27
28
    /**
29
     * @var Team
30
     *
31
     * @ORM\ManyToOne(targetEntity="Team", inversedBy="players")
32
     */
33
    private $team;
34
35
    /**
36
     * @var PlayerSkills
37
     *
38
     * @ORM\OneToOne(targetEntity="PlayerSkills", cascade={"all"})
39
     */
40
    private $skills;
41
42
    /**
43
     * @var Transfer
44
     *
45
     * @ORM\OneToMany(targetEntity="Transfer", mappedBy="player")
46
     */
47
    private $transfers;
48
49
    /**
50
     * @param Player $player
51
     *
52
     * @return bool
53
     */
54 3
    public function equals(Player $player)
55
    {
56 3
        return $this->id == $player->getId();
57
    }
58
59
    /**
60
     * @param int $id
61
     */
62 8
    public function setId($id)
63
    {
64 8
        $this->id = $id;
65 8
    }
66
67
    /**
68
     * @return int
69
     */
70 4
    public function getId()
71
    {
72 4
        return $this->id;
73
    }
74
75
    /**
76
     * @return string
77
     */
78 1
    public function getName()
79
    {
80 1
        return $this->name;
81
    }
82
83
    /**
84
     * @param string $name
85
     */
86 1
    public function setName($name)
87
    {
88 1
        $this->name = $name;
89 1
    }
90
91
    /**
92
     * @param Team $team
93
     */
94 31
    public function setTeam(Team $team)
95
    {
96 31
        if (null === $this->team || !$this->team->equals($team)) {
97 31
            $this->team = $team;
98 31
            $this->team->addPlayer($this);
99 31
        }
100 31
    }
101
102
    /**
103
     * @return Team
104
     */
105 4
    public function getTeam()
106
    {
107 4
        return $this->team;
108
    }
109
110
    /**
111
     * @return bool
112
     */
113 1
    public function hasTeam()
114
    {
115 1
        return null !== $this->team;
116
    }
117
118
    /**
119
     * @return Transfer
120
     */
121
    public function getTransfers()
122
    {
123
        return $this->transfers;
124
    }
125
126
    /**
127
     * @return float
128
     */
129 1
    public function getAverage()
130
    {
131 1
        return $this->skills->getAverage();
132
    }
133
134
    /**
135
     * @return int
136
     */
137 16
    public function getMarketValue()
138
    {
139 16
        return $this->getSkills()->getMarketValue();
140
    }
141
142
    /**
143
     * @return PlayerSkills
144
     */
145 28
    public function getSkills()
146
    {
147 28
        return $this->skills;
148
    }
149
150
    /**
151
     * @param PlayerSkills $skills
152
     */
153 28
    public function setSkills(PlayerSkills $skills)
154
    {
155 28
        $this->skills = $skills;
156 28
        if (null === $skills->getPlayer()) {
157 27
            $skills->setPlayer($this);
158 27
        }
159 28
    }
160
}
161