Test Failed
Push — master ( 3f892b...ca4849 )
by Curtis
03:14 queued 02:42
created

Buri::getDati()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
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\Record;
16
17
use Gedcom\Record;
18
19
/**
20
 * Class Chan.
21
 */
22
class Buri extends \Gedcom\Record
23
{
24
    private $months = [
25
        'JAN' => '01', 'FEB' => '02', 'MAR' => '03', 'APR' => '04', 'MAY' => '05', 'JUN' => '06',
26
        'JUL' => '07', 'AUG' => '08', 'SEP' => '09', 'OCT' => '10', 'NOV' => '11', 'DEC' => '12',
27
    ];
28
    
29
    public $date;
30
31
    public $year;
32
33
    public $dateFormatted = null;
34
    
35
    public $dati;
36
    
37
    public $plac;
38
    
39
    public function setDate($date) {
40
        $this->date = $date;
41
        if ($this->getDay()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getDay() 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 ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

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
Loading history...
42
            $this->dateFormatted = $this->getYear() .'-'. $this->getMonth() .'-'. substr("0{$this->getDay()}", -2);
43
        }
44
        else {
45
            $this->dateFormatted = null;
46
            $this->year = $date;
47
            $this->date = null;
48
        }
49
    }
50
    
51
    public function getDateFormatted() {
52
        return $this->dateFormatted;
53
    }
54
    
55
    public function getDate() {
56
        return $this->date;
57
    }
58
    
59
    public function setDati($dati) {
60
        $this->dati = $dati;
61
    }
62
    
63
    public function getDati() {
64
        return $this->dati;
65
    }
66
    
67
    public function setPlac($plac) {
68
        $this->plac = $plac;
69
    }
70
    
71
    public function getPlac() {
72
        return $this->plac;
73
    }
74
75
    public function getDay()
76
    {
77
        $record = explode(' ', $this->date);
78
        if (!empty($record[0])) {
79
            if ($this->isPrefix($record[0])) {
80
                unset($record[0]);
81
            }
82
            if (count($record) > 0) {
83
                $day = (int) reset($record);
84
                if ($day >= 1 && $day <= 31) {
85
                    return $day;
86
                }
87
            }
88
        }
89
90
        return null;
91
    }
92
93
    public function getMonth()
94
    {
95
        $record = explode(' ', $this->date);
96
        if (count($record) > 0) {
97
            if ($this->isPrefix($record[0])) {
98
                unset($record[0]);
99
            }
100
            foreach ($record as $part) {
101
                if (isset($this->months[trim($part)])) {
102
                    return $this->months[trim($part)];
103
                }
104
            }
105
        }
106
107
        return null;
108
    }
109
110
    public function getYear()
111
    {
112
        $record = explode(' ', $this->date);
113
        if (count($record) > 0) {
114
            if ($this->isPrefix($record[0])) {
115
                unset($record[0]);
116
            }
117
            if (count($record) > 0) {
118
                return (int) end($record);
119
            }
120
        }
121
122
        return null;
123
    }
124
125
    private function isPrefix($datePart)
126
    {
127
        return in_array($datePart, ['FROM', 'TO', 'BEF', 'AFT', 'BET', 'AND', 'ABT', 'EST', 'CAL', 'INT']);
128
    }
129
}
130