TimeEntity   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 0
dl 0
loc 89
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getEndTime() 0 8 3
A getStartTime() 0 8 3
A setEndTime() 0 7 2
A setStartTime() 0 7 2
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 1/2/18
7
 * Time: 2:57 PM
8
 */
9
10
namespace Tfboe\FmLib\Entity\Helpers;
11
12
/**
13
 * Trait TimeEntity
14
 * @package Tfboe\FmLib\Entity\Helpers
15
 */
16
trait TimeEntity
17
{
18
//<editor-fold desc="Fields">
19
  /**
20
   * @ORM\Column(type="datetime", nullable=true)
21
   * @var \DateTime|null
22
   */
23
  private $startTime = null;
24
25
  /**
26
   * @ORM\Column(type="datetime", nullable=true)
27
   * @var \DateTime|null
28
   */
29
  private $endTime = null;
30
31
  /**
32
   * @ORM\Column(type="string")
33
   * @var string
34
   */
35
  private $startTimezone = "";
36
37
  /**
38
   * @ORM\Column(type="string")
39
   * @var string
40
   */
41
  private $endTimezone = "";
42
43
  /**
44
   * @var bool
45
   */
46
  private $startLocalized = false;
47
48
  /**
49
   * @var bool
50
   */
51
  private $endLocalized = false;
52
//</editor-fold desc="Fields">
53
54
//<editor-fold desc="Public Methods">
55
  /**
56
   * @return \DateTime|null
57
   */
58
  public function getEndTime(): ?\DateTime
59
  {
60
    if ($this->endTime !== null && !$this->endLocalized) {
61
      $this->endTime->setTimezone(new \DateTimeZone($this->endTimezone));
62
      $this->endLocalized = true;
63
    }
64
    return $this->endTime;
65
  }
66
67
  /**
68
   * @return \DateTime|null
69
   */
70
  public function getStartTime(): ?\DateTime
71
  {
72
    if ($this->startTime !== null && !$this->startLocalized) {
73
      $this->startTime->setTimezone(new \DateTimeZone($this->startTimezone));
74
      $this->startLocalized = true;
75
    }
76
    return $this->startTime;
77
  }
78
79
80
  /**
81
   * @param \DateTime|null $endTime
82
   * @return $this|TimeEntity
0 ignored issues
show
Comprehensibility Bug introduced by
The return type TimeEntity is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
83
   */
84
  public function setEndTime(?\DateTime $endTime)
85
  {
86
    $this->endTime = $endTime;
87
    $this->endTimezone = $endTime === null ? "" : $endTime->getTimezone()->getName();
88
    $this->endLocalized = true;
89
    return $this;
90
  }
91
92
  /**
93
   * @param \DateTime|null $startTime
94
   * @return $this|TimeEntity
0 ignored issues
show
Comprehensibility Bug introduced by
The return type TimeEntity is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
95
   */
96
  public function setStartTime(?\DateTime $startTime)
97
  {
98
    $this->startTime = $startTime;
99
    $this->startTimezone = $startTime === null ? "" : $startTime->getTimezone()->getName();
100
    $this->startLocalized = true;
101
    return $this;
102
  }
103
//</editor-fold desc="Public Methods">
104
}