| Conditions | 10 |
| Paths | 19 |
| Total Lines | 53 |
| Code Lines | 30 |
| 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 |
||
| 102 | public function getAllClassNames() |
||
| 103 | { |
||
| 104 | if ($this->classNames !== null) { |
||
| 105 | return $this->classNames; |
||
| 106 | } |
||
| 107 | |||
| 108 | if (!$this->paths) { |
||
|
|
|||
| 109 | throw MappingException::pathRequired(); |
||
| 110 | } |
||
| 111 | |||
| 112 | $includedFiles = []; |
||
| 113 | foreach ($this->paths as $path) { |
||
| 114 | if (!is_dir($path)) { |
||
| 115 | throw MappingException::invalidDirectory($path); |
||
| 116 | } |
||
| 117 | |||
| 118 | $iterator = new \RegexIterator( |
||
| 119 | new \RecursiveIteratorIterator( |
||
| 120 | new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS), |
||
| 121 | \RecursiveIteratorIterator::LEAVES_ONLY |
||
| 122 | ), |
||
| 123 | '/^.+'.preg_quote($this->fileExtension).'$/i', |
||
| 124 | \RecursiveRegexIterator::GET_MATCH |
||
| 125 | ); |
||
| 126 | |||
| 127 | foreach ($iterator as $file) { |
||
| 128 | $sourceFile = $file[0]; |
||
| 129 | |||
| 130 | if (!preg_match('(^phar:)i', $sourceFile)) { |
||
| 131 | $sourceFile = realpath($sourceFile); |
||
| 132 | } |
||
| 133 | |||
| 134 | foreach ($this->excludePaths as $excludePath) { |
||
| 135 | $exclude = str_replace('\\', '/', realpath($excludePath)); |
||
| 136 | $current = str_replace('\\', '/', $sourceFile); |
||
| 137 | |||
| 138 | if (strpos($current, $exclude) !== false) { |
||
| 139 | continue 2; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | require_once $sourceFile; |
||
| 144 | $includedFiles[] = $sourceFile; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | $this->classNames = []; |
||
| 149 | foreach ($includedFiles as $includedFile) { |
||
| 150 | $this->classNames = array_merge($this->classNames, ClassUtils::getClassesInFile($includedFile)); |
||
| 151 | } |
||
| 152 | |||
| 153 | return $this->classNames; |
||
| 154 | } |
||
| 155 | } |
||
| 156 |
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.