| Conditions | 4 |
| Paths | 4 |
| Total Lines | 18 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 46 | 13 | public static function createDirectory(string $path, int $permissions = 0777): void |
|
| 47 | { |
||
| 48 | |||
| 49 | 13 | if (preg_match("/(\/\.+|\.+)$/i", $path)) { |
|
| 50 | 6 | throw new \Exception( |
|
| 51 | 6 | sprintf("Нельзя создать директорию: %s", $path) |
|
| 52 | ); |
||
| 53 | } |
||
| 54 | |||
| 55 | //Clear the most recent error |
||
| 56 | 7 | error_clear_last(); |
|
| 57 | |||
| 58 | 7 | if (!is_dir($path)) { |
|
| 59 | 7 | if (@mkdir($path, $permissions, true) === false) { |
|
| 60 | /** @var string[] $error */ |
||
| 61 | 1 | $error = error_get_last(); |
|
| 62 | 1 | throw new \Exception( |
|
| 63 | 1 | sprintf("Не удалось создать директорию: %s! Причина: %s", $path, $error['message']) |
|
| 64 | ); |
||
| 69 |