1 | <?php |
||
2 | /** |
||
3 | * php-gedcom. |
||
4 | * |
||
5 | * php-gedcom is a library for parsing, manipulating, importing and exporting |
||
6 | * GEDCOM 5.5 files in PHP 5.3+. |
||
7 | * |
||
8 | * @author Kristopher Wilson <[email protected]> |
||
9 | * @copyright Copyright (c) 2010-2013, Kristopher Wilson |
||
10 | * @license MIT |
||
11 | * |
||
12 | * @link http://github.com/mrkrstphr/php-gedcom |
||
13 | */ |
||
14 | |||
15 | namespace Gedcom\Parser; |
||
16 | |||
17 | class Date extends \Gedcom\Parser\Component |
||
18 | { |
||
19 | public static function parse(\Gedcom\Parser $parser) |
||
20 | { |
||
21 | $record = $parser->getCurrentLineRecord(); |
||
22 | $depth = (int) $record[0]; |
||
23 | |||
24 | $parser->forward(); |
||
25 | $record = $parser->getCurrentLineRecord(); |
||
26 | |||
27 | if (isset($record[1])) { |
||
28 | $dat = new \Gedcom\Record\Date(); |
||
29 | if (!empty($record[2])) { |
||
30 | $dat->setDate($record[2]); |
||
31 | } |
||
32 | } else { |
||
33 | $parser->skipToNextLevel($depth); |
||
34 | |||
35 | return null; |
||
36 | } |
||
37 | |||
38 | if ($dat->getYear() && $dat->getMonth() && $dat->getDay()) { |
||
0 ignored issues
–
show
The expression
$dat->getMonth() of type integer|null is loosely compared to true ; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For 0 == false // true
0 == null // true
123 == false // false
123 == null // false
// It is often better to use strict comparison
0 === false // false
0 === null // false
![]() The expression
$dat->getYear() of type integer|null is loosely compared to true ; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For 0 == false // true
0 == null // true
123 == false // false
123 == null // false
// It is often better to use strict comparison
0 === false // false
0 === null // false
![]() |
|||
39 | return $dat->getYear().'-'.substr("0{$dat->getMonth()}", -2).'-'.substr("0{$dat->getDay()}", -2); |
||
40 | } |
||
41 | |||
42 | return $dat->getYear(); |
||
43 | } |
||
44 | } |
||
45 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: