| Conditions | 10 |
| Paths | 10 |
| Total Lines | 35 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 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 | |||
| 139 | } |
$sourcecan contain request data and is used in file manipulation context(s) leading to a potential security vulnerability.1 path for user data to reach this point
HTTP_HOSTfrom$_SERVER,and$_SERVER['HTTP_HOST']is passed through str_replace(), andstr_replace(':', '_', $_SERVER['HTTP_HOST'])is passed through strtolower(), andstrtolower(str_replace(':', '_', $_SERVER['HTTP_HOST']))is passed through preg_replace(), and$securityKeyis assignedin src/phpFastCache/Core/Pool/IO/PathSeekerTrait.php on line 60
in vendor/src/phpFastCache/Core/Pool/IO/PathSeekerTrait.php on line 194
$securityKeyis assignedin src/phpFastCache/Core/Pool/IO/PathSeekerTrait.php on line 70
$full_pathis assignedin src/phpFastCache/Core/Pool/IO/PathSeekerTrait.php on line 87
$full_pathis passed through realpath()in src/phpFastCache/Core/Pool/IO/PathSeekerTrait.php on line 104
$this->getPath(true)is passed to Directory::rrmdir()in src/phpFastCache/Drivers/Files/Driver.php on line 135
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:
if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) { throw new \InvalidArgumentException('This input is not allowed.'); }For numeric data, we recommend to explicitly cast the data: