Completed
Push — master ( 74d8cf...88d0d9 )
by Marcin
02:58
created

City::find()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4.0072

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 2
nop 1
dl 0
loc 18
ccs 12
cts 13
cp 0.9231
crap 4.0072
rs 9.2
c 0
b 0
f 0
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
 *
12
 * @author  Marcin Pudełek <[email protected]>
13
 *
14
 */
15
16
/**
17
 * Created by Marcin Pudełek <[email protected]>
18
 * Date: 07.09.2017
19
 */
20
21
namespace mrcnpdlk\Teryt\Model;
22
23
24
use mrcnpdlk\Teryt\Exception\NotFound;
25
use mrcnpdlk\Teryt\NativeApi;
26
27
/**
28
 * Class City
29
 *
30
 * @package mrcnpdlk\Teryt\Model
31
 */
32
class City extends EntityAbstract
33
{
34
    /**
35
     * 7 znakowy identyfikator miejscowości
36
     *
37
     * @var string
38
     */
39
    public $id;
40
    /**
41
     * 7 znakowy identyfikator miejscowości nadrzędnej
42
     *
43
     * @var string
44
     */
45
    public $parentId;
46
    /**
47
     * Symbol rodzaju miejscowości
48
     *
49
     * @var string
50
     */
51
    public $rmId;
52
    /**
53
     * Nazwa rodzaju miejscowości
54
     *
55
     * @var string
56
     */
57
    public $rmName;
58
    /**
59
     * Nazwa miejscowości
60
     *
61
     * @var static
62
     */
63
    public $name;
64
    /**
65
     * Obiekt z danymi o gminie w której znajduje się miasto/miejscowość
66
     *
67
     * @var \mrcnpdlk\Teryt\Model\Commune
68
     */
69
    public $commune;
70
71
72
    /**
73
     * @param string $id
74
     *
75
     * @return \mrcnpdlk\Teryt\Model\City
76
     * @throws NotFound
77
     */
78 2
    public function find(string $id)
79
    {
80 2
        $res = NativeApi::getInstance()->WyszukajMiejscowoscWRejestrze(null, $id);
81 1
        if (!empty($res) && count($res) === 1) {
82 1
            $oCity          = $res[0];
83 1
            $this->id       = $id;
84 1
            $this->parentId = $oCity->cityParentId;
85 1
            $this->name     = $oCity->cityName;
0 ignored issues
show
Documentation Bug introduced by
It seems like $oCity->cityName of type string is incompatible with the declared type mrcnpdlk\Teryt\Model\City of property $name.

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...
86 1
            $this->rmId     = $oCity->rmId;
87 1
            $this->rmName   = $oCity->rmName;
88 1
            $this->commune  = (new Commune())->find($oCity->tercId);
89
        }
90
91 1
        if (!$this->id) {
92
            throw new NotFound(sprintf('City [id:%s] not exists', $id));
93
        }
94
95 1
        return $this;
96
    }
97
}
98