| Conditions | 11 |
| Paths | 75 |
| Total Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 127 | public function init() |
||
| 128 | { |
||
| 129 | parent::init(); |
||
| 130 | |||
| 131 | if ($this->has('format')) { |
||
|
|
|||
| 132 | $format = $this->__get('format'); |
||
| 133 | if (!in_array($format, $this->formatMap)) { |
||
| 134 | throw new SpecificationErrorException('属性-》数据格式(format)的取值不在合法范围内'); |
||
| 135 | } |
||
| 136 | $this->format = $format; |
||
| 137 | } |
||
| 138 | |||
| 139 | if ($this->has('access')) { |
||
| 140 | $access = $this->__get('access'); |
||
| 141 | if (!empty($access)) { |
||
| 142 | foreach ($access as $item) { |
||
| 143 | if (!in_array($item, $this->accessMap)) { |
||
| 144 | throw new SpecificationErrorException('属性-》访问方式(access)的取值不在合法范围内'); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | $this->access = $access; |
||
| 148 | } else { |
||
| 149 | $this->access = []; |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | if ($this->has('value-range')) { |
||
| 154 | $valueRange = $this->__get('value-range'); |
||
| 155 | $this->valueRange = $valueRange; |
||
| 156 | } |
||
| 157 | |||
| 158 | if ($this->has('value-list')) { |
||
| 159 | $valueList = $this->__get('value-list'); |
||
| 160 | |||
| 161 | // TODO 当format为整型,可定义"value-list"的验证 |
||
| 162 | $this->valueList = $valueList; |
||
| 163 | } |
||
| 164 | |||
| 165 | if ($this->has('unit')) { |
||
| 166 | $unit = $this->__get('unit'); |
||
| 167 | if (!in_array($unit, $this->unitMap)) { |
||
| 168 | throw new SpecificationErrorException('属性-》单位(unit)的取值不在合法范围内'); |
||
| 169 | } |
||
| 170 | |||
| 171 | // TODO 当format为整型或浮点型,可定义unit值 的验证 |
||
| 172 | $this->unit = $unit; |
||
| 173 | } |
||
| 216 |