Birt   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 24
eloc 47
c 1
b 0
f 0
dl 0
loc 113
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setDate() 0 8 2
A getDati() 0 3 1
A isPrefix() 0 3 1
A setDati() 0 3 1
A getDateFormatted() 0 3 1
A setPlac() 0 3 1
A getMonth() 0 15 5
A getDay() 0 16 6
A getYear() 0 13 4
A getPlac() 0 3 1
A getDate() 0 3 1
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
/**
18
 * Class Chan.
19
 */
20
class Birt extends \Gedcom\Record
21
{
22
    private $months = [
23
        'JAN' => '01', 'FEB' => '02', 'MAR' => '03', 'APR' => '04', 'MAY' => '05', 'JUN' => '06',
24
        'JUL' => '07', 'AUG' => '08', 'SEP' => '09', 'OCT' => '10', 'NOV' => '11', 'DEC' => '12',
25
    ];
26
27
    public $date;
28
29
    public $month;
30
31
    public $year;
32
33
    public $dateFormatted;
34
35
    public $dati;
36
37
    public $plac;
38
39
    public function setDate($date)
40
    {
41
        $this->date = $date;
42
        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...
43
            $this->dateFormatted = $this->getYear().'-'.$this->getMonth().'-'.substr("0{$this->getDay()}", -2);
44
        } else {
45
            $this->month = $this->getMonth();
46
            $this->year = $this->getYear();
47
        }
48
    }
49
50
    public function getDateFormatted()
51
    {
52
        return $this->dateFormatted;
53
    }
54
55
    public function getDate()
56
    {
57
        return $this->date;
58
    }
59
60
    public function setDati($dati)
61
    {
62
        $this->dati = $dati;
63
    }
64
65
    public function getDati()
66
    {
67
        return $this->dati;
68
    }
69
70
    public function setPlac($plac)
71
    {
72
        $this->plac = $plac;
73
    }
74
75
    public function getPlac()
76
    {
77
        return $this->plac;
78
    }
79
80
    public function getDay()
81
    {
82
        $record = explode(' ', $this->date);
83
        if (!empty($record[0])) {
84
            if ($this->isPrefix($record[0])) {
85
                unset($record[0]);
86
            }
87
            if (count($record) > 0) {
88
                $day = (int) reset($record);
89
                if ($day >= 1 && $day <= 31) {
90
                    return $day;
91
                }
92
            }
93
        }
94
95
        return null;
96
    }
97
98
    public function getMonth()
99
    {
100
        $record = explode(' ', $this->date);
101
        if (count($record) > 0) {
102
            if ($this->isPrefix($record[0])) {
103
                unset($record[0]);
104
            }
105
            foreach ($record as $part) {
106
                if (isset($this->months[trim($part)])) {
107
                    return $this->months[trim($part)];
108
                }
109
            }
110
        }
111
112
        return null;
113
    }
114
115
    public function getYear()
116
    {
117
        $record = explode(' ', $this->date);
118
        if (count($record) > 0) {
119
            if ($this->isPrefix($record[0])) {
120
                unset($record[0]);
121
            }
122
            if (count($record) > 0) {
123
                return (int) end($record);
124
            }
125
        }
126
127
        return null;
128
    }
129
130
    private function isPrefix($datePart)
131
    {
132
        return in_array($datePart, ['FROM', 'TO', 'BEF', 'AFT', 'BET', 'AND', 'ABT', 'EST', 'CAL', 'INT']);
133
    }
134
}
135