City   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 67
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A find() 0 18 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 City
26
 */
27
class City extends EntityAbstract
28
{
29
    /**
30
     * 7 znakowy identyfikator miejscowości
31
     *
32
     * @var string
33
     */
34
    public $id;
35
    /**
36
     * 7 znakowy identyfikator miejscowości nadrzędnej
37
     *
38
     * @var string
39
     */
40
    public $parentId;
41
    /**
42
     * Symbol rodzaju miejscowości
43
     *
44
     * @var string
45
     */
46
    public $rmId;
47
    /**
48
     * Nazwa rodzaju miejscowości
49
     *
50
     * @var string
51
     */
52
    public $rmName;
53
    /**
54
     * Nazwa miejscowości
55
     *
56
     * @var string
57
     */
58
    public $name;
59
    /**
60
     * Obiekt z danymi o gminie w której znajduje się miasto/miejscowość
61
     *
62
     * @var \mrcnpdlk\Teryt\Model\Commune
63
     */
64
    public $commune;
65
66
    /**
67
     * @param string $id
68
     *
69
     * @throws \mrcnpdlk\Teryt\Exception
70
     * @throws \mrcnpdlk\Teryt\Exception\Connection
71
     * @throws \mrcnpdlk\Teryt\Exception\InvalidArgument
72
     * @throws \mrcnpdlk\Teryt\Exception\NotFound
73
     *
74
     * @return \mrcnpdlk\Teryt\Model\City
75
     */
76 2
    public function find(string $id): City
77
    {
78 2
        $res = NativeApi::getInstance()->WyszukajMiejscowoscWRejestrze(null, $id);
79 1
        if (!empty($res) && 1 === count($res)) {
80 1
            $oCity          = $res[0];
81 1
            $this->id       = $id;
82 1
            $this->parentId = $oCity->cityParentId;
83 1
            $this->name     = $oCity->cityName;
84 1
            $this->rmId     = $oCity->rmId;
85 1
            $this->rmName   = $oCity->rmName;
86 1
            $this->commune  = (new Commune())->find((string)($oCity->tercId));
87
        }
88
89 1
        if (!$this->id) {
90
            throw new NotFound(sprintf('City [id:%s] not exists', $id));
91
        }
92
93 1
        return $this;
94
    }
95
}
96