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

DataProvider   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 24
lcom 1
cbo 1
dl 0
loc 138
rs 10
c 0
b 0
f 0

19 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 2
A setCity() 0 5 1
A setCompany() 0 5 1
A setCourt() 0 5 1
A setCreated() 0 5 1
A setFileNumber() 0 5 1
A setIN() 0 5 1
A setIsPerson() 0 5 1
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 7 1
A setZip() 0 5 1
A toNull() 0 8 2
1
<?php
2
3
namespace h4kuna\Ares;
4
5
use DateTime,
6
	DateTimeZone;
7
8
/**
9
 * @author Milan Matějček
10
 */
11
class DataProvider
12
{
13
14
	/** @var IDataFactory */
15
	private $dataFactory;
16
17
	/** @var array */
18
	private $data = [];
19
20
	public function __construct(IDataFactory $dataFactory)
21
	{
22
		$this->dataFactory = $dataFactory;
23
	}
24
25
	/** @return Data */
26
	public function getData()
27
	{
28
		if (is_array($this->data)) {
29
			$this->setFileNumberAndCourt();
30
			$this->data = $this->dataFactory->create($this->data);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dataFactory->create($this->data) of type object<h4kuna\Ares\Data> is incompatible with the declared type array of property $data.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
31
		}
32
		return $this->data;
33
	}
34
35
	public function prepareData()
36
	{
37
		$this->data = [];
38
		return $this;
39
	}
40
41
	/**
42
	 * @param string $active
43
	 * @return self
44
	 */
45
	public function setActive($active)
46
	{
47
		$this->data['active'] = is_bool($active) ? $active : (((string) $active) == 'Aktivní'); // ==
48
		return $this;
49
	}
50
51
	public function setCity($city)
52
	{
53
		$this->data['city'] = self::toNull($city);
54
		return $this;
55
	}
56
57
	public function setCompany($company)
58
	{
59
		$this->data['company'] = self::toNull($company);
60
		return $this;
61
	}
62
63
	public function setCourt($court)
64
	{
65
		$this->data['court'] = self::toNull($court);
66
		return $this;
67
	}
68
69
	public function setCreated($date)
70
	{
71
		$this->data['created'] = new DateTime((string) $date, new DateTimeZone('Europe/Prague'));
72
		return $this;
73
	}
74
75
	public function setFileNumber($fileNumber)
76
	{
77
		$this->data['file_number'] = self::toNull($fileNumber);
78
		return $this;
79
	}
80
81
	public function setIN($in)
82
	{
83
		$this->data['in'] = self::toNull($in);
84
		return $this;
85
	}
86
87
	public function setIsPerson($s)
88
	{
89
		$this->data['is_person'] = ((string) $s) <= '108';
90
		return $this;
91
	}
92
93
	private function setFileNumberAndCourt()
94
	{
95
		$this->data['court_all'] = NULL;
96
		if ($this->data['file_number'] && $this->data['court']) {
97
			$this->data['court_all'] = $this->data['file_number'] . ', ' . $this->data['court'];
98
		}
99
	}
100
101
	public function setCityDistrict($district)
102
	{
103
		$this->data['city_district'] = self::toNull($district);
104
		return $this;
105
	}
106
107
	public function setCityPost($district)
108
	{
109
		$this->data['city_post'] = self::toNull($district);
110
		return $this;
111
	}
112
113
	public function setStreet($street)
114
	{
115
		$this->data['street'] = self::toNull($street);
116
		return $this;
117
	}
118
119
	public function setHouseNumber($cd, $co)
120
	{
121
		$this->data['house_number'] = self::toNull(trim($cd . '/' . $co, '/'));
122
		return $this;
123
	}
124
125
	public function setTIN($s)
126
	{
127
		$tin = strval($s);
128
		$this->data['tin'] = self::toNull($tin);
129
		$this->data['vat_payer'] = (bool) $tin;
130
		return $this;
131
	}
132
133
	public function setZip($zip)
134
	{
135
		$this->data['zip'] = self::toNull($zip);
136
		return $this;
137
	}
138
139
	private static function toNull($v)
140
	{
141
		$string = trim((string) $v);
142
		if ($string === '') {
143
			return NULL;
144
		}
145
		return $string;
146
	}
147
148
}
149