1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MOJEPANSTWO-API |
4
|
|
|
* |
5
|
|
|
* Copyright © 2017 pudelek.org.pl |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view source file |
10
|
|
|
* that is bundled with this package in the file LICENSE |
11
|
|
|
* |
12
|
|
|
* @author Marcin Pudełek <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare (strict_types=1); |
16
|
|
|
|
17
|
|
|
namespace mrcnpdlk\MojePanstwo\Model\Address; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
use mrcnpdlk\MojePanstwo\Api; |
21
|
|
|
|
22
|
|
|
class Nts |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
public $region_id; |
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
public $podregion_id; |
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
public $teryt_wojewodztwo_id; |
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
public $teryt_powiat_id; |
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
public $teryt_gmina_id; |
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
public $teryt_gmina_typ_id; |
48
|
|
|
/** |
49
|
|
|
* @var int |
50
|
|
|
*/ |
51
|
|
|
public $teryt_terc_id; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Nts constructor. |
55
|
|
|
* |
56
|
|
|
* @param string|null $nts |
57
|
|
|
* |
58
|
|
|
* @throws \mrcnpdlk\MojePanstwo\Exception |
59
|
|
|
*/ |
60
|
5 |
|
public function __construct(string $nts = null) |
61
|
|
|
{ |
62
|
5 |
|
if (null === $nts || \strlen($nts) < 10) { |
63
|
|
|
Api::getInstance() |
64
|
|
|
->getClient() |
65
|
|
|
->getLogger() |
66
|
|
|
->warning(sprintf('Invalid value of NTS code [%s]', $nts)) |
67
|
|
|
; |
68
|
|
|
} else { |
69
|
|
|
/** @noinspection SubStrUsedAsArrayAccessInspection */ |
70
|
5 |
|
$this->teryt_gmina_typ_id = substr($nts, -1, 1); |
71
|
5 |
|
$this->teryt_gmina_id = substr($nts, -3, 2); |
72
|
5 |
|
$this->teryt_powiat_id = substr($nts, -5, 2); |
73
|
5 |
|
$this->podregion_id = substr($nts, -7, 2); |
74
|
5 |
|
$this->teryt_wojewodztwo_id = substr($nts, -9, 2); |
75
|
|
|
/** @noinspection SubStrUsedAsArrayAccessInspection */ |
76
|
5 |
|
$this->region_id = substr($nts, -10, 1); |
77
|
5 |
|
if ($this->teryt_powiat_id === '00') { |
78
|
|
|
$this->teryt_powiat_id = null; |
79
|
|
|
} |
80
|
5 |
|
if ($this->teryt_gmina_id === '00') { |
81
|
1 |
|
$this->teryt_gmina_id = null; |
82
|
|
|
} |
83
|
5 |
|
if ($this->teryt_gmina_typ_id === '0') { |
84
|
1 |
|
$this->teryt_gmina_typ_id = null; |
85
|
|
|
} |
86
|
5 |
|
if ($this->teryt_powiat_id && $this->teryt_gmina_id) { |
|
|
|
|
87
|
4 |
|
$this->teryt_terc_id = (int)($this->teryt_wojewodztwo_id . $this->teryt_powiat_id . $this->teryt_gmina_id . $this->teryt_gmina_typ_id); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
5 |
|
} |
93
|
|
|
} |
94
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: