Address   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 110
rs 10
c 1
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getName() 0 4 1
A getCode() 0 4 1
A __toString() 0 4 1
A setParent() 0 4 1
A getParent() 0 4 1
A setChildren() 0 4 1
A getChildren() 0 4 1
A jsonSerialize() 0 9 1
A getType() 0 4 1
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
     *
35
     * @var AddressInterface[]|Collection
36
     */
37
    protected $children;
38
39
    public function __construct($code, $name, AddressInterface $parent = null)
40
    {
41
        $this->code = $code;
42
        $this->name = $name;
43
        $this->parent = $parent;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getName()
50
    {
51
        return $this->name;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function getCode()
58
    {
59
        return $this->code;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function __toString()
66
    {
67
        return $this->getName();
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function setParent(AddressInterface $parent)
74
    {
75
        $this->parent = $parent;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function getParent()
82
    {
83
        return $this->parent;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function setChildren($children)
90
    {
91
        $this->children = $children;
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function getChildren()
98
    {
99
        return $this->children;
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function jsonSerialize()
106
    {
107
        return [
108
            'code' => $this->code,
109
            'name' => $this->name,
110
            'type' => static::getType(),
111
            'children' => $this->getChildren(),
112
        ];
113
    }
114
115
    /**
116
     * 获取当前类类型.
117
     *
118
     * @return string
119
     */
120
    public static function getType()
121
    {
122
        return '';
123
    }
124
}