Completed
Pull Request — master (#2)
by Саша
08:50
created

HookContext::clearDirectory()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 17
rs 9.4285
cc 3
eloc 11
nc 3
nop 1
1
<?php
2
3
use Behat\Behat\Context\Context;
4
5
class HookContext extends BaseContext implements Context
6
{
7
    /**
8
     * @BeforeScenario
9
     */
10
    public function initialize()
11
    {
12
        self::$workingDirectory = sys_get_temp_dir().DIRECTORY_SEPARATOR.'etl'.DIRECTORY_SEPARATOR;
13
    }
14
15
    /**
16
     * @AfterScenario
17
     */
18
    public function cleanup()
19
    {
20
        $this->clearDirectory(self::$workingDirectory);
21
    }
22
23
    private function clearDirectory($path)
24
    {
25
        $files = scandir($path);
26
        array_shift($files);
27
        array_shift($files);
28
29
        foreach ($files as $file) {
30
            $file = $path.DIRECTORY_SEPARATOR.$file;
31
            if (is_dir($file)) {
32
                $this->clearDirectory($file);
33
            } else {
34
                unlink($file);
35
            }
36
        }
37
38
        rmdir($path);
39
    }
40
}
41