Completed
Push — master ( 2d2a4f...6d125c )
by Greg
01:53
created

Fixtures::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Robo;
4
5
use Symfony\Component\Filesystem\Filesystem;
6
7
class Fixtures
8
{
9
    protected $testDir;
10
    protected $tmpDirs = [];
11
    protected $clonedRepos = [];
12
13
    /**
14
     * Fixtures constructor
15
     */
16
    public function __construct()
17
    {
18
        $testDir = false;
0 ignored issues
show
Unused Code introduced by
$testDir is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
19
    }
20
21
    /**
22
     * Clean up any temporary directories that may have been created
23
     */
24
    public function cleanup()
25
    {
26
        $fs = new Filesystem();
27
        foreach ($this->tmpDirs as $tmpDir) {
28
            try {
29
                $fs->remove($tmpDir);
30
            }
31
            catch (\Exception $e) {
32
                // Ignore problems with removing fixtures.
33
            }
34
        }
35
        $this->tmpDirs = [];
36
    }
37
38
    /**
39
     * Create a new temporary directory.
40
     *
41
     * @param string|bool $basedir Where to store the temporary directory
42
     * @return type
43
     */
44
    public function mktmpdir($basedir = false)
45
    {
46
        $tempfile = tempnam($basedir ?: $this->testDir ?: sys_get_temp_dir(),'robo-tests');
47
        unlink($tempfile);
48
        mkdir($tempfile);
49
        $this->tmpDirs[] = $tempfile;
50
        return $tempfile;
51
    }
52
53
    public function createAndCdToSandbox()
54
    {
55
        $sourceSandbox = $this->sandboxDir();
56
        $targetSandbox = $this->mktmpdir();
57
        $fs = new Filesystem();
58
        $fs->mirror($sourceSandbox, $targetSandbox);
59
        chdir($targetSandbox);
60
61
        return $targetSandbox;
62
    }
63
64
    public function dataFile($filename)
65
    {
66
        return $this->fixturesDir() . '/' . $filename;
67
    }
68
69
    protected function fixturesDir()
70
    {
71
        return dirname(__DIR__) . '/_data';
72
    }
73
74
    protected function sandboxDir()
75
    {
76
        return $this->fixturesDir() . '/claypit';
77
    }
78
79
    protected function testDir()
80
    {
81
        if (!$this->testDir) {
82
            $this->testDir = $this->mktmpdir();
83
        }
84
        return $this->testDir;
85
    }
86
}
87