Completed
Branch v1.x-dev (5c2708)
by Benjamin
04:14
created

Player   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Test Coverage

Coverage 27.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 17
eloc 33
c 1
b 0
f 0
dl 0
loc 130
ccs 11
cts 40
cp 0.275
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A setNumber() 0 5 1
A getPosition() 0 3 1
A setPosition() 0 5 1
A addVersion() 0 8 2
A getId() 0 3 1
A removeVersion() 0 11 3
A setStarPlayer() 0 5 1
A getVersions() 0 3 1
A getStarPlayer() 0 3 1
A __construct() 0 3 1
A getNumber() 0 3 1
A isStarPlayer() 0 3 1
A getTeam() 0 3 1
A setTeam() 0 5 1
1
<?php
2
3
namespace Obblm\Core\Entity;
4
5
use Obblm\Core\Entity\Traits\DeadAndFireTrait;
6
use Obblm\Core\Entity\Traits\NameTrait;
7
use Obblm\Core\Repository\PlayerRepository;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\Common\Collections\Collection;
10
use Doctrine\ORM\Mapping as ORM;
11
12
/**
13
 * @ORM\Entity(repositoryClass=PlayerRepository::class)
14
 * @ORM\Table(name="obblm_team_player")
15
 */
16
class Player
17
{
18
    /**
19
     * @ORM\Id()
20
     * @ORM\GeneratedValue()
21
     * @ORM\Column(type="integer")
22
     */
23
    private $id;
24
25
    use NameTrait, DeadAndFireTrait;
26
27
    /**
28
     * @ORM\ManyToOne(targetEntity=Team::class, inversedBy="players")
29
     * @ORM\JoinColumn(nullable=false)
30
     */
31
    private $team;
32
33
    /**
34
     * @ORM\Column(type="integer")
35
     */
36
    private $number;
37
38
    /**
39
     * @ORM\Column(type="string", length=50)
40
     */
41
    private $position;
42
43
    /**
44
     * @ORM\Column(type="string", length=255)
45
     */
46
    private $starPlayer = false;
47
48
    /**
49
     * @ORM\OneToMany(targetEntity=PlayerVersion::class, mappedBy="player", orphanRemoval=true, cascade={"remove"})
50
     * @ORM\OrderBy({"id"="DESC"})
51
     */
52
    private $versions;
53
54 2
    public function __construct()
55
    {
56 2
        $this->versions = new ArrayCollection();
57 2
    }
58
59
    public function getId(): ?int
60
    {
61
        return $this->id;
62
    }
63
64
    public function getTeam(): ?Team
65
    {
66
        return $this->team;
67
    }
68
69 2
    public function setTeam(?Team $team): self
70
    {
71 2
        $this->team = $team;
72
73 2
        return $this;
74
    }
75
76
    public function getNumber(): ?int
77
    {
78
        return $this->number;
79
    }
80
81
    public function setNumber(int $number): self
82
    {
83
        $this->number = $number;
84
85
        return $this;
86
    }
87
88 1
    public function getPosition(): ?string
89
    {
90 1
        return $this->position;
91
    }
92
93 2
    public function setPosition(?string $position): self
94
    {
95 2
        $this->position = $position;
96
97 2
        return $this;
98
    }
99
100
    public function getStarPlayer(): ?bool
101
    {
102
        return $this->starPlayer;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->starPlayer returns the type string which is incompatible with the type-hinted return boolean|null.
Loading history...
103
    }
104
105
    public function isStarPlayer(): ?bool
106
    {
107
        return $this->starPlayer;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->starPlayer returns the type string which is incompatible with the type-hinted return boolean|null.
Loading history...
108
    }
109
110
    public function setStarPlayer(bool $starPlayer): self
111
    {
112
        $this->starPlayer = $starPlayer;
0 ignored issues
show
Documentation Bug introduced by
The property $starPlayer was declared of type string, but $starPlayer is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
113
114
        return $this;
115
    }
116
117
    /**
118
     * @return Collection|PlayerVersion[]
119
     */
120
    public function getVersions(): Collection
121
    {
122
        return $this->versions;
123
    }
124
125
    public function addVersion(PlayerVersion $version): self
126
    {
127
        if (!$this->versions->contains($version)) {
128
            $this->versions[] = $version;
129
            $version->setPlayer($this);
130
        }
131
132
        return $this;
133
    }
134
135
    public function removeVersion(PlayerVersion $version): self
136
    {
137
        if ($this->versions->contains($version)) {
138
            $this->versions->removeElement($version);
139
            // set the owning side to null (unless already changed)
140
            if ($version->getPlayer() === $this) {
141
                $version->setPlayer(null);
142
            }
143
        }
144
145
        return $this;
146
    }
147
}
148