File::recursiveDelete()   B
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 21.1875

Importance

Changes 0
Metric Value
cc 6
eloc 12
nc 5
nop 1
dl 0
loc 19
ccs 3
cts 12
cp 0.25
crap 21.1875
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace BitWasp\Bitcoind\Utils;
4
5
use BitWasp\Bitcoind\Exception\BitcoindException;
6
7
class File
8
{
9 1
    public static function recursiveDelete(string $src)
10
    {
11 1
        if (!is_dir($src)) {
12 1
            throw new BitcoindException("Parameter 1 for recursiveDelete should be a directory");
13
        }
14
15
        $dir = opendir($src);
16
        while (false !== ( $file = readdir($dir))) {
0 ignored issues
show
Bug introduced by
It seems like $dir can also be of type false; however, parameter $dir_handle of readdir() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

16
        while (false !== ( $file = readdir(/** @scrutinizer ignore-type */ $dir))) {
Loading history...
17
            if (( $file != '.' ) && ( $file != '..' )) {
18
                $full = $src . '/' . $file;
19
                if (is_dir($full)) {
20
                    self::recursiveDelete($full);
21
                } else {
22
                    unlink($full);
23
                }
24
            }
25
        }
26
        closedir($dir);
0 ignored issues
show
Bug introduced by
It seems like $dir can also be of type false; however, parameter $dir_handle of closedir() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        closedir(/** @scrutinizer ignore-type */ $dir);
Loading history...
27
        rmdir($src);
28
    }
29
}
30