Completed
Push — master ( 566db7...17d057 )
by Alberto
04:54
created

Entity::addUpdateAt()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace ADiaz\AML\OpenList\models;
4
5
/**
6
 * This file is part of the OpenList Parser utility.
7
 *
8
 * @category PHP
9
 *
10
 * @author    Alberto Diaz <[email protected]>
11
 * @copyright 2016 Alberto Diaz <[email protected]>
12
 * @license   This source file is subject to the MIT license that is bundled
13
 *
14
 * @version Release: @package_version@
15
 *
16
 * @link http://tytem.com
17
 */
18
19
/**
20
 * Class Entity.
21
 */
22
class Entity
23
{
24
    public $external_id;
25
    public $first_name;
26
    public $last_name;
27
    public $name_original_script;
28
    public $type;
29
    public $title;
30
    public $position;
31
    public $program_list;
32
    public $aka_list;
33
    public $address_list;
34
    public $id_list;
35
    public $nationality_list;
36
    public $citizenship_list;
37
    public $date_of_birth_list;
38
    public $place_of_birth_list;
39
    public $vessel;
40
    public $remarks;
41
    public $update_at_list;
42
43
    /* Individual */
44
    const TYPE_INDIVIDUAL = 'Individual';
45
46
    /* Entity / Company */
47
    const TYPE_ENTITY = 'Entity';
48
49
    /* prime alias */
50
    const ALIAS_TYPE_PRIME_ALIAS = 'Prime Alias';
51
52
    /* also known as */
53
    const ALIAS_TYPE_AKA = 'AKA';
54
55
    /* formerly known as */
56
    const ALIAS_TYPE_FKA = 'FKA';
57
58
    public function __construct($external_id)
59
    {
60
        $this->id_list = [];
61
        $this->aka_list = [];
62
        $this->address_list = [];
63
        $this->program_list = [];
64
        $this->address_list = [];
65
        $this->nationality_list = [];
66
        $this->citizenship_list = [];
67
        $this->date_of_birth_list = [];
68
        $this->place_of_birth_list = [];
69
        $this->update_at_list = [];
70
        $this->external_id = $external_id;
71
    }
72
73
    public function addAka(Aka $aka)
74
    {
75
        if (!$this->isEmpty($aka) && !in_array($aka, $this->aka_list)) {
76
            $this->aka_list[] = $aka;
77
        }
78
    }
79
80
    public function addId(Id $documentId)
81
    {
82
        if (!$this->isEmpty($documentId) && !in_array($documentId, $this->id_list)) {
83
            $this->id_list[] = $documentId;
84
        }
85
    }
86
87
    public function addNationality(Nationality $nationality)
88
    {
89
        if (!$this->isEmpty($nationality) && !in_array($nationality, $this->nationality_list)) {
90
            $this->nationality_list[] = $nationality;
91
        }
92
    }
93
94
    public function addCitizenship(Citizenship $citizenship)
95
    {
96
        if (!$this->isEmpty($citizenship) && !in_array($citizenship, $this->citizenship_list)) {
97
            $this->citizenship_list[] = $citizenship;
98
        }
99
    }
100
101
    public function addAddress(Address $address)
102
    {
103
        if (!$this->isEmpty($address) && !in_array($address, $this->address_list)) {
104
            $this->address_list[] = $address;
105
        }
106
    }
107
108
    public function addDateOfBirth(DateOfBirth $dob)
109
    {
110
        if (!$this->isEmpty($dob) && !in_array($dob, $this->date_of_birth_list)) {
111
            $this->date_of_birth_list[] = $dob;
112
        }
113
    }
114
115
    public function addPlaceOfBirth(PlaceOfBirth $pob)
116
    {
117
        if (!$this->isEmpty($pob) && !in_array($pob, $this->place_of_birth_list)) {
118
            $this->place_of_birth_list[] = $pob;
119
        }
120
    }
121
122
    public function addProgram(Program $program)
123
    {
124
        if (!$this->isEmpty($program) && !in_array($program, $this->program_list)) {
125
            $this->program_list[] = $program;
126
        }
127
    }
128
    public function addUpdateAt($date)
129
    {
130
        if ((bool) strtotime($date)) {
131
            $this->update_at_list[] = $date;
132
        }
133
    }
134
135
    public function isEmpty($obj)
136
    {
137
        foreach ($obj as $attribute => $value) {
138
            if ((is_string($value) && trim($value) !== '')) {
139
                return false;
140
            }
141
        }
142
143
        return true;
144
    }
145
146
    public function setter($attribute, $value)
147
    {
148
        if (property_exists($this, $attribute) && !empty($value)) {
149
            $this->$attribute = $value;
150
        }
151
    }
152
153
    public function setType($type)
154
    {
155
        $this->type = $type;
156
    }
157
}
158