Completed
Pull Request — master (#15)
by
unknown
05:40
created

DataProvider   A

Complexity

Total Complexity 27

Size/Duplication

Total Lines 169
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 27
lcom 1
cbo 1
dl 0
loc 169
rs 10
c 0
b 0
f 0

21 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getData() 0 8 2
A prepareData() 0 5 1
A setActive() 0 5 1
A setCity() 0 5 1
A setCompany() 0 5 1
A setCourt() 0 5 1
A setCreated() 0 5 1
A setDissolved() 0 5 1
A setFileNumber() 0 5 1
A setIN() 0 5 1
A setIsPerson() 0 6 3
A setFileNumberAndCourt() 0 7 3
A setCityDistrict() 0 5 1
A setCityPost() 0 5 1
A setStreet() 0 5 1
A setHouseNumber() 0 5 1
A setTIN() 0 6 1
A setZip() 0 5 1
A setNace() 0 5 1
A toNull() 0 8 2
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()
38
	{
39
		$this->data = [];
40
		return $this;
41
	}
42
43
44
	public function setActive(bool $active)
45
	{
46
		$this->data['active'] = $active;
47
		return $this;
48
	}
49
50
51
	public function setCity(string $city)
52
	{
53
		$this->data['city'] = self::toNull($city);
54
		return $this;
55
	}
56
57
58
	public function setCompany(string $company)
59
	{
60
		$this->data['company'] = self::toNull($company);
61
		return $this;
62
	}
63
64
65
	public function setCourt(string $court)
66
	{
67
		$this->data['court'] = self::toNull($court);
68
		return $this;
69
	}
70
71
72
	public function setCreated(string $date)
73
	{
74
		$this->data['created'] = new DateTime($date, new DateTimeZone('Europe/Prague'));
75
		return $this;
76
	}
77
	
78
	
79
    	public function setDissolved(string $date)
80
    	{
81
		$this->data['dissolved'] = new DateTime($date, new DateTimeZone('Europe/Prague'));
82
		return $this;
83
    	}
84
85
86
	public function setFileNumber(string $fileNumber)
87
	{
88
		$this->data['file_number'] = self::toNull($fileNumber);
89
		return $this;
90
	}
91
92
93
	public function setIN(string $in)
94
	{
95
		$this->data['in'] = self::toNull($in);
96
		return $this;
97
	}
98
99
100
	public function setIsPerson(string $s)
101
	{
102
		$this->data['is_person'] = $s <= '108' || $s === '424' || $s === '425';
103
		$this->data['legal_form_code'] = (int) $s;
104
		return $this;
105
	}
106
107
108
	private function setFileNumberAndCourt(): void
109
	{
110
		$this->data['court_all'] = null;
111
		if ($this->data['file_number'] && $this->data['court']) {
112
			$this->data['court_all'] = $this->data['file_number'] . ', ' . $this->data['court'];
113
		}
114
	}
115
116
117
	public function setCityDistrict(string $district)
118
	{
119
		$this->data['city_district'] = self::toNull($district);
120
		return $this;
121
	}
122
123
124
	public function setCityPost(string $district)
125
	{
126
		$this->data['city_post'] = self::toNull($district);
127
		return $this;
128
	}
129
130
131
	public function setStreet(string $street)
132
	{
133
		$this->data['street'] = self::toNull($street);
134
		return $this;
135
	}
136
137
138
	public function setHouseNumber(string $cd, string $co)
139
	{
140
		$this->data['house_number'] = self::toNull(trim($cd . '/' . $co, '/'));
141
		return $this;
142
	}
143
144
145
	public function setTIN(string $s)
146
	{
147
		$this->data['tin'] = self::toNull($s);
148
		$this->data['vat_payer'] = (bool) $s;
149
		return $this;
150
	}
151
152
153
	public function setZip(string $zip)
154
	{
155
		$this->data['zip'] = self::toNull($zip);
156
		return $this;
157
	}
158
159
160
	public function setNace(array $nace)
161
	{
162
		$this->data['nace'] = $nace;
163
		return $this;
164
	}
165
166
167
	private static function toNull(string $v): ?string
168
	{
169
		$string = trim($v);
170
		if ($string === '') {
171
			return null;
172
		}
173
		return $string;
174
	}
175
176
}
177