Passed
Push — master ( 79545d...728467 )
by Petr
02:28
created

AVolume::rmFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace VolumeTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_files\Interfaces\IProcessDirs;
8
use kalanis\kw_files\Processing\Volume\ProcessDir;
9
use kalanis\kw_paths\PathsException;
10
11
12
class AVolume extends CommonTestClass
13
{
14
    protected function setUp(): void
15
    {
16
        $this->clearData();
17
    }
18
19
    protected function tearDown(): void
20
    {
21
        $this->clearData();
22
    }
23
24
    protected function clearData(): void
25
    {
26
        clearstatcache();
27
        $this->rmFile('another' . DIRECTORY_SEPARATOR . 'sub_one' . DIRECTORY_SEPARATOR . '.gitkeep');
28
        $this->rmDir('another' . DIRECTORY_SEPARATOR . 'sub_one');
29
        $this->rmDir('another');
30
        clearstatcache();
31
        $this->rmDir('sub' . DIRECTORY_SEPARATOR . 'added');
32
        $this->rmDir('more' . DIRECTORY_SEPARATOR . 'added');
33
        clearstatcache();
34
        $this->rmFile('more' . DIRECTORY_SEPARATOR . 'sub_one' . DIRECTORY_SEPARATOR . '.gitkeep');
35
        $this->rmDir('more' . DIRECTORY_SEPARATOR . 'sub_one');
36
        $this->rmDir('more');
37
        clearstatcache();
38
    }
39
40
    protected function rmDir(string $path): void
41
    {
42
        if (is_dir($this->getTestPath() . DIRECTORY_SEPARATOR . $path)) {
43
            rmdir($this->getTestPath() . DIRECTORY_SEPARATOR . $path);
44
        }
45
    }
46
47
    protected function rmFile(string $path): void
48
    {
49
        if (is_file($this->getTestPath() . DIRECTORY_SEPARATOR . $path)) {
50
            unlink($this->getTestPath() . DIRECTORY_SEPARATOR . $path);
51
        }
52
    }
53
54
    /**
55
     * @throws PathsException
56
     * @return IProcessDirs
57
     */
58
    protected function getDirLib(): IProcessDirs
59
    {
60
        return new ProcessDir($this->getTestPath());
61
    }
62
63
    protected function getTestPath(): string
64
    {
65
        return __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'tree';
66
    }
67
}
68