Git   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 90
rs 10
c 1
b 0
f 0
wmc 10
lcom 2
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getCode() 0 4 1
A getWorkingDirectory() 0 4 1
A prepare() 0 4 1
A process() 0 16 3
A getWrapper() 0 4 1
A setWrapper() 0 4 1
1
<?php
2
3
/**
4
 * Drush Cerbere command line tools.
5
 * Copyright (C) 2015 - Sebastien Malot <[email protected]>
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along
18
 * with this program; if not, write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
 */
21
22
namespace Cerbere\Versioning;
23
24
use GitWrapper\GitWrapper;
25
26
/**
27
 * Class Git
28
 * @package Cerbere\Versioning
29
 */
30
class Git implements VersioningInterface
31
{
32
    /**
33
     * @var GitWrapper
34
     */
35
    protected $wrapper;
36
37
    /**
38
     * @var string
39
     */
40
    protected $workDirectory;
41
42
    /**
43
     * @param GitWrapper $wrapper
44
     */
45
    public function __construct(GitWrapper $wrapper = null)
46
    {
47
        if (null === $wrapper) {
48
            $wrapper = new GitWrapper();
49
        }
50
51
        $this->wrapper = $wrapper;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getCode()
58
    {
59
        return 'git';
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getWorkingDirectory()
66
    {
67
        return $this->workDirectory;
68
    }
69
70
    /**
71
     * @param string $source
72
     *
73
     * @return void
74
     */
75
    public function prepare($source)
76
    {
77
        $this->workDirectory = drush_tempdir();
78
    }
79
80
    /**
81
     * @param string $source
82
     * @param string $destination
83
     * @param array $options
84
     *
85
     * @return string
86
     */
87
    public function process($source, $destination, $options = array())
88
    {
89
        $parameters = array();
90
91
        $options += array('arguments' => array());
92
93
        foreach ($options['arguments'] as $param => $value) {
94
            if (is_numeric($param)) {
95
                $parameters[$value] = true;
96
            } else {
97
                $parameters[$param] = $value;
98
            }
99
        }
100
101
        $this->wrapper->cloneRepository($source, $destination, $parameters);
102
    }
103
104
    /**
105
     * @return GitWrapper
106
     */
107
    public function getWrapper()
108
    {
109
        return $this->wrapper;
110
    }
111
112
    /**
113
     * @param GitWrapper $wrapper
114
     */
115
    public function setWrapper($wrapper)
116
    {
117
        $this->wrapper = $wrapper;
118
    }
119
}
120