| Conditions | 39 |
| Paths | 1149 |
| Total Lines | 115 |
| Code Lines | 78 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 207 | public function parse($value, $defaultToCurrentTime = true) |
||
| 208 | { |
||
| 209 | if(is_int($value) || is_float($value)) |
||
| 210 | return $value; |
||
| 211 | elseif(!is_string($value)) |
||
| 212 | throw new TInvalidDataValueException('date_to_parse_must_be_string', $value); |
||
| 213 | |||
| 214 | if(empty($this->pattern)) return time(); |
||
| 215 | |||
| 216 | $date = time(); |
||
| 217 | |||
| 218 | if($this->length(trim($value)) < 1) |
||
| 219 | return $defaultToCurrentTime ? $date : null; |
||
| 220 | |||
| 221 | $pattern = $this->pattern; |
||
| 222 | |||
| 223 | $i_val = 0; |
||
| 224 | $i_format = 0; |
||
| 225 | $pattern_length = $this->length($pattern); |
||
| 226 | $c = ''; |
||
| 227 | $token = ''; |
||
| 228 | $x = null; $y = null; |
||
| 229 | |||
| 230 | |||
| 231 | if($defaultToCurrentTime) |
||
| 232 | { |
||
| 233 | $year = "{$date['year']}"; |
||
| 234 | $month = $date['mon']; |
||
| 235 | $day = $date['mday']; |
||
| 236 | } |
||
| 237 | else |
||
| 238 | { |
||
| 239 | $year = null; |
||
| 240 | $month = null; |
||
| 241 | $day = null; |
||
| 242 | } |
||
| 243 | |||
| 244 | while ($i_format < $pattern_length) |
||
| 245 | { |
||
| 246 | $c = $this->charAt($pattern, $i_format); |
||
| 247 | $token = ''; |
||
| 248 | while ($this->charEqual($pattern, $i_format, $c) |
||
| 249 | && ($i_format < $pattern_length)) |
||
| 250 | { |
||
| 251 | $token .= $this->charAt($pattern, $i_format++); |
||
| 252 | } |
||
| 253 | |||
| 254 | if ($token == 'yyyy' || $token == 'yy' || $token == 'y') |
||
| 255 | { |
||
| 256 | if ($token == 'yyyy') { $x = 4;$y = 4; } |
||
| 257 | if ($token == 'yy') { $x = 2;$y = 2; } |
||
| 258 | if ($token == 'y') { $x = 2;$y = 4; } |
||
| 259 | $year = $this->getInteger($value, $i_val, $x, $y); |
||
| 260 | if($year === null) |
||
| 261 | return null; |
||
| 262 | //throw new TInvalidDataValueException('Invalid year', $value); |
||
| 263 | $i_val += strlen($year); |
||
| 264 | if(strlen($year) == 2) |
||
| 265 | { |
||
| 266 | $iYear = (int)$year; |
||
| 267 | if($iYear > 70) |
||
| 268 | $year = $iYear + 1900; |
||
| 269 | else |
||
| 270 | $year = $iYear + 2000; |
||
| 271 | } |
||
| 272 | $year = (int)$year; |
||
| 273 | } |
||
| 274 | elseif($token == 'MM' || $token == 'M') |
||
| 275 | { |
||
| 276 | $month = $this->getInteger($value,$i_val, |
||
| 277 | $this->length($token), 2); |
||
| 278 | $iMonth = (int)$month; |
||
| 279 | if($month === null || $iMonth < 1 || $iMonth > 12) |
||
| 280 | return null; |
||
| 281 | //throw new TInvalidDataValueException('Invalid month', $value); |
||
| 282 | $i_val += strlen($month); |
||
| 283 | $month = $iMonth; |
||
| 284 | } |
||
| 285 | elseif ($token == 'dd' || $token == 'd') |
||
| 286 | { |
||
| 287 | $day = $this->getInteger($value,$i_val, |
||
| 288 | $this->length($token), 2); |
||
| 289 | $iDay = (int)$day; |
||
| 290 | if($day === null || $iDay < 1 || $iDay > 31) |
||
| 291 | return null; |
||
| 292 | //throw new TInvalidDataValueException('Invalid day', $value); |
||
| 293 | $i_val += strlen($day); |
||
| 294 | $day = $iDay; |
||
| 295 | } |
||
| 296 | else |
||
| 297 | { |
||
| 298 | if($this->substring($value, $i_val, $this->length($token)) != $token) |
||
| 299 | return null; |
||
| 300 | //throw new TInvalidDataValueException("Subpattern '{$this->pattern}' mismatch", $value); |
||
| 301 | else |
||
| 302 | $i_val += $this->length($token); |
||
| 303 | } |
||
| 304 | } |
||
| 305 | if ($i_val != $this->length($value)) |
||
| 306 | return null; |
||
| 307 | //throw new TInvalidDataValueException("Pattern '{$this->pattern}' mismatch", $value); |
||
| 308 | if(!$defaultToCurrentTime && ($month === null || $day === null || $year === null)) |
||
| 309 | return null; |
||
| 310 | else |
||
| 311 | { |
||
| 312 | if(empty($year)) { |
||
| 313 | $year = date('Y'); |
||
| 314 | } |
||
| 315 | $day = (int)$day <= 0 ? 1 : (int)$day; |
||
| 316 | $month = (int)$month <= 0 ? 1 : (int)$month; |
||
| 317 | |||
| 318 | $s = new \DateTime; |
||
| 319 | $s->setDate($year, $month, $day); |
||
| 320 | $s->setTime(0, 0, 0); |
||
| 321 | return $s->getTimeStamp(); |
||
| 322 | } |
||
| 381 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths