AbstractTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 22
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A cleanupCacheDir() 0 11 4
A setUp() 0 5 1
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