Completed
Push — master ( 8fae0f...b69ce8 )
by Taosikai
14:32
created

Address::getTye()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the Slince/China package.
4
 *
5
 * (c) Slince <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace China\Region\Location;
12
13
use Doctrine\Common\Collections\Collection;
14
15
abstract class Address implements AddressInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $code;
21
22
    /**
23
     * @var string
24
     */
25
    protected $name;
26
27
    /**
28
     * @var AddressInterface
29
     */
30
    protected $parent;
31
32
    /**
33
     * 子地区
34
     * @var AddressInterface[]|Collection
35
     */
36
    protected $children;
37
38
    public function __construct($code, $name, AddressInterface $parent = null)
39
    {
40
        $this->code = $code;
41
        $this->name = $name;
42
        $this->parent = $parent;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getName()
49
    {
50
        return $this->name;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getCode()
57
    {
58
        return $this->code;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function __toString()
65
    {
66
        return $this->getName();
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function setParent(AddressInterface $parent)
73
    {
74
        $this->parent = $parent;
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function getParent()
81
    {
82
        return $this->parent;
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function setChildren($children)
89
    {
90
        $this->children = $children;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function getChildren()
97
    {
98
        return $this->children;
99
    }
100
101
    /**
102
     * {@inheritdoc}
103
     */
104
    public function jsonSerialize()
105
    {
106
        return [
107
            'code' => $this->code,
108
            'name' => $this->name,
109
            'type' => static::getType(),
110
            'children' => $this->getChildren()
111
        ];
112
    }
113
114
    /**
115
     * 获取当前类类型
116
     * @return string
117
     */
118
    public static function getType()
119
    {
120
        return '';
121
    }
122
}