Conditions | 13 |
Paths | 23 |
Total Lines | 50 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 10 | ||
Bugs | 2 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
60 | private function _getAddress($addressCode, $birthdayCode, $strictMode = false) |
||
61 | { |
||
62 | $address = ''; |
||
63 | if (isset($this->_addressCodeTimeline[$addressCode])) { |
||
64 | $timeline = $this->_addressCodeTimeline[$addressCode]; |
||
65 | $year = substr($birthdayCode, 0, 4); |
||
66 | // 严格模式下,会检查【地址码正式启用的年份】与【身份证上的出生年份】 |
||
67 | foreach ($timeline as $val) { |
||
68 | $start_year = $val['start_year'] != '' ? $val['start_year'] : '0001'; |
||
69 | $end_year = $val['end_year'] != '' ? $val['end_year'] : '9999'; |
||
70 | if ($year >= $start_year and $year <= $end_year) { |
||
71 | $address = $val['address']; |
||
72 | } |
||
73 | } |
||
74 | |||
75 | // 非严格模式下,则不会检查【地址码正式启用的年份】与【身份证上的出生年份】的关系 |
||
76 | if (empty($address) and !$strictMode) { |
||
77 | // 由于较晚申请户口或身份证等原因,导致会出现地址码正式启用于2000年,但实际1999年出生的新生儿,由于晚了一年报户口,导致身份证上的出生年份早于地址码正式启用的年份 |
||
78 | // 由于某些地区的地址码已经废弃,但是实际上在之后的几年依然在使用 |
||
79 | // 这里就不做时间判断了 |
||
80 | return array_pop($timeline)['address']; |
||
81 | } |
||
82 | |||
83 | return $address; |
||
84 | } |
||
85 | |||
86 | // 修复 \d\d\d\d01、\d\d\d\d02、\d\d\d\d11 和 \d\d\d\d20 的历史遗留问题 |
||
87 | // 以上四种地址码,现实身份证真实存在,但民政部历年公布的官方地址码中可能没有查询到 |
||
88 | // 如:440401 450111 等 |
||
89 | // 所以这里需要特殊处理 |
||
90 | // 1980年、1982年版本中,未有制定省辖市市辖区的代码,所有带县的省辖市给予“××××20”的“市区”代码。 |
||
91 | // 1984年版本开始对地级市(前称省辖市)市辖区制定代码,其中“××××01”表示市辖区的汇总码,同时撤销“××××20”的“市区”代码(追溯至1983年)。 |
||
92 | // 1984年版本的市辖区代码分为城区和郊区两类,城区由“××××02”开始排起,郊区由“××××11”开始排起,后来版本已不再采用此方式,已制定的代码继续沿用。 |
||
93 | $suffixes = substr($addressCode, 4, 2); |
||
94 | switch ($suffixes) { |
||
95 | case '20': |
||
96 | $address = '市区'; |
||
97 | break; |
||
98 | case '01': |
||
99 | $address = '市辖区'; |
||
100 | break; |
||
101 | case '02': |
||
102 | $address = '城区'; |
||
103 | break; |
||
104 | case '11': |
||
105 | $address = '郊区'; |
||
106 | break; |
||
107 | } |
||
108 | |||
109 | return $address; |
||
110 | } |
||
154 |