Completed
Push — master ( 4f911a...20d659 )
by Milan
06:11
created

Data::setFileNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace h4kuna\Ares;
4
5
use h4kuna\DataType\Immutable;
6
7
/**
8
 * @author Milan Matějček
9
 * @property-read bool $active
10
 * @property-read string $city
11
 * @property-read string $city_district
12
 * @property-read string $city_post
13
 * @property-read string $company
14
 * @property-read string $court
15
 * @property-read string $court_all
16
 * @property-read \DateTime $created
17
 * @property-read string $file_number
18
 * @property-read string $in
19
 * @property-read bool $is_person
20
 * @property-read string $house_number
21
 * @property-read string $street
22
 * @property-read string $tin
23
 * @property-read string $vat_payer
24
 * @property-read string $zip
25
 */
26
class Data extends Immutable\Messenger
27
{
28
29
	/**
30
	 * Copy data
31
	 * @param array $map
32
	 * @return array
33
	 */
34
	public function toArray(array $map = [])
35
	{
36
		if ($map === []) {
37
			return $this->getData();
38
		}
39
		$out = [];
40
		foreach ($map as $k => $v) {
41
			if ($this->offsetExists($k)) {
42
				if (!$v) {
43
					$v = $k;
44
				}
45
				$out[$v] = $this[$k];
46
			}
47
		}
48
		return $out;
49
	}
50
51
	public function jsonSerialize()
52
	{
53
		$data = $this->getData();
54
		if ($this->created instanceof \DateTime) {
55
			$data['created'] = $this->created->format(\DateTime::ISO8601);
56
		}
57
		return $data;
58
	}
59
60
	public function __toString()
61
	{
62
		return json_encode($this->jsonSerialize());
63
	}
64
}
65