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