Passed
Push — master ( 21c505...12ca40 )
by Sebastian
02:34
created

DummyRepo   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 0
dl 0
loc 43
c 0
b 0
f 0
rs 10
1
<?php
2
/**
3
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace sebastianfeldmann\CaptainHook\Git;
11
12
class DummyRepo
13
{
14
    private $path;
15
16
    private $gitDir;
17
18
    public function __construct($name = null)
19
    {
20
        $name         = empty($name) ? md5(mt_rand(0, 9999)) : $name;
21
        $this->path   = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $name;
22
        $this->gitDir = $this->path . DIRECTORY_SEPARATOR . '.git';
23
    }
24
25
    public function setup()
26
    {
27
        mkdir($this->gitDir . DIRECTORY_SEPARATOR . 'hooks', 0777, true);
28
    }
29
30
    public function touchHook($name, $content = '# dummy hook')
31
    {
32
        file_put_contents($this->gitDir . DIRECTORY_SEPARATOR . 'hooks' . DIRECTORY_SEPARATOR . $name, $content);
33
    }
34
35
    public function merge()
36
    {
37
        file_put_contents($this->gitDir . DIRECTORY_SEPARATOR . 'MERGE_MSG', '# merge file');
38
    }
39
40
    public function getPath()
41
    {
42
        return $this->path;
43
    }
44
45
    public function getGitDir()
46
    {
47
        return $this->path . DIRECTORY_SEPARATOR . '.git';
48
    }
49
50
    public function cleanup()
51
    {
52
        system('rm -rf ' . $this->path);
53
    }
54
}
55