Conditions | 10 |
Paths | 13 |
Total Lines | 75 |
Code Lines | 34 |
Lines | 24 |
Ratio | 32 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
93 | public function setCustom( |
||
94 | $startStandards, $startFees, $addStandards, $addFees, |
||
95 | $destProvince, $destCity = null,$destCountry = '中国' |
||
96 | ) |
||
97 | { |
||
98 | |||
99 | if (empty($destProvince)) throw new ShopsException('$destProvince不允许为空'); |
||
100 | |||
101 | $this->custom = array(); |
||
102 | |||
103 | //todo 未做反选,排除一个城市,选择其他 |
||
104 | |||
105 | if (empty($destCity)) { |
||
106 | |||
107 | //todo $destProvince的判断 |
||
108 | //todo 加入 全国省直辖市的 简称等 |
||
109 | //todo 加入 某些不平等条约的存在 例如 江浙沪 ,你们懂得!! |
||
110 | |||
111 | |||
112 | |||
113 | $destProvince = is_string($destProvince) ? array($destProvince) : $destProvince; |
||
114 | |||
115 | $regional = new Regional(); |
||
116 | |||
117 | foreach ($destProvince as $province) { |
||
118 | |||
119 | |||
120 | $citys = $regional->getCity($province); |
||
121 | |||
122 | if (empty($citys)) throw new ShopsException('请传入合法的省份名!!!'); |
||
123 | |||
124 | View Code Duplication | foreach ($citys[0] as $city) { |
|
125 | $this->attributes['custom'][] = array( |
||
126 | 'StartStandards' => $startStandards, |
||
127 | 'StartFees' => $startFees, |
||
128 | 'AddStandards' => $addStandards, |
||
129 | 'AddFees' => $addFees, |
||
130 | 'DestCountry' => $destCountry, |
||
131 | 'DestProvince' => $province, |
||
132 | 'DestCity' => $city |
||
133 | ); |
||
134 | } |
||
135 | |||
136 | } |
||
137 | |||
138 | return $this; |
||
139 | |||
140 | } else { |
||
141 | |||
142 | //todo 未做省份的检测 |
||
143 | //todo 未做市检测 |
||
144 | |||
145 | $destCity = is_string($destCity) ? array($destCity) : $destCity; |
||
146 | |||
147 | if (is_array($destCity)) { |
||
148 | View Code Duplication | foreach ($destCity as $city) { |
|
149 | |||
150 | $this->attributes['custom'][] = array( |
||
151 | 'StartStandards' => $startStandards, |
||
152 | 'StartFees' => $startFees, |
||
153 | 'AddStandards' => $addStandards, |
||
154 | 'AddFees' => $addFees, |
||
155 | 'DestCountry' => $destCountry, |
||
156 | 'DestProvince' => $destProvince, |
||
157 | 'DestCity' => $city |
||
158 | ); |
||
159 | |||
160 | } |
||
161 | } |
||
162 | |||
163 | |||
164 | return $this; |
||
165 | |||
166 | } |
||
167 | } |
||
168 | |||
178 | } |
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.