Conditions | 10 |
Paths | 9 |
Total Lines | 37 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
60 | public static function listDirectory(string $path, int $option = self::LIST_DIRECTORY_BOTH): ?array |
||
61 | { |
||
62 | if (!file_exists($path) || !is_dir($path)) { |
||
63 | return null; |
||
64 | } |
||
65 | |||
66 | $aResult = []; |
||
67 | |||
68 | $resourceDir = opendir($path); |
||
69 | |||
70 | while (false !== ($strFile = readdir($resourceDir))) { |
||
|
|||
71 | if (in_array($strFile, ['.', '..'])) { |
||
72 | continue; |
||
73 | } |
||
74 | |||
75 | $strCompleteFile = $path.'/'.$strFile; |
||
76 | switch ($option) { |
||
77 | case self::LIST_DIRECTORY_FILE_ONLY: |
||
78 | if (!is_dir($strCompleteFile)) { |
||
79 | $aResult[] = $strFile; |
||
80 | } |
||
81 | break; |
||
82 | case self::LIST_DIRECTORY_DIR_ONLY: |
||
83 | if (is_dir($strCompleteFile)) { |
||
84 | $aResult[] = $strFile; |
||
85 | } |
||
86 | break; |
||
87 | case self::LIST_DIRECTORY_BOTH: |
||
88 | $aResult[] = $strFile; |
||
89 | break; |
||
90 | default: |
||
91 | return null; |
||
92 | } |
||
93 | } |
||
94 | closedir($resourceDir); |
||
95 | |||
96 | return $aResult; |
||
97 | } |
||
99 |