Completed
Push — master ( fc7b1e...f39e81 )
by Benedikt
08:37
created

Tournament::getUserIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
rs 10
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\UserInterface;
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
  /**
36
   * @ORM\Column(type="string")
37
   * @var string
38
   */
39
  private $tournamentListId;
40
  /**
41
   * @ORM\ManyToOne(targetEntity="\Tfboe\FmLib\Entity\UserInterface")
42
   * @var UserInterface
43
   */
44
  private $creator;
45
  /**
46
   * @ORM\OneToMany(targetEntity="\Tfboe\FmLib\Entity\CompetitionInterface", mappedBy="tournament",indexBy="name")
47
   * @var Collection|CompetitionInterface[]
48
   */
49
  private $competitions;
50
//</editor-fold desc="Fields">
51
52
//<editor-fold desc="Public Methods">
53
  /**
54
   * @inheritDoc
55
   */
56
  public function getChildren(): Collection
57
  {
58
    return $this->getCompetitions();
59
  }
60
61
  /**
62
   * @return CompetitionInterface[]|Collection
63
   */
64
  public function getCompetitions()
65
  {
66
    return $this->competitions;
67
  }
68
69
  /**
70
   * @return UserInterface
71
   */
72
  public function getCreator(): UserInterface
73
  {
74
    return $this->creator;
75
  }
76
77
  /**
78
   * @inheritDoc
79
   */
80
  public function getLevel(): int
81
  {
82
    return Level::TOURNAMENT;
83
  }
84
85
  /**
86
   * @inheritDoc
87
   */
88
  public function getLocalIdentifier()
89
  {
90
    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...
91
  }
92
93
  /**
94
   * @inheritDoc
95
   */
96
  public function getParent(): ?TournamentHierarchyInterface
97
  {
98
    return null;
99
  }
100
101
  /**
102
   * @return string
103
   */
104
  public function getTournamentListId(): string
105
  {
106
    return $this->tournamentListId;
107
  }
108
109
  /**
110
   * Tournament constructor.
111
   */
112
  protected final function init()
113
  {
114
    $this->tournamentListId = "";
115
    $this->competitions = new ArrayCollection();
116
  }
117
118
  /**
119
   * @param UserInterface $creator
120
   * @return TournamentInterface|Tournament
121
   */
122
  public function setCreator(UserInterface $creator)
123
  {
124
    $this->creator = $creator;
125
    return $this;
126
  }
127
128
  /**
129
   * @param string $tournamentListId
130
   * @return TournamentInterface|Tournament
131
   */
132
  public function setTournamentListId(string $tournamentListId)
133
  {
134
    $this->tournamentListId = $tournamentListId;
135
    return $this;
136
  }
137
//</editor-fold desc="Public Methods">
138
}