SvnStack   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 78
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A update() 0 4 1
A add() 0 4 1
A commit() 0 4 1
A checkout() 0 4 1
1
<?php
2
3
namespace Robo\Task\Vcs;
4
5
use Robo\Contract\CommandInterface;
6
use Robo\Result;
7
use Robo\Task\CommandStack;
8
9
/**
10
 * Runs Svn commands in stack. You can use `stopOnFail()` to point that stack should be terminated on first fail.
11
 *
12
 * ``` php
13
 * <?php
14
 * $this->taskSvnStack()
15
 *  ->checkout('http://svn.collab.net/repos/svn/trunk')
16
 *  ->run()
17
 *
18
 * // alternatively
19
 * $this->_svnCheckout('http://svn.collab.net/repos/svn/trunk');
20
 *
21
 * $this->taskSvnStack('username', 'password')
22
 *  ->stopOnFail()
23
 *  ->update()
24
 *  ->add('doc/*')
25
 *  ->commit('doc updated')
26
 *  ->run();
27
 * ?>
28
 * ```
29
 */
30
class SvnStack extends CommandStack implements CommandInterface
31
{
32
    /**
33
     * @var bool
34
     */
35
    protected $stopOnFail = false;
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected $result;
41
42
    /**
43
     * @param string $username
44
     * @param string $password
45
     * @param string $pathToSvn
46
     */
47
    public function __construct($username = '', $password = '', $pathToSvn = 'svn')
48
    {
49
        $this->executable = $pathToSvn;
50
        if (!empty($username)) {
51
            $this->executable .= " --username $username";
52
        }
53
        if (!empty($password)) {
54
            $this->executable .= " --password $password";
55
        }
56
        $this->result = Result::success($this);
57
    }
58
59
    /**
60
     * Updates `svn update` command
61
     *
62
     * @param string $path
63
     *
64
     * @return $this
65
     */
66
    public function update($path = '')
67
    {
68
        return $this->exec("update $path");
69
    }
70
71
    /**
72
     * Executes `svn add` command with files to add pattern
73
     *
74
     * @param string $pattern
75
     *
76
     * @return $this
77
     */
78
    public function add($pattern = '')
79
    {
80
        return $this->exec("add $pattern");
81
    }
82
83
    /**
84
     * Executes `svn commit` command with a message
85
     *
86
     * @param string $message
87
     * @param string $options
88
     *
89
     * @return $this
90
     */
91
    public function commit($message, $options = "")
92
    {
93
        return $this->exec("commit -m '$message' $options");
94
    }
95
96
    /**
97
     * Executes `svn checkout` command
98
     *
99
     * @param string $branch
100
     *
101
     * @return $this
102
     */
103
    public function checkout($branch)
104
    {
105
        return $this->exec("checkout $branch");
106
    }
107
}
108