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

Cleaner   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 94.44%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 43
ccs 17
cts 18
cp 0.9444
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A purgeCurrentTempDir() 0 4 1
A cleanUpDir() 0 19 4
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