Conditions | 12 |
Paths | 14 |
Total Lines | 34 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
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 |
||
89 | protected function readScalar() { |
||
90 | switch ($name = $this->reader->localName) { |
||
91 | case 'array': |
||
92 | $depth = $this->reader->depth; |
||
93 | $array = array(); |
||
94 | while (true) { |
||
95 | $node = $this->read($depth, false, $nodeFound); |
||
96 | if (!$nodeFound) { |
||
97 | break; |
||
98 | } |
||
99 | $array[] = $node; |
||
100 | } |
||
101 | return $array; |
||
102 | case 'string': |
||
103 | return $this->reader->readString(); |
||
104 | case 'int': |
||
105 | return $this->parseInt($this->reader->readString()); |
||
106 | case 'float': |
||
107 | $text = $this->reader->readString(); |
||
108 | if (false === $float = filter_var($text, FILTER_VALIDATE_FLOAT)) { |
||
109 | throw new DomainException(sprintf('"%s" is not a valid float', $text)); |
||
110 | } |
||
111 | return $float; |
||
112 | case 'true': |
||
113 | case 'false': |
||
114 | case 'null': |
||
115 | if (!$this->reader->isEmptyElement) { |
||
116 | throw new DomainException(sprintf('"%s" scalar must be empty', $name)); |
||
117 | } |
||
118 | return constant($name); |
||
119 | default: |
||
120 | throw new DomainException(sprintf('Unknown scalar type "%s"', $name)); |
||
121 | } |
||
122 | } |
||
123 | |||
153 |