Completed
Push — master ( c087ad...47fff7 )
by Benedikt
02:33
created

Ranking::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: 10/20/17
7
 * Time: 12:30 PM
8
 */
9
10
namespace Tfboe\FmLib\Entity\Traits;
11
12
use Doctrine\Common\Collections\ArrayCollection;
13
use Doctrine\Common\Collections\Collection;
14
use Doctrine\ORM\Mapping as ORM;
15
use Tfboe\FmLib\Entity\Helpers\NameEntity;
16
use Tfboe\FmLib\Entity\Helpers\UUIDEntity;
17
use Tfboe\FmLib\Entity\PhaseInterface;
18
use Tfboe\FmLib\Entity\TeamInterface;
19
20
/**
21
 * Trait Ranking
22
 * @package Tfboe\FmLib\Entity\Traits
23
 */
24
trait Ranking
25
{
26
  use UUIDEntity;
27
  use NameEntity;
28
29
//<editor-fold desc="Fields">
30
31
  /**
32
   * @ORM\ManyToMany(targetEntity="\Tfboe\FmLib\Entity\TeamInterface", indexBy="startNumber")
33
   * @ORM\JoinTable(name="relation__ranking_teams")
34
   * @var Collection|TeamInterface[]
35
   */
36
  private $teams;
37
38
  /**
39
   * @ORM\ManyToOne(targetEntity="\Tfboe\FmLib\Entity\PhaseInterface", inversedBy="rankings")
40
   * @var PhaseInterface
41
   */
42
  private $phase;
43
44
  /**
45
   * @ORM\Column(type="integer")
46
   * @var int
47
   */
48
  private $rank;
49
50
  /**
51
   * @ORM\Column(type="integer")
52
   * @var int
53
   */
54
  private $uniqueRank;
55
//</editor-fold desc="Fields">
56
57
//<editor-fold desc="Constructor">
58
//</editor-fold desc="Constructor">
59
60
//<editor-fold desc="Public Methods">
61
  /**
62
   * @return PhaseInterface
63
   */
64
  public function getPhase(): PhaseInterface
65
  {
66
    return $this->phase;
67
  }
68
69
  /**
70
   * @return int
71
   */
72
  public function getRank(): int
73
  {
74
    return $this->rank;
75
  }
76
77
  /**
78
   * @return TeamInterface[]|Collection
79
   */
80
  public function getTeams(): Collection
81
  {
82
    return $this->teams;
83
  }
84
85
  /**
86
   * @return int
87
   */
88
  public function getUniqueRank(): int
89
  {
90
    return $this->uniqueRank;
91
  }
92
93
  /**
94
   * @param PhaseInterface $phase
95
   */
96
  public function setPhase(PhaseInterface $phase)
97
  {
98
    if ($this->phase !== null) {
99
      $this->phase->getRankings()->remove($this->getUniqueRank());
100
    }
101
    $this->phase = $phase;
102
    $phase->getRankings()->set($this->getUniqueRank(), $this);
103
  }
104
105
  /**
106
   * @param int $rank
107
   */
108
  public function setRank(int $rank)
109
  {
110
    $this->rank = $rank;
111
  }
112
113
  /**
114
   * @param int $uniqueRank
115
   */
116
  public function setUniqueRank(int $uniqueRank)
117
  {
118
    $this->uniqueRank = $uniqueRank;
119
  }
120
//</editor-fold desc="Public Methods">
121
122
//<editor-fold desc="Protected Final Methods">
123
  /**
124
   * Ranking init
125
   */
126
  protected final function init()
127
  {
128
    $this->teams = new ArrayCollection();
129
    $this->name = "";
130
  }
131
//</editor-fold desc="Protected Final Methods">
132
133
134
}