Passed
Push — v2 ( 960327...58683d )
by Berend
03:11
created

Address::initAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 38
ccs 21
cts 21
cp 1
rs 9.472
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace miBadger\ActiveRecord\Traits;
4
5
use miBadger\ActiveRecord\ColumnProperty;
6
7
const TRAIT_ADDRESS_FIELD_ADDRESS = "address_address";
8
const TRAIT_ADDRESS_FIELD_ZIPCODE = "address_zipcode";
9
const TRAIT_ADDRESS_FIELD_CITY = "address_city";
10
const TRAIT_ADDRESS_FIELD_COUNTRY = "address_country";
11
12
trait Address
13
{
14
	/** @var string the address line */
15
	protected $address;
16
17
	/** @var string the zipcode */
18
	protected $zipcode;
19
20
	/** @var string the city */
21
	protected $city;
22
23
	/** @var string the country */
24
	protected $country;
25
26
	/**
27
	 * Registers the Address trait on the including class
28
	 * @return void
29
	 */
30 2
	protected function initAddress() 
31
	{
32 2
		$this->extendTableDefinition(TRAIT_ADDRESS_FIELD_ADDRESS, [
33 2
			'value' => &$this->address,
34
			'validate' => null,
35 2
			'type' => 'VARCHAR',
36 2
			'length' => 1024,
37
			'properties' => null
38
		]);
39
40 2
		$this->extendTableDefinition(TRAIT_ADDRESS_FIELD_ZIPCODE, [
41 2
			'value' => &$this->zipcode,
42
			'validate' => null,
43 2
			'type' => 'VARCHAR',
44 2
			'length' => 1024,
45
			'properties' => null
46
		]);
47
48 2
		$this->extendTableDefinition(TRAIT_ADDRESS_FIELD_CITY, [
49 2
			'value' => &$this->city,
50
			'validate' => null,
51 2
			'type' => 'VARCHAR',
52 2
			'length' => 1024,
53
			'properties' => null
54
		]);
55
56 2
		$this->extendTableDefinition(TRAIT_ADDRESS_FIELD_COUNTRY, [
57 2
			'value' => &$this->country,
58
			'validate' => null,
59 2
			'type' => 'VARCHAR',
60 2
			'length' => 1024,
61
			'properties' => null
62
		]);
63
64 2
		$this->address = null;
65 2
		$this->zipcode = null;
66 2
		$this->city = null;
67 2
		$this->country = null;
68 2
	}
69
70
	/**
71
	 * @return string
72
	 */
73 1
	public function getAddress()
74
	{
75 1
		return $this->address;
76
	}
77
	
78
	/**
79
	 * @param string $address
80
	 */
81 1
	public function setAddress($address)
82
	{
83 1
		$this->address = $address;
84 1
	}
85
86
	/**
87
	 * @return string
88
	 */
89 1
	public function getZipcode()
90
	{
91 1
		return $this->zipcode;
92
	}
93
	
94
	/**
95
	 * @param string $zipcode
96
	 */
97 1
	public function setZipcode($zipcode)
98
	{
99 1
		$this->zipcode = $zipcode;
100 1
	}
101
102
	/**
103
	 * @return string
104
	 */
105 1
	public function getCity()
106
	{
107 1
		return $this->city;
108
	}
109
	
110
	/**
111
	 * @param string $city
112
	 */
113 1
	public function setCity($city)
114
	{
115 1
		$this->city = $city;
116 1
	}
117
118
	/**
119
	 * @return string
120
	 */
121 1
	public function getCountry()
122
	{
123 1
		return $this->country;
124
	}
125
	
126
	/**
127
	 * @param string $country
128
	 */
129 1
	public function setCountry($country)
130
	{
131 1
		$this->country = $country;
132 1
	}
133
134
	/**
135
	 * @return void
136
	 */
137
	abstract protected function extendTableDefinition($columnName, $definition);
138
	
139
	/**
140
	 * @return void
141
	 */
142
	abstract protected function registerSearchHook($columnName, $fn);
143
144
	/**
145
	 * @return void
146
	 */
147
	abstract protected function registerDeleteHook($columnName, $fn);
148
149
	/**
150
	 * @return void
151
	 */
152
	abstract protected function registerUpdateHook($columnName, $fn);
153
154
	/**
155
	 * @return void
156
	 */
157
	abstract protected function registerReadHook($columnName, $fn);
158
159
	/**
160
	 * @return void
161
	 */
162
	abstract protected function registerCreateHook($columnName, $fn);
163
	
164
}