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 | /* |
||
4 | * This file is part of the eluceo/iCal package. |
||
5 | * |
||
6 | * (c) Markus Poerschke <[email protected]> |
||
7 | * |
||
8 | * This source file is subject to the MIT license that is bundled |
||
9 | * with this source code in the file LICENSE. |
||
10 | */ |
||
11 | |||
12 | namespace Eluceo\iCal\Component; |
||
13 | |||
14 | use Eluceo\iCal\Component; |
||
15 | use Eluceo\iCal\Property\Event\RecurrenceRule; |
||
16 | use Eluceo\iCal\PropertyBag; |
||
17 | |||
18 | /** |
||
19 | * Implementation of Standard Time and Daylight Saving Time observances (or rules) |
||
20 | * which define the TIMEZONE component. |
||
21 | */ |
||
22 | class TimezoneRule extends Component |
||
23 | { |
||
24 | const TYPE_DAYLIGHT = 'DAYLIGHT'; |
||
25 | const TYPE_STANDARD = 'STANDARD'; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $type; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $tzOffsetFrom; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $tzOffsetTo; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $tzName; |
||
46 | |||
47 | /** |
||
48 | * @var \DateTimeInterface |
||
49 | */ |
||
50 | protected $dtStart; |
||
51 | |||
52 | /** |
||
53 | * @var RecurrenceRule |
||
54 | */ |
||
55 | protected $recurrenceRule; |
||
56 | |||
57 | /** |
||
58 | * create new Timezone Rule object by giving a rule type identifier. |
||
59 | * |
||
60 | * @param string $ruleType one of DAYLIGHT or STANDARD |
||
61 | * |
||
62 | * @throws \InvalidArgumentException |
||
63 | */ |
||
64 | View Code Duplication | public function __construct($ruleType) |
|
0 ignored issues
–
show
|
|||
65 | { |
||
66 | $ruleType = strtoupper($ruleType); |
||
67 | if ($ruleType === self::TYPE_DAYLIGHT || $ruleType === self::TYPE_STANDARD) { |
||
68 | $this->type = $ruleType; |
||
69 | } else { |
||
70 | throw new \InvalidArgumentException('Invalid value for timezone rule type'); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | public function buildPropertyBag() |
||
78 | { |
||
79 | $propertyBag = new PropertyBag(); |
||
80 | |||
81 | if ($this->getTzName()) { |
||
82 | $propertyBag->set('TZNAME', $this->getTzName()); |
||
83 | } |
||
84 | |||
85 | if ($this->getTzOffsetFrom()) { |
||
86 | $propertyBag->set('TZOFFSETFROM', $this->getTzOffsetFrom()); |
||
87 | } |
||
88 | |||
89 | if ($this->getTzOffsetTo()) { |
||
90 | $propertyBag->set('TZOFFSETTO', $this->getTzOffsetTo()); |
||
91 | } |
||
92 | |||
93 | if ($this->getDtStart()) { |
||
0 ignored issues
–
show
The expression
$this->getDtStart() of type string|null is loosely compared to true ; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
![]() |
|||
94 | $propertyBag->set('DTSTART', $this->getDtStart()); |
||
95 | } |
||
96 | |||
97 | if ($this->recurrenceRule) { |
||
98 | $propertyBag->set('RRULE', $this->recurrenceRule); |
||
99 | } |
||
100 | |||
101 | return $propertyBag; |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @param $offset |
||
106 | * |
||
107 | * @return $this |
||
108 | */ |
||
109 | public function setTzOffsetFrom($offset) |
||
110 | { |
||
111 | $this->tzOffsetFrom = $offset; |
||
112 | |||
113 | return $this; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * @param $offset |
||
118 | * |
||
119 | * @return $this |
||
120 | */ |
||
121 | public function setTzOffsetTo($offset) |
||
122 | { |
||
123 | $this->tzOffsetTo = $offset; |
||
124 | |||
125 | return $this; |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * @param $name |
||
130 | * |
||
131 | * @return $this |
||
132 | */ |
||
133 | public function setTzName($name) |
||
134 | { |
||
135 | $this->tzName = $name; |
||
136 | |||
137 | return $this; |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * @return $this |
||
142 | */ |
||
143 | public function setDtStart(\DateTimeInterface $dtStart) |
||
144 | { |
||
145 | $this->dtStart = $dtStart; |
||
146 | |||
147 | return $this; |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * @return $this |
||
152 | */ |
||
153 | public function setRecurrenceRule(RecurrenceRule $recurrenceRule) |
||
154 | { |
||
155 | $this->recurrenceRule = $recurrenceRule; |
||
156 | |||
157 | return $this; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * {@inheritdoc} |
||
162 | */ |
||
163 | public function getType() |
||
164 | { |
||
165 | return $this->type; |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * @return string |
||
170 | */ |
||
171 | public function getTzOffsetFrom() |
||
172 | { |
||
173 | return $this->tzOffsetFrom; |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * @return string |
||
178 | */ |
||
179 | public function getTzOffsetTo() |
||
180 | { |
||
181 | return $this->tzOffsetTo; |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * @return string |
||
186 | */ |
||
187 | public function getTzName() |
||
188 | { |
||
189 | return $this->tzName; |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * @return RecurrenceRule |
||
194 | */ |
||
195 | public function getRecurrenceRule() |
||
196 | { |
||
197 | return $this->recurrenceRule; |
||
198 | } |
||
199 | |||
200 | /** |
||
201 | * @return mixed return string representation of start date or NULL if no date was given |
||
202 | */ |
||
203 | public function getDtStart() |
||
204 | { |
||
205 | if ($this->dtStart) { |
||
206 | return $this->dtStart->format('Ymd\THis'); |
||
207 | } |
||
208 | |||
209 | return; |
||
210 | } |
||
211 | } |
||
212 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.