District   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 56
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A find() 0 17 4
1
<?php
2
/**
3
 * TERYT-API
4
 *
5
 * Copyright (c) 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
 * @author  Marcin Pudełek <[email protected]>
12
 */
13
14
/**
15
 * Created by Marcin Pudełek <[email protected]>
16
 * Date: 07.09.2017
17
 */
18
19
namespace mrcnpdlk\Teryt\Model;
20
21
use mrcnpdlk\Teryt\Exception\NotFound;
22
use mrcnpdlk\Teryt\NativeApi;
23
24
/**
25
 * Class District
26
 */
27
class District extends EntityAbstract
28
{
29
    /**
30
     * 4 znakowy symbol powiatu
31
     * sklada sie z 2 cyfr województwa i 2 powiatu
32
     *
33
     * @var string
34
     */
35
    public $id;
36
    /**
37
     * Nazwa powiatu
38
     *
39
     * @var string
40
     */
41
    public $name;
42
    /**
43
     * Nazwa typu powiatu
44
     *
45
     * @var string
46
     */
47
    public $typeName;
48
    /**
49
     * Obiekt z informacjami o wojewodztwie
50
     *
51
     * @var \mrcnpdlk\Teryt\Model\Province
52
     */
53
    public $province;
54
55
    /**
56
     * District constructor.
57
     *
58
     * @param string $id 4-znakowy symbol powiatu
59
     *
60
     * @throws \mrcnpdlk\Teryt\Exception\Connection
61
     * @throws \mrcnpdlk\Teryt\Exception
62
     * @throws NotFound
63
     *
64
     * @return $this
65
     */
66 1
    public function find(string $id)
67
    {
68 1
        $provinceId = substr($id, 0, 2);
69 1
        $districtId = substr($id, 2, 2);
70 1
        foreach (NativeApi::getInstance()->PobierzListePowiatow($provinceId) as $i) {
71 1
            if ($i->districtId === $districtId) {
72 1
                $this->id       = $id;
73 1
                $this->name     = $i->name;
74 1
                $this->typeName = $i->typeName;
75
            }
76
        }
77 1
        if (!$this->id) {
78
            throw new NotFound(sprintf('District [id:%s] not exists', $id));
79
        }
80 1
        $this->province = (new Province())->find($provinceId);
81
82 1
        return $this;
83
    }
84
}
85