AbstractTest::cleanupCacheDir()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 4
nc 4
nop 0
1
<?php
2
3
namespace Nip\Cache\Tests;
4
5
use FilesystemIterator;
6
use PHPUnit\Framework\TestCase;
7
use RecursiveDirectoryIterator;
8
use RecursiveIteratorIterator;
9
10
/**
11
 * Class AbstractTest
12
 */
13
abstract class AbstractTest extends TestCase
14
{
15
    protected $object;
16
17
    protected function setUp(): void
18
    {
19
        parent::setUp();
20
21
        $this->cleanupCacheDir();
22
    }
23
24
    protected function cleanupCacheDir()
25
    {
26
        $dir = CACHE_PATH;
27
28
        $di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
29
        $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
30
        foreach ($ri as $file) {
31
            if ($file->getFilename() == '.gitignore') {
32
                continue;
33
            }
34
            $file->isDir() ? rmdir($file) : unlink($file);
35
        }
36
    }
37
}
38