Passed
Push — master ( cd504b...48cb3c )
by Petr
07:41
created

TRemoveCycle::removeEndingSign()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 2
1
<?php
2
3
namespace kalanis\kw_storage\Extras;
4
5
6
/**
7
 * Trait TRemoveCycle
8
 * @package kalanis\kw_storage\Extras
9
 * low-level work with extended dirs - remove dirs and files in cycle - everything with subdirectories
10
 */
11
trait TRemoveCycle
12
{
13
    /**
14
     * Remove sub dirs and their content recursively
15
     * @param string $dirPath
16
     * @param string $sign
17
     * @return bool
18
     */
19 4
    protected function removeCycle(string $dirPath, string $sign = DIRECTORY_SEPARATOR): bool
20
    {
21 4
        $path = realpath($dirPath);
22 4
        if (false === $path) {
23 2
            return false;
24
        }
25 4
        if (is_dir($path)) {
26 2
            $fileListing = scandir($path);
27 2
            if (!empty($fileListing)) {
28 2
                foreach ($fileListing as $fileName) {
29 2
                    if (is_dir($path . $sign . $fileName)) {
30 2
                        if (('.' != $fileName) && ('..' != $fileName)) {
31 2
                            $this->removeCycle($path . $sign . $fileName);
32
                        }
33
                    } else {
34 2
                        unlink($path . $sign . $fileName);
35
                    }
36
                }
37
            }
38 2
            rmdir($path);
39 2
        } elseif (is_file($path)) {
40 2
            unlink($path);
41
        }
42 4
        return true;
43
    }
44
}
45