Completed
Pull Request — master (#10)
by
unknown
02:01
created

DataProvider::setNace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace h4kuna\Ares;
4
5
use DateTime;
6
use DateTimeZone;
7
8
class DataProvider
9
{
10
11
	/** @var IFactory */
12
	private $factory;
13
14
	/** @var array */
15
	private $data;
16
17
	/** @var Data */
18
	private $dataMessenger;
19
20
21
	public function __construct(IFactory $dataFactory)
22
	{
23
		$this->factory = $dataFactory;
24
	}
25
26
27
	public function getData(): Data
28
	{
29
		if (is_array($this->data)) {
30
			$this->setFileNumberAndCourt();
31
			$this->dataMessenger = $this->factory->createData($this->data);
32
		}
33
		return $this->dataMessenger;
34
	}
35
36
37
	public function prepareData(): self
38
	{
39
		$this->data = [];
40
		return $this;
41
	}
42
43
44
	/**
45
	 * @param string|bool $active
46
	 * @return static
47
	 */
48
	public function setActive($active): self
49
	{
50
		$this->data['active'] = is_bool($active) ? $active : ($active === 'Aktivní');
51
		return $this;
52
	}
53
54
55
	public function setCity(string $city): self
56
	{
57
		$this->data['city'] = self::toNull($city);
58
		return $this;
59
	}
60
61
62
	public function setCompany(string $company): self
63
	{
64
		$this->data['company'] = self::toNull($company);
65
		return $this;
66
	}
67
68
69
	public function setCourt(string $court): self
70
	{
71
		$this->data['court'] = self::toNull($court);
72
		return $this;
73
	}
74
75
76
	public function setCreated(string $date): self
77
	{
78
		$this->data['created'] = new DateTime($date, new DateTimeZone('Europe/Prague'));
79
		return $this;
80
	}
81
82
83
	public function setFileNumber(string $fileNumber): self
84
	{
85
		$this->data['file_number'] = self::toNull($fileNumber);
86
		return $this;
87
	}
88
89
90
	public function setIN(string $in): self
91
	{
92
		$this->data['in'] = self::toNull($in);
93
		return $this;
94
	}
95
96
97
	public function setIsPerson(string $s): self
98
	{
99
		$this->data['is_person'] = $s <= '108';
100
		return $this;
101
	}
102
103
104
	private function setFileNumberAndCourt(): void
105
	{
106
		$this->data['court_all'] = null;
107
		if ($this->data['file_number'] && $this->data['court']) {
108
			$this->data['court_all'] = $this->data['file_number'] . ', ' . $this->data['court'];
109
		}
110
	}
111
112
113
	public function setCityDistrict(string $district): self
114
	{
115
		$this->data['city_district'] = self::toNull($district);
116
		return $this;
117
	}
118
119
120
	public function setCityPost(string $district): self
121
	{
122
		$this->data['city_post'] = self::toNull($district);
123
		return $this;
124
	}
125
126
127
	public function setStreet(string $street): self
128
	{
129
		$this->data['street'] = self::toNull($street);
130
		return $this;
131
	}
132
133
134
	public function setHouseNumber(string $cd, string $co): self
135
	{
136
		$this->data['house_number'] = self::toNull(trim($cd . '/' . $co, '/'));
137
		return $this;
138
	}
139
140
141
	public function setTIN(string $s): self
142
	{
143
		$this->data['tin'] = self::toNull($s);
144
		$this->data['vat_payer'] = (bool) $s;
145
		return $this;
146
	}
147
148
149
	public function setZip(string $zip): self
150
	{
151
		$this->data['zip'] = self::toNull($zip);
152
		return $this;
153
	}
154
	
155
	public function setNace(array $nace): self
156
	{
157
		$this->data['nace'] = $nace;
158
		return $this;
159
	}
160
161
162
	private static function toNull(string $v): ?string
163
	{
164
		$string = trim($v);
165
		if ($string === '') {
166
			return null;
167
		}
168
		return $string;
169
	}
170
171
}
172