Conditions | 10 |
Paths | 13 |
Total Lines | 67 |
Code Lines | 36 |
Lines | 24 |
Ratio | 35.82 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
101 | public function setCustom( |
||
102 | $startStandards, $startFees, $addStandards, $addFees, |
||
103 | $destProvince, $destCity = null, $destCountry = '中国' |
||
104 | ) { |
||
105 | if (empty($destProvince)) { |
||
106 | throw new ShopsException('$destProvince不允许为空'); |
||
107 | } |
||
108 | |||
109 | $this->custom = array(); |
||
110 | |||
111 | //todo 未做反选,排除一个城市,选择其他 |
||
112 | |||
113 | if (empty($destCity)) { |
||
114 | |||
115 | //todo $destProvince的判断 |
||
116 | //todo 加入 全国省直辖市的 简称等 |
||
117 | //todo 加入 某些不平等条约的存在 例如 江浙沪 ,你们懂得!! |
||
118 | |||
119 | $destProvince = is_string($destProvince) ? array($destProvince) : $destProvince; |
||
120 | |||
121 | $regional = new Regional(); |
||
122 | |||
123 | foreach ($destProvince as $province) { |
||
124 | $citys = $regional->getCity($province); |
||
125 | |||
126 | if (empty($citys)) { |
||
127 | throw new ShopsException('请传入合法的省份名!!!'); |
||
128 | } |
||
129 | |||
130 | View Code Duplication | foreach ($citys[0] as $city) { |
|
131 | $this->attributes['custom'][] = array( |
||
132 | 'StartStandards' => $startStandards, |
||
133 | 'StartFees' => $startFees, |
||
134 | 'AddStandards' => $addStandards, |
||
135 | 'AddFees' => $addFees, |
||
136 | 'DestCountry' => $destCountry, |
||
137 | 'DestProvince' => $province, |
||
138 | 'DestCity' => $city, |
||
139 | ); |
||
140 | } |
||
141 | } |
||
142 | |||
143 | return $this; |
||
144 | } else { |
||
145 | |||
146 | //todo 未做省份的检测 |
||
147 | //todo 未做市检测 |
||
148 | |||
149 | $destCity = is_string($destCity) ? array($destCity) : $destCity; |
||
150 | |||
151 | if (is_array($destCity)) { |
||
152 | View Code Duplication | foreach ($destCity as $city) { |
|
153 | $this->attributes['custom'][] = array( |
||
154 | 'StartStandards' => $startStandards, |
||
155 | 'StartFees' => $startFees, |
||
156 | 'AddStandards' => $addStandards, |
||
157 | 'AddFees' => $addFees, |
||
158 | 'DestCountry' => $destCountry, |
||
159 | 'DestProvince' => $destProvince, |
||
160 | 'DestCity' => $city, |
||
161 | ); |
||
162 | } |
||
163 | } |
||
164 | |||
165 | return $this; |
||
166 | } |
||
167 | } |
||
168 | |||
179 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.