DMSFilesystemTestHelper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 40
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B delete() 0 23 6
1
<?php
2
3
class DMSFilesystemTestHelper
4
{
5
    /**
6
     * Files that are added to the DMS asset directory by the DMS instance. They will be removed after running tests.
7
     *
8
     * @var array
9
     */
10
    protected static $dmsFiles = array('.htaccess', 'web.config');
11
12
    /**
13
     * Deletes a directory and all files within it, or a file. Will automatically prepend the base path.
14
     *
15
     * This only work while a unit test is running for safety reasons.
16
     *
17
     * @param string $path
18
     */
19
    public static function delete($path)
20
    {
21
        if (!SapphireTest::is_running_test() || !file_exists($path)) {
22
            return false;
23
        }
24
25
        $path = BASE_PATH . DIRECTORY_SEPARATOR . $path;
26
        if (is_dir($path)) {
27
            $files = new RecursiveIteratorIterator(
28
                new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
29
                RecursiveIteratorIterator::CHILD_FIRST
30
            );
31
32
            foreach ($files as $fileinfo) {
33
                $action = $fileinfo->isDir() ? 'rmdir' : 'unlink';
34
                $action($fileinfo->getRealPath());
35
            }
36
37
            rmdir($path);
38
        } else {
39
            unlink($path);
40
        }
41
    }
42
}
43