| Conditions | 11 |
| Paths | 75 |
| Total Lines | 50 |
| 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 |
||
| 43 | public function init() |
||
| 44 | { |
||
| 45 | $this->iid = $this->collection->get('iid'); |
||
| 46 | $this->urn = new Urn($this->collection->get('type')); |
||
| 47 | |||
| 48 | if ($this->has('format')) { |
||
|
|
|||
| 49 | $format = $this->__get('format'); |
||
| 50 | if (!in_array($format, $this->formatMap)) { |
||
| 51 | throw new SpecificationErrorException('属性-》数据格式(format)的取值不在合法范围内'); |
||
| 52 | } |
||
| 53 | $this->format = $format; |
||
| 54 | } |
||
| 55 | |||
| 56 | if ($this->has('access')) { |
||
| 57 | $access = $this->__get('access'); |
||
| 58 | if (!empty($access)) { |
||
| 59 | foreach ($access as $item) { |
||
| 60 | if (!in_array($item, $this->accessMap)) { |
||
| 61 | throw new SpecificationErrorException('属性-》访问方式(access)的取值不在合法范围内'); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | $this->access = $access; |
||
| 65 | } else { |
||
| 66 | $this->access = []; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | if ($this->has('value-range')) { |
||
| 71 | $valueRange = $this->__get('value-range'); |
||
| 72 | $this->valueRange = $valueRange; |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($this->has('value-list')) { |
||
| 76 | $valueList = $this->__get('value-list'); |
||
| 77 | |||
| 78 | // TODO 当format为整型,可定义"value-list"的验证 |
||
| 79 | $this->valueList = $valueList; |
||
| 80 | } |
||
| 81 | |||
| 82 | if ($this->has('unit')) { |
||
| 83 | $unit = $this->__get('unit'); |
||
| 84 | if (!in_array($unit, $this->unitMap)) { |
||
| 85 | throw new SpecificationErrorException('属性-》单位(unit)的取值不在合法范围内'); |
||
| 86 | } |
||
| 87 | |||
| 88 | // TODO 当format为整型或浮点型,可定义unit值 的验证 |
||
| 89 | $this->unit = $unit; |
||
| 90 | } |
||
| 91 | |||
| 92 | $this->specification = new PropertySpecification($this->urn->getBaseUrn()); |
||
| 93 | } |
||
| 177 |