Conditions | 10 |
Paths | 18 |
Total Lines | 28 |
Code Lines | 16 |
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 |
||
50 | public static function getReferences (string $file, bool $parseExtensions = true): array |
||
51 | { |
||
52 | $references = []; |
||
53 | |||
54 | foreach (file ($file) as $id => $line) |
||
55 | if (substr ($line, 0, 7) == 'require') |
||
56 | try |
||
57 | { |
||
58 | $begin = strpos ($line, "'"); |
||
59 | $end = strrpos ($line, "'") - $begin + 1; |
||
60 | |||
61 | $references = array_merge ($references, self::getReferences (dirname ($file) .'/'. eval ('namespace VoidEngine; return '. substr ($line, $begin, $end) .';'), false)); |
||
62 | } |
||
63 | |||
64 | catch (\Throwable $e) |
||
65 | { |
||
66 | continue; |
||
67 | } |
||
68 | |||
69 | if ($parseExtensions) |
||
70 | if (is_dir (\VoidEngine\ENGINE_DIR .'/extensions') && is_array ($exts = scandir (\VoidEngine\ENGINE_DIR .'/extensions'))) |
||
71 | foreach ($exts as $id => $ext) |
||
72 | if (is_dir (\VoidEngine\ENGINE_DIR .'/extensions/'. $ext) && file_exists ($ext = \VoidEngine\ENGINE_DIR .'/extensions/'. $ext .'/main.php')) |
||
73 | $references = array_merge ($references, self::getReferences ($ext, false)); |
||
74 | |||
75 | $references[] = $file; |
||
76 | |||
77 | return $references; |
||
78 | } |
||
99 |