| Conditions | 13 |
| Paths | 19 |
| Total Lines | 42 |
| Code Lines | 25 |
| 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 |
||
| 74 | protected function checkOptions() |
||
| 75 | { |
||
| 76 | foreach ($this->getAllOptionDefinitions() as $def) { |
||
| 77 | list($optionName, $optionType) = $def; |
||
| 78 | |||
| 79 | if (isset($this->providedOptions[$optionName])) { |
||
| 80 | //$this->logLn($optionName); |
||
| 81 | |||
| 82 | $actualType = gettype($this->providedOptions[$optionName]); |
||
| 83 | if ($actualType != $optionType) { |
||
| 84 | $optionType = str_replace('number', 'integer|double', $optionType); |
||
| 85 | if (!in_array($actualType, explode('|', $optionType))) { |
||
| 86 | throw new InvalidOptionTypeException( |
||
| 87 | 'The provided ' . $optionName . ' option is not a ' . $optionType . |
||
| 88 | ' (it is a ' . $actualType . ')' |
||
| 89 | ); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | $optionValue = $this->providedOptions[$optionName]; |
||
| 94 | |||
| 95 | if ($optionName == 'quality') { |
||
| 96 | if ($actualType == 'string') { |
||
| 97 | if ($optionValue != 'auto') { |
||
| 98 | throw new InvalidOptionTypeException( |
||
| 99 | 'Quality option must be either "auto" or a number between 0-100. ' . |
||
| 100 | 'A string, "' . $optionValue . '" was given' |
||
| 101 | ); |
||
| 102 | } |
||
| 103 | } else { |
||
| 104 | if (($optionValue < 0) || ($optionValue > 100)) { |
||
| 105 | throw new InvalidOptionTypeException( |
||
| 106 | 'Quality option must be either "auto" or a number between 0-100. ' . |
||
| 107 | 'The number you provided (' . strval($optionValue) . ') is out of range.' |
||
| 108 | ); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | if (($optionName == 'lossless') && ($actualType == 'string') && ($optionValue != 'auto')) { |
||
| 114 | throw new InvalidOptionTypeException( |
||
| 115 | 'Lossless option must be true, false or "auto". It was set to: "' . $optionValue . '"' |
||
| 116 | ); |
||
| 164 |