| Conditions | 12 |
| Paths | 27 |
| Total Lines | 62 |
| Code Lines | 34 |
| 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 |
||
| 175 | public function getAllClassNames() |
||
| 176 | { |
||
| 177 | if ($this->classNames !== null) { |
||
| 178 | return $this->classNames; |
||
| 179 | } |
||
| 180 | |||
| 181 | if ( ! $this->paths) { |
||
|
|
|||
| 182 | throw MappingException::pathRequired(); |
||
| 183 | } |
||
| 184 | |||
| 185 | $classes = []; |
||
| 186 | $includedFiles = []; |
||
| 187 | |||
| 188 | foreach ($this->paths as $path) { |
||
| 189 | if ( ! is_dir($path)) { |
||
| 190 | throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path); |
||
| 191 | } |
||
| 192 | |||
| 193 | $iterator = new \RegexIterator( |
||
| 194 | new \RecursiveIteratorIterator( |
||
| 195 | new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS), |
||
| 196 | \RecursiveIteratorIterator::LEAVES_ONLY |
||
| 197 | ), |
||
| 198 | '/^.+' . preg_quote($this->fileExtension) . '$/i', |
||
| 199 | \RecursiveRegexIterator::GET_MATCH |
||
| 200 | ); |
||
| 201 | |||
| 202 | foreach ($iterator as $file) { |
||
| 203 | $sourceFile = $file[0]; |
||
| 204 | |||
| 205 | if ( ! preg_match('(^phar:)i', $sourceFile)) { |
||
| 206 | $sourceFile = realpath($sourceFile); |
||
| 207 | } |
||
| 208 | |||
| 209 | foreach ($this->excludePaths as $excludePath) { |
||
| 210 | $exclude = str_replace('\\', '/', realpath($excludePath)); |
||
| 211 | $current = str_replace('\\', '/', $sourceFile); |
||
| 212 | |||
| 213 | if (strpos($current, $exclude) !== false) { |
||
| 214 | continue 2; |
||
| 215 | } |
||
| 216 | } |
||
| 217 | |||
| 218 | require_once $sourceFile; |
||
| 219 | |||
| 220 | $includedFiles[] = $sourceFile; |
||
| 221 | } |
||
| 222 | } |
||
| 223 | |||
| 224 | $declared = get_declared_classes(); |
||
| 225 | |||
| 226 | foreach ($declared as $className) { |
||
| 227 | $rc = new \ReflectionClass($className); |
||
| 228 | $sourceFile = $rc->getFileName(); |
||
| 229 | if (in_array($sourceFile, $includedFiles) && ! $this->isTransient($className)) { |
||
| 230 | $classes[] = $className; |
||
| 231 | } |
||
| 232 | } |
||
| 233 | |||
| 234 | $this->classNames = $classes; |
||
| 235 | |||
| 236 | return $classes; |
||
| 237 | } |
||
| 239 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.