Conditions | 10 |
Paths | 10 |
Total Lines | 37 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
74 | public static function rrmdir($source, $removeOnlyChildren = false) |
||
75 | { |
||
76 | if (empty($source) || file_exists($source) === false) { |
||
77 | return false; |
||
78 | } |
||
79 | |||
80 | if (is_file($source) || is_link($source)) { |
||
81 | return unlink($source); |
||
|
|||
82 | } |
||
83 | |||
84 | $files = new RecursiveIteratorIterator |
||
85 | ( |
||
86 | new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), |
||
87 | RecursiveIteratorIterator::CHILD_FIRST |
||
88 | ); |
||
89 | |||
90 | foreach ($files as $fileinfo) { |
||
91 | /** |
||
92 | * @var SplFileInfo $fileinfo |
||
93 | */ |
||
94 | if ($fileinfo->isDir()) { |
||
95 | if (self::rrmdir($fileinfo->getRealPath()) === false) { |
||
96 | return false; |
||
97 | } |
||
98 | } else { |
||
99 | if (unlink($fileinfo->getRealPath()) === false) { |
||
100 | return false; |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | |||
105 | if ($removeOnlyChildren === false) { |
||
106 | return rmdir($source); |
||
107 | } |
||
108 | |||
109 | return true; |
||
110 | } |
||
111 | } |
$source
can contain request data and is used in file manipulation context(s) leading to a potential security vulnerability.General Strategies to prevent injection
In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:
For numeric data, we recommend to explicitly cast the data: