Completed
Pull Request — master (#2)
by Саша
36:16 queued 06:11
created

HookContext   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 36
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 4 1
A cleanup() 0 4 1
A clearDirectory() 0 17 3
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