This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace ValueObjects\DateTime; |
||
4 | |||
5 | use ValueObjects\Util\Util; |
||
6 | use ValueObjects\ValueObjectInterface; |
||
7 | |||
8 | class DateTimeWithTimeZone implements ValueObjectInterface |
||
9 | { |
||
10 | /** @var DateTime */ |
||
11 | protected $dateTime; |
||
12 | |||
13 | /** @var TimeZone */ |
||
14 | protected $timeZone; |
||
15 | |||
16 | /** |
||
17 | * Returns a new DateTime object from native values |
||
18 | * |
||
19 | * @param int $year |
||
0 ignored issues
–
show
|
|||
20 | * @param string $month |
||
0 ignored issues
–
show
There is no parameter named
$month . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
21 | * @param int $day |
||
0 ignored issues
–
show
There is no parameter named
$day . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
22 | * @param int $hour |
||
0 ignored issues
–
show
There is no parameter named
$hour . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
23 | * @param int $minute |
||
0 ignored issues
–
show
There is no parameter named
$minute . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
24 | * @param int $second |
||
0 ignored issues
–
show
There is no parameter named
$second . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
25 | * @param string $timezone |
||
0 ignored issues
–
show
There is no parameter named
$timezone . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
26 | * |
||
27 | * @return DateTimeWithTimeZone |
||
28 | */ |
||
29 | 1 | public static function fromNative() |
|
30 | { |
||
31 | 1 | $args = func_get_args(); |
|
32 | |||
33 | 1 | $datetime = DateTime::fromNative($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); |
|
34 | 1 | $timezone = TimeZone::fromNative($args[6]); |
|
35 | |||
36 | 1 | return new static($datetime, $timezone); |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * Returns a new DateTime from a native PHP \DateTime |
||
41 | * |
||
42 | * @param \DateTime $nativeDatetime |
||
43 | * |
||
44 | * @return DateTimeWithTimeZone |
||
45 | */ |
||
46 | 1 | public static function fromNativeDateTime(\DateTime $nativeDatetime) |
|
47 | { |
||
48 | 1 | $datetime = DateTime::fromNativeDateTime($nativeDatetime); |
|
49 | 1 | $timezone = TimeZone::fromNativeDateTimeZone($nativeDatetime->getTimezone()); |
|
50 | |||
51 | 1 | return new static($datetime, $timezone); |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Returns a DateTimeWithTimeZone object using current DateTime and default TimeZone |
||
56 | * |
||
57 | * @return DateTimeWithTimeZone |
||
58 | */ |
||
59 | 1 | public static function now() |
|
60 | { |
||
61 | 1 | return new static(DateTime::now(), TimeZone::fromDefault()); |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * Returns a new DateTimeWithTimeZone object |
||
66 | * |
||
67 | * @param DateTime $datetime |
||
68 | * @param TimeZone $timezone |
||
69 | */ |
||
70 | 9 | public function __construct(DateTime $datetime, TimeZone $timezone = null) |
|
71 | { |
||
72 | 9 | $this->dateTime = $datetime; |
|
73 | 9 | $this->timeZone = $timezone; |
|
74 | 9 | } |
|
75 | |||
76 | /** |
||
77 | * Tells whether two DateTimeWithTimeZone are equal by comparing their values |
||
78 | * |
||
79 | * @param ValueObjectInterface $dateTimeWithTimeZone |
||
80 | * |
||
81 | * @return bool |
||
82 | */ |
||
83 | 4 | public function sameValueAs(ValueObjectInterface $dateTimeWithTimeZone) |
|
84 | { |
||
85 | 4 | if (false === Util::classEquals($this, $dateTimeWithTimeZone)) { |
|
86 | 1 | return false; |
|
87 | } |
||
88 | |||
89 | 4 | return $this->getDateTime()->sameValueAs($dateTimeWithTimeZone->getDateTime()) && |
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
ValueObjects\ValueObjectInterface as the method getDateTime() does only exist in the following implementations of said interface: ValueObjects\DateTime\DateTimeWithTimeZone .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
90 | 4 | $this->getTimeZone()->sameValueAs($dateTimeWithTimeZone->getTimeZone()); |
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
ValueObjects\ValueObjectInterface as the method getTimeZone() does only exist in the following implementations of said interface: ValueObjects\DateTime\DateTimeWithTimeZone .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Tells whether two DateTimeWithTimeZone represents the same timestamp |
||
95 | * |
||
96 | * @param ValueObjectInterface $dateTimeWithTimeZone |
||
97 | * |
||
98 | * @return bool |
||
99 | */ |
||
100 | 1 | public function sameTimestampAs(ValueObjectInterface $dateTimeWithTimeZone) |
|
101 | { |
||
102 | 1 | if (false === Util::classEquals($this, $dateTimeWithTimeZone)) { |
|
103 | 1 | return false; |
|
104 | } |
||
105 | |||
106 | 1 | return $this->toNativeDateTime() == $dateTimeWithTimeZone->toNativeDateTime(); |
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
ValueObjects\ValueObjectInterface as the method toNativeDateTime() does only exist in the following implementations of said interface: ValueObjects\DateTime\Date , ValueObjects\DateTime\DateTime , ValueObjects\DateTime\DateTimeWithTimeZone , ValueObjects\DateTime\Time .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Returns datetime from current DateTimeWithTimeZone |
||
111 | * |
||
112 | * @return DateTime |
||
113 | */ |
||
114 | 8 | public function getDateTime() |
|
115 | { |
||
116 | 8 | return clone $this->dateTime; |
|
117 | } |
||
118 | |||
119 | /** |
||
120 | * Returns timezone from current DateTimeWithTimeZone |
||
121 | * |
||
122 | * @return TimeZone |
||
123 | */ |
||
124 | 8 | public function getTimeZone() |
|
125 | { |
||
126 | 8 | return clone $this->timeZone; |
|
127 | } |
||
128 | |||
129 | /** |
||
130 | * Returns a native PHP \DateTime version of the current DateTimeWithTimeZone |
||
131 | * |
||
132 | * @return \DateTime |
||
133 | */ |
||
134 | 2 | public function toNativeDateTime() |
|
135 | { |
||
136 | 2 | $date = $this->getDateTime()->getDate(); |
|
137 | 2 | $time = $this->getDateTime()->getTime(); |
|
138 | 2 | $year = $date->getYear()->toNative(); |
|
139 | 2 | $month = $date->getMonth()->getNumericValue(); |
|
140 | 2 | $day = $date->getDay()->toNative(); |
|
141 | 2 | $hour = $time->getHour()->toNative(); |
|
142 | 2 | $minute = $time->getMinute()->toNative(); |
|
143 | 2 | $second = $time->getSecond()->toNative(); |
|
144 | 2 | $timezone = $this->getTimeZone()->toNativeDateTimeZone(); |
|
145 | |||
146 | 2 | $dateTime = new \DateTime(); |
|
147 | 2 | $dateTime->setTimezone($timezone); |
|
148 | 2 | $dateTime->setDate($year, $month, $day); |
|
149 | 2 | $dateTime->setTime($hour, $minute, $second); |
|
150 | |||
151 | 2 | return $dateTime; |
|
152 | } |
||
153 | |||
154 | /** |
||
155 | * Returns DateTime as string in format "Y-n-j G:i:s e" |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | 2 | public function __toString() |
|
160 | { |
||
161 | 2 | return \sprintf('%s %s', $this->getDateTime(), $this->getTimeZone()); |
|
162 | } |
||
163 | } |
||
164 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.