Completed
Push — master ( 685463...a3ac99 )
by Benedikt
13:47
created

Tournament::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
rs 9.4285
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 9/17/17
7
 * Time: 11:35 AM
8
 */
9
10
namespace Tfboe\FmLib\Entity\Traits;
11
12
13
use Doctrine\Common\Collections\ArrayCollection;
14
use Doctrine\Common\Collections\Collection;
15
use Doctrine\ORM\Mapping as ORM;
16
use Tfboe\FmLib\Entity\CompetitionInterface;
17
use Tfboe\FmLib\Entity\Helpers\NameEntity;
18
use Tfboe\FmLib\Entity\Helpers\TimestampableEntity;
19
use Tfboe\FmLib\Entity\Helpers\TournamentHierarchyInterface;
20
use Tfboe\FmLib\Entity\TournamentInterface;
21
use Tfboe\FmLib\Entity\User;
22
use Tfboe\FmLib\Helpers\Level;
23
24
/**
25
 * Trait Tournament
26
 * @package Tfboe\FmLib\Entity\Traits
27
 */
28
trait Tournament
29
{
30
  use TimestampableEntity;
31
  use NameEntity;
32
33
//<editor-fold desc="Fields">
34
  /**
35
   * @ORM\Column(type="string")
36
   * @var string
37
   */
38
  private $userIdentifier;
39
40
  /**
41
   * @ORM\Column(type="string")
42
   * @var string
43
   */
44
  private $tournamentListId;
45
  /**
46
   * @ORM\ManyToOne(targetEntity="\Tfboe\FmLib\Entity\User")
47
   * @var User
48
   */
49
  private $creator;
50
  /**
51
   * @ORM\OneToMany(targetEntity="\Tfboe\FmLib\Entity\CompetitionInterface", mappedBy="tournament",indexBy="name")
52
   * @var Collection|CompetitionInterface[]
53
   */
54
  private $competitions;
55
//</editor-fold desc="Fields">
56
57
//<editor-fold desc="Public Methods">
58
  /**
59
   * @inheritDoc
60
   */
61
  public function getChildren(): Collection
62
  {
63
    return $this->getCompetitions();
64
  }
65
66
  /**
67
   * @return CompetitionInterface[]|Collection
68
   */
69
  public function getCompetitions()
70
  {
71
    return $this->competitions;
72
  }
73
74
  /**
75
   * @return User
76
   */
77
  public function getCreator(): User
78
  {
79
    return $this->creator;
80
  }
81
82
  /**
83
   * @inheritDoc
84
   */
85
  public function getLevel(): int
86
  {
87
    return Level::TOURNAMENT;
88
  }
89
90
  /**
91
   * @inheritDoc
92
   */
93
  public function getLocalIdentifier()
94
  {
95
    return $this->getId();
0 ignored issues
show
Bug introduced by
It seems like getId() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
96
  }
97
98
  /**
99
   * @inheritDoc
100
   */
101
  public function getParent(): ?TournamentHierarchyInterface
102
  {
103
    return null;
104
  }
105
106
  /**
107
   * @return string
108
   */
109
  public function getTournamentListId(): string
110
  {
111
    return $this->tournamentListId;
112
  }
113
114
  /**
115
   * @return string
116
   */
117
  public function getUserIdentifier(): string
118
  {
119
    return $this->userIdentifier;
120
  }
121
122
  /**
123
   * Tournament constructor.
124
   */
125
  public function init()
126
  {
127
    $this->tournamentListId = "";
128
    $this->competitions = new ArrayCollection();
129
  }
130
131
  /**
132
   * @param User $creator
133
   * @return TournamentInterface|Tournament
134
   */
135
  public function setCreator(User $creator)
136
  {
137
    $this->creator = $creator;
138
    return $this;
139
  }
140
141
  /**
142
   * @param string $tournamentListId
143
   * @return TournamentInterface|Tournament
144
   */
145
  public function setTournamentListId(string $tournamentListId)
146
  {
147
    $this->tournamentListId = $tournamentListId;
148
    return $this;
149
  }
150
151
  /**
152
   * @param string $userIdentifier
153
   * @return TournamentInterface|Tournament
154
   */
155
  public function setUserIdentifier(string $userIdentifier)
156
  {
157
    $this->userIdentifier = $userIdentifier;
158
    return $this;
159
  }
160
//</editor-fold desc="Public Methods">
161
}