Completed
Push — master ( 88d0d9...a53fa0 )
by Marcin
02:57
created

JednostkaTerytorialna::__construct()   C

Complexity

Conditions 7
Paths 8

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 7.0671

Importance

Changes 0
Metric Value
cc 7
eloc 18
nc 8
nop 1
dl 0
loc 25
ccs 16
cts 18
cp 0.8889
crap 7.0671
rs 6.7272
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: 06.09.2017
19
 */
20
21
namespace mrcnpdlk\Teryt\ResponseModel\Territory;
22
23
/**
24
 * Class JednostkaTerytorialna
25
 *
26
 * @package mrcnpdlk\Teryt\ResponseModel\Territory
27
 */
28
class JednostkaTerytorialna extends AbstractResponseModel
29
{
30
    /**
31
     * Nazwa jednostki
32
     *
33
     * @var string
34
     */
35
    public $name;
36
    /**
37
     * Typ jednostki podziału terytorialnego
38
     *
39
     * @var string
40
     */
41
    public $typeName;
42
43
    /**
44
     * JednostkaTerytorialna constructor.
45
     *
46
     * @param \stdClass $oData Obiekt zwrócony z TerytWS1
47
     */
48 3
    public function __construct(\stdClass $oData)
49
    {
50 3
        $this->provinceId    = $oData->WOJ;
51 3
        $this->districtId    = $oData->POW;
52 3
        $this->communeId     = $oData->GMI;
53 3
        $this->communeTypeId = $oData->RODZ;
54 3
        $this->name          = $oData->NAZWA;
55 3
        $this->typeName      = $oData->NAZWA_DOD;
56 3
        $this->statusDate    = $oData->STAN_NA;
57
58
        try {
59 3
            $this->statusDate = $oData->STAN_NA ? (new \DateTime($oData->STAN_NA))->format('Y-m-d') : null;
60
        } catch (\Exception $e) {
61
            $this->statusDate = null;
62
        }
63
64 3
        if ($this->provinceId && $this->districtId && $this->communeId && $this->communeTypeId) {
65 1
            $this->tercId = intval(sprintf("%s%s%s%s",
66 1
                $this->provinceId,
67 1
                $this->districtId,
68 1
                $this->communeId,
69 1
                $this->communeTypeId));
70
        }
71
72 3
        parent::__construct();
73 3
    }
74
}
75