Completed
Push — master ( 8b8afe...5f2bbe )
by Greg
02:21
created

src/Task/Vcs/HgStack.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Robo\Task\Vcs;
3
4
use Robo\Task\CommandStack;
5
6
/**
7
 * Runs hg commands in stack. You can use `stopOnFail()` to point that stack should be terminated on first fail.
8
 *
9
 * ``` php
10
 * <?php
11
 * $this->hgStack
12
 *  ->cloneRepo('https://bitbucket.org/durin42/hgsubversion')
13
 *  ->pull()
14
 *  ->add()
15
 *  ->commit('changed')
16
 *  ->push()
17
 *  ->tag('0.6.0')
18
 *  ->push('0.6.0')
19
 *  ->run();
20
 * ?>
21
 * ```
22
 */
23
class HgStack extends CommandStack
24
{
25
26
    /**
27
     * @param string $pathToHg
28
     */
29
    public function __construct($pathToHg = 'hg')
30
    {
31
        $this->executable = $pathToHg;
32
    }
33
34
    /**
35
     * Executes `hg clone`
36
     *
37
     * @param string $repo
38
     * @param string $to
39
     *
40
     * @return $this
41
     */
42
    public function cloneRepo($repo, $to = '')
43
    {
44
        return $this->exec(['clone', $repo, $to]);
45
    }
46
47
    /**
48
     * Executes `hg add` command with files to add by pattern
49
     *
50
     * @param string $include
51
     * @param string $exclude
52
     *
53
     * @return $this
54
     */
55
    public function add($include = '', $exclude = '')
56
    {
57
        if (strlen($include) > 0) {
58
            $include = "-I {$include}";
59
        }
60
61
        if (strlen($exclude) > 0) {
62
            $exclude = "-X {$exclude}";
63
        }
64
65
        return $this->exec([__FUNCTION__, $include, $exclude]);
66
    }
67
68
    /**
69
     * Executes `hg commit` command with a message
70
     *
71
     * @param string $message
72
     * @param string $options
73
     *
74
     * @return $this
75
     */
76
    public function commit($message, $options = '')
77
    {
78
        return $this->exec([__FUNCTION__, "-m '{$message}'", $options]);
79
    }
80
81
    /**
82
     * Executes `hg pull` command.
83
     *
84
     * @param string $branch
85
     *
86
     * @return $this
87
     */
88 View Code Duplication
    public function pull($branch = '')
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90
        if (strlen($branch) > 0) {
91
            $branch = "-b '{$branch}''";
92
        }
93
94
        return $this->exec([__FUNCTION__, $branch]);
95
    }
96
97
    /**
98
     * Executes `hg push` command
99
     *
100
     * @param string $branch
101
     *
102
     * @return $this
103
     */
104 View Code Duplication
    public function push($branch = '')
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
105
    {
106
        if (strlen($branch) > 0) {
107
            $branch = "-b '{$branch}'";
108
        }
109
110
        return $this->exec([__FUNCTION__, $branch]);
111
    }
112
113
    /**
114
     * Performs hg merge
115
     *
116
     * @param string $revision
117
     *
118
     * @return $this
119
     */
120
    public function merge($revision = '')
121
    {
122
        if (strlen($revision) > 0) {
123
            $revision = "-r {$revision}";
124
        }
125
126
        return $this->exec([__FUNCTION__, $revision]);
127
    }
128
129
    /**
130
     * Executes `hg tag` command
131
     *
132
     * @param string $tag_name
133
     * @param string $message
134
     *
135
     * @return $this
136
     */
137 View Code Duplication
    public function tag($tag_name, $message = '')
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
138
    {
139
        if ($message !== '') {
140
            $message = "-m '{$message}'";
141
        }
142
        return $this->exec([__FUNCTION__, $message, $tag_name]);
143
    }
144
145
    /**
146
     * {@inheritdoc}
147
     */
148
    public function run()
149
    {
150
        $this->printTaskInfo('Running hg commands...');
151
        return parent::run();
152
    }
153
}
154