RecursiveEndStartTimeService::clearTimes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 1/7/18
7
 * Time: 9:04 PM
8
 */
9
10
namespace Tfboe\FmLib\Service\RankingSystem;
11
12
13
use Tfboe\FmLib\Entity\Helpers\TournamentHierarchyInterface;
14
use Tfboe\FmLib\Entity\TournamentInterface;
15
16
/**
17
 * Class RecursiveEndStartTimeService
18
 * @package Tfboe\FmLib\Service\RankingSystemListService
19
 */
20
class RecursiveEndStartTimeService implements TimeServiceInterface
21
{
22
//<editor-fold desc="Fields">
23
  /** @var \DateTime[] */
24
  private $times = [];
25
//</editor-fold desc="Fields">
26
27
//<editor-fold desc="Public Methods">
28
  /**
29
   * @inheritDoc
30
   */
31
  public function clearTimes()
32
  {
33
    $this->times = [];
34
  }
35
36
  /**
37
   * @inheritDoc
38
   */
39
  public function getTime(TournamentHierarchyInterface $entity)
40
  {
41
    $entityId = $entity->getId();
42
    if (!array_key_exists($entityId, $this->times)) {
43
      $this->times[$entityId] = $entity->getEndTime();
44
      if ($this->times[$entityId] == null) {
45
        $this->times[$entityId] = $entity->getStartTime();
46
        if ($this->times[$entityId] == null) {
47
          if ($entity->getParent() !== null) {
48
            $this->times[$entityId] = $this->getTime($entity->getParent());
49
          } else {
50
            //entity must be a tournament
51
            /** @var TournamentInterface $entity */
52
            $this->times[$entityId] = $entity->getUpdatedAt();
53
          }
54
        }
55
      }
56
    }
57
    return $this->times[$entityId];
58
  }
59
//</editor-fold desc="Public Methods">
60
}