| Conditions | 11 |
| Paths | 21 |
| Total Lines | 52 |
| 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 |
||
| 22 | function mappingsFrom(array $paths, $fileExtension = '.php') { |
||
| 23 | $includedFiles = []; |
||
| 24 | |||
| 25 | foreach ($paths as $path) { |
||
| 26 | if (!is_dir($path)) { |
||
| 27 | throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path); |
||
| 28 | } |
||
| 29 | |||
| 30 | $iterator = new RegexIterator( |
||
| 31 | new RecursiveIteratorIterator( |
||
| 32 | new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS), |
||
| 33 | RecursiveIteratorIterator::LEAVES_ONLY |
||
| 34 | ), |
||
| 35 | '/^.+'.preg_quote($fileExtension, '/').'$/i', |
||
| 36 | RecursiveRegexIterator::GET_MATCH |
||
| 37 | ); |
||
| 38 | |||
| 39 | foreach ($iterator as $file) { |
||
| 40 | $sourceFile = $file[0]; |
||
| 41 | |||
| 42 | if (!preg_match('(^phar:)i', $sourceFile)) { |
||
| 43 | $sourceFile = realpath($sourceFile); |
||
| 44 | } |
||
| 45 | |||
| 46 | require_once $sourceFile; |
||
| 47 | |||
| 48 | $includedFiles[$sourceFile] = true; |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | $mappings = []; |
||
| 53 | $declared = get_declared_classes(); |
||
| 54 | foreach ($declared as $className) { |
||
| 55 | $rc = new ReflectionClass($className); |
||
| 56 | $sourceFile = $rc->getFileName(); |
||
| 57 | if ($sourceFile === false || !array_key_exists($sourceFile, $includedFiles)) { |
||
| 58 | continue; |
||
| 59 | } |
||
| 60 | |||
| 61 | if ($rc->isAbstract() || $rc->isInterface()) { |
||
| 62 | continue; |
||
| 63 | } |
||
| 64 | |||
| 65 | if (!$rc->implementsInterface(Mapping::class)) { |
||
| 66 | continue; |
||
| 67 | } |
||
| 68 | |||
| 69 | $mappings[] = $rc->newInstanceWithoutConstructor(); |
||
| 70 | } |
||
| 71 | |||
| 72 | return $mappings; |
||
| 73 | } |
||
| 74 |