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

RankingSystem::setGenerationInterval()   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 1
rs 9.4285
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 1/2/18
7
 * Time: 8:47 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\AutomaticInstanceGeneration;
16
use Tfboe\FmLib\Entity\Helpers\NameEntity;
17
use Tfboe\FmLib\Entity\Helpers\SubClassData;
18
use Tfboe\FmLib\Entity\Helpers\TimestampableEntity;
19
use Tfboe\FmLib\Entity\Helpers\UUIDEntity;
20
use Tfboe\FmLib\Entity\RankingSystemListInterface;
21
use Tfboe\FmLib\Entity\TournamentInterface;
22
use Tfboe\FmLib\Exceptions\ValueNotValid;
23
use Tfboe\FmLib\Helpers\Level;
24
25
/**
26
 * Trait RankingSystem
27
 * @package Tfboe\FmLib\Entity\Traits
28
 */
29
trait RankingSystem
30
{
31
  use SubClassData;
32
  use TimestampableEntity;
33
  use UUIDEntity;
34
  use NameEntity;
35
36
  //<editor-fold desc="Fields">
37
38
  /**
39
   * @ORM\Column(type="string")
40
   *
41
   * @var string
42
   */
43
  private $serviceName;
44
  /**
45
   * @ORM\Column(type="smallint", nullable=true)
46
   * @var int|null
47
   */
48
  private $defaultForLevel;
49
50
  /**
51
   * @ORM\Column(type="integer")
52
   * @var int
53
   */
54
  private $generationInterval;
55
56
  /**
57
   * @ORM\ManyToMany(
58
   *     targetEntity="\Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity",
59
   *     mappedBy="rankingSystems",
60
   *     indexBy="id"
61
   * )
62
   * @ORM\JoinTable(name="relation__tournament_ranking_systems")
63
   * @var Collection|TournamentInterface[]
64
   */
65
  private $hierarchyEntries;
66
  /**
67
   * @ORM\Column(type="datetime", nullable=true)
68
   * @var \DateTime|null
69
   */
70
  private $openSyncFrom;
71
  /**
72
   * @ORM\OneToMany(targetEntity="\Tfboe\FmLib\Entity\RankingSystemListInterface", mappedBy="rankingSystem",
73
   *   indexBy="id")
74
   * @var Collection|RankingSystemListInterface[]
75
   */
76
  private $lists;
77
//</editor-fold desc="Fields">
78
79
//<editor-fold desc="Constructor">
80
//</editor-fold desc="Constructor">
81
82
//<editor-fold desc="Public Methods">
83
  /**
84
   * @return int|null
85
   */
86
  public function getDefaultForLevel(): ?int
87
  {
88
    return $this->defaultForLevel;
89
  }
90
91
  /**
92
   * @return int
93
   */
94
  public function getGenerationInterval(): int
95
  {
96
    return $this->generationInterval;
97
  }
98
99
  /**
100
   * @return TournamentInterface[]|Collection
101
   */
102
  public function getHierarchyEntries()
103
  {
104
    return $this->hierarchyEntries;
105
  }
106
107
  /**
108
   * @return RankingSystemListInterface[]|Collection
109
   */
110
  public function getLists(): Collection
111
  {
112
    return $this->lists;
113
  }
114
115
  /**
116
   * @return \DateTime|null
117
   */
118
  public function getOpenSyncFrom(): ?\DateTime
119
  {
120
    return $this->openSyncFrom;
121
  }
122
123
  /**
124
   * @return string
125
   */
126
  public function getServiceName(): string
127
  {
128
    return $this->serviceName;
129
  }
130
131
  /**
132
   * @param int|null $defaultForLevel
133
   * @throws ValueNotValid
134
   */
135
  public function setDefaultForLevel(?int $defaultForLevel)
136
  {
137
    if ($defaultForLevel !== null) {
138
      Level::ensureValidValue($defaultForLevel);
139
    }
140
    $this->defaultForLevel = $defaultForLevel;
141
  }
142
143
  /**
144
   * @param int $generationInterval
145
   * @throws \Tfboe\FmLib\Exceptions\ValueNotValid
146
   */
147
  public function setGenerationInterval(int $generationInterval)
148
  {
149
    AutomaticInstanceGeneration::ensureValidValue($generationInterval);
150
    $this->generationInterval = $generationInterval;
151
  }
152
153
  /**
154
   * @param \DateTime|null $openSyncFrom
155
   */
156
  public function setOpenSyncFrom(?\DateTime $openSyncFrom)
157
  {
158
    $this->openSyncFrom = $openSyncFrom;
159
  }
160
161
  /**
162
   * @param string $serviceName
163
   */
164
  public function setServiceName(string $serviceName)
165
  {
166
    $this->serviceName = $serviceName;
167
  }
168
//</editor-fold desc="Public Methods">
169
170
//<editor-fold desc="Protected Final Methods">
171
  /**
172
   * RankingSystem init
173
   * @param string[] $keys the keys of the subclass properties
174
   */
175
  protected final function init(array $keys)
176
  {
177
    $this->initSubClassData($keys);
178
    $this->generationInterval = AutomaticInstanceGeneration::OFF;
179
    $this->defaultForLevel = null;
180
    $this->openSyncFrom = null;
181
    $this->lists = new ArrayCollection();
182
    $this->hierarchyEntries = new ArrayCollection();
183
  }
184
//</editor-fold desc="Protected Final Methods">
185
}