| Conditions | 10 |
| Paths | 15 |
| Total Lines | 47 |
| Code Lines | 26 |
| 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 |
||
| 68 | public function getAllClassNames() |
||
| 69 | { |
||
| 70 | if ($this->classNames !== null) { |
||
| 71 | return $this->classNames; |
||
| 72 | } |
||
| 73 | |||
| 74 | if ( ! $this->paths) { |
||
|
|
|||
| 75 | throw MappingException::pathRequired(); |
||
| 76 | } |
||
| 77 | |||
| 78 | $classes = []; |
||
| 79 | $includedFiles = []; |
||
| 80 | |||
| 81 | foreach ($this->paths as $path) { |
||
| 82 | if ( ! is_dir($path)) { |
||
| 83 | throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path); |
||
| 84 | } |
||
| 85 | |||
| 86 | $iterator = new \RecursiveIteratorIterator( |
||
| 87 | new \RecursiveDirectoryIterator($path), |
||
| 88 | \RecursiveIteratorIterator::LEAVES_ONLY |
||
| 89 | ); |
||
| 90 | |||
| 91 | foreach ($iterator as $file) { |
||
| 92 | if ($file->getBasename('.php') == $file->getBasename()) { |
||
| 93 | continue; |
||
| 94 | } |
||
| 95 | |||
| 96 | $sourceFile = realpath($file->getPathName()); |
||
| 97 | require_once $sourceFile; |
||
| 98 | $includedFiles[] = $sourceFile; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | $declared = get_declared_classes(); |
||
| 103 | |||
| 104 | foreach ($declared as $className) { |
||
| 105 | $rc = new \ReflectionClass($className); |
||
| 106 | $sourceFile = $rc->getFileName(); |
||
| 107 | if (in_array($sourceFile, $includedFiles) && ! $this->isTransient($className)) { |
||
| 108 | $classes[] = $className; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | $this->classNames = $classes; |
||
| 113 | |||
| 114 | return $classes; |
||
| 115 | } |
||
| 125 |
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.