Completed
Push — output_parsers_refactor ( aea727...5337aa )
by Alessandro
03:53
created

Cleaner::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Paraunit\File;
4
5
6
use Paraunit\Configuration\Paraunit;
7
8
/**
9
 * Class Cleaner
10
 * @package Paraunit\File
11
 */
12
class Cleaner
13
{
14
    /** @var  Paraunit */
15
    private $configuration;
16
17
    /**
18
     * Cleaner constructor.
19
     * @param Paraunit $configuration
20
     */
21 8
    public function __construct(Paraunit $configuration)
22
    {
23 8
        $this->configuration = $configuration;
24 8
    }
25
26 8
    public function purgeCurrentTempDir()
27
    {
28 8
        self::cleanUpDir($this->configuration->getTempDirForThisExecution());
29 8
    }
30
31
    /**
32
     * @param string $dir
33
     * @return bool True if the directory existed and it has been deleted
34
     */
35 27
    public static function cleanUpDir($dir)
36
    {
37 27
        if ( ! file_exists($dir)) {
38
            return false;
39
        }
40
41 27
        $it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
42 27
        $files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
43
44 27
        foreach($files as $file) {
45 27
            if ($file->isDir()){
46 27
                rmdir($file->getRealPath());
47 27
            } else {
48 16
                unlink($file->getRealPath());
49
            }
50 27
        }
51
52 27
        return rmdir($dir);
53
    }
54
}
55