| Conditions | 19 |
| Paths | 785 |
| Total Lines | 82 |
| 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 |
||
| 128 | protected function exportObj($i, $obj) |
||
| 129 | { |
||
| 130 | if (array_search($obj, $this->outputObjects, true) !== false) { |
||
| 131 | return $i . ' [recursion, skipped]<br />'; |
||
| 132 | } |
||
| 133 | |||
| 134 | $this->outputObjects[] = $obj; |
||
| 135 | |||
| 136 | $list = (array)$obj; |
||
| 137 | |||
| 138 | $protectedLength = strlen(get_class($obj)) + 2; |
||
| 139 | |||
| 140 | $out = array(); |
||
| 141 | |||
| 142 | if ($this->outputMethods) { |
||
| 143 | $ref = new ReflectionObject($obj); |
||
| 144 | |||
| 145 | foreach ($ref->getMethods() as $method) { |
||
| 146 | if (!$method->isPublic()) { |
||
| 147 | continue; |
||
| 148 | } |
||
| 149 | |||
| 150 | if (empty($out['method'])) { |
||
| 151 | $out['method'] = ''; |
||
| 152 | } |
||
| 153 | |||
| 154 | $params = array(); |
||
| 155 | foreach ($method->getParameters() as $param) { |
||
| 156 | $params[] = ($param->isPassedByReference() ? '&' : '') . '$' . $param->getName() . ($param->isOptional() ? ' = ' . var_export($param->getDefaultValue(), true) : ''); |
||
| 157 | } |
||
| 158 | |||
| 159 | $out['method'] .= '(method) ' . $method->getName() . '(' . implode(', ', $params) . ')<br />'; |
||
| 160 | } |
||
| 161 | } |
||
| 162 | |||
| 163 | foreach ($list as $attributeName => $attributeValue) { |
||
| 164 | if (property_exists($obj, $attributeName)) { |
||
| 165 | $key = 'public'; |
||
| 166 | } elseif (substr($attributeName, 0, 3) === "\0*\0") { |
||
| 167 | $key = 'protected'; |
||
| 168 | $attributeName = substr($attributeName, 3); |
||
| 169 | } else { |
||
| 170 | $key = 'private'; |
||
| 171 | $attributeName = substr($attributeName, $protectedLength); |
||
| 172 | } |
||
| 173 | |||
| 174 | if (empty($out[$key])) { |
||
| 175 | $out[$key] = ''; |
||
| 176 | } |
||
| 177 | |||
| 178 | $out[$key] .= '(' . $key . ') '; |
||
| 179 | |||
| 180 | if (is_array($attributeValue)) { |
||
| 181 | $out[$key] .= $attributeName . ' (array):<br /> |
||
| 182 | <div style="padding-left:20px;">' . $this->export($attributeValue, false) . '</div>'; |
||
| 183 | } elseif (is_object($attributeValue)) { |
||
| 184 | $out[$key] .= $this->exportObj($attributeName . ' (object: ' . get_class($attributeValue) . '):', $attributeValue); |
||
| 185 | } else { |
||
| 186 | $out[$key] .= $this->exportVar($attributeName . ' = ', $attributeValue); |
||
| 187 | } |
||
| 188 | } |
||
| 189 | |||
| 190 | $return = $i . '<br /><div style="padding-left:20px;">'; |
||
| 191 | |||
| 192 | if (!empty($out['method'])) { |
||
| 193 | $return .= $out['method']; |
||
| 194 | } |
||
| 195 | |||
| 196 | if (!empty($out['public'])) { |
||
| 197 | $return .= $out['public']; |
||
| 198 | } |
||
| 199 | |||
| 200 | if (!empty($out['protected'])) { |
||
| 201 | $return .= $out['protected']; |
||
| 202 | } |
||
| 203 | |||
| 204 | if (!empty($out['private'])) { |
||
| 205 | $return .= $out['private']; |
||
| 206 | } |
||
| 207 | |||
| 208 | return $return . '</div>'; |
||
| 209 | } |
||
| 210 | } |
||
| 211 |