Conditions | 10 |
Paths | 10 |
Total Lines | 35 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
78 | public static function rrmdir($source, $removeOnlyChildren = false) |
||
79 | { |
||
80 | if (empty($source) || file_exists($source) === false) { |
||
81 | return false; |
||
82 | } |
||
83 | |||
84 | if (is_file($source) || is_link($source)) { |
||
85 | return unlink($source); |
||
|
|||
86 | } |
||
87 | |||
88 | $files = new RecursiveIteratorIterator |
||
89 | ( |
||
90 | new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), |
||
91 | RecursiveIteratorIterator::CHILD_FIRST |
||
92 | ); |
||
93 | |||
94 | foreach ($files as $fileinfo) { |
||
95 | /** |
||
96 | * @var SplFileInfo $fileinfo |
||
97 | */ |
||
98 | if ($fileinfo->isDir()) { |
||
99 | if (self::rrmdir($fileinfo->getRealPath()) === false) { |
||
100 | return false; |
||
101 | } |
||
102 | } else if(unlink($fileinfo->getRealPath()) === false) { |
||
103 | return false; |
||
104 | } |
||
105 | } |
||
106 | |||
107 | if ($removeOnlyChildren === false) { |
||
108 | return rmdir($source); |
||
109 | } |
||
110 | |||
111 | return true; |
||
112 | } |
||
113 | } |
$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: