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

District::find()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4.0092

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 3
nop 1
dl 0
loc 17
ccs 11
cts 12
cp 0.9167
crap 4.0092
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 District
29
 *
30
 * @package mrcnpdlk\Teryt\Model
31
 */
32
class District extends EntityAbstract
33
{
34
    /**
35
     * 4 znakowy symbol powiatu
36
     * sklada sie z 2 cyfr województwa i 2 powiatu
37
     *
38
     * @var string
39
     */
40
    public $id;
41
    /**
42
     * Nazwa powiatu
43
     *
44
     * @var static
45
     */
46
    public $name;
47
    /**
48
     * Nazwa typu powiatu
49
     *
50
     * @var string
51
     */
52
    public $typeName;
53
    /**
54
     * Obiekt z informacjami o wojewodztwie
55
     *
56
     * @var \mrcnpdlk\Teryt\Model\Province
57
     */
58
    public $province;
59
60
    /**
61
     * District constructor.
62
     *
63
     * @param string $id 4-znakowy symbol powiatu
64
     *
65
     * @return $this
66
     * @throws NotFound
67
     */
68 1
    public function find(string $id)
69
    {
70 1
        $provinceId = substr($id, 0, 2);
71 1
        $districtId = substr($id, 2, 2);
72 1
        foreach (NativeApi::getInstance()->PobierzListePowiatow($provinceId) as $i) {
73 1
            if ($i->districtId === $districtId) {
74 1
                $this->id       = $id;
75 1
                $this->name     = $i->name;
0 ignored issues
show
Documentation Bug introduced by
It seems like $i->name of type string is incompatible with the declared type mrcnpdlk\Teryt\Model\District 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...
76 1
                $this->typeName = $i->typeName;
77
            }
78
        }
79 1
        if (!$this->id) {
80
            throw new NotFound(sprintf('District [id:%s] not exists', $id));
81
        }
82 1
        $this->province = (new Province())->find($provinceId);
83
84 1
        return $this;
85
    }
86
87
}
88