Completed
Push — develop ( 700ecb...e69eaa )
by Matteo
02:36
created

StashCommand::show()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * GitElephant - An abstraction layer for git written in PHP
4
 * Copyright (C) 2013  Matteo Giachino
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see [http://www.gnu.org/licenses/].
18
 */
19
20
namespace GitElephant\Command;
21
22
use GitElephant\Repository;
23
24
/**
25
 * Stash command generator
26
 *
27
 * @author Matteo Giachino <[email protected]>
28
 * @author Kirk Madera <[email protected]>
29
 */
30
class StashCommand extends BaseCommand
31
{
32
    const STASH_COMMAND = 'stash';
33
34
    /**
35
     * constructor
36
     *
37
     * @param \GitElephant\Repository $repo The repository object this command
38
     *                                      will interact with
39
     */
40 9
    public function __construct(Repository $repo = null)
41
    {
42 9
        parent::__construct($repo);
43 9
    }
44
45
    /**
46
     *  Save your local modifications to a new stash, and run git reset --hard to revert them.
47
     *
48
     * @param string|null $message
49
     * @param boolean $includeUntracked
50
     * @param boolean $keepIndex
51
     */
52 1
    public function save($message = null, $includeUntracked = false, $keepIndex = false)
53
    {
54 1
        $this->clearAll();
55 1
        $this->addCommandName(self::STASH_COMMAND . ' save');
56 1
        if (!is_null($message)) {
57 1
            $this->addCommandSubject($message);
58
        }
59
60 1
        if ($includeUntracked) {
61 1
            $this->addCommandArgument('--include-untracked');
62
        }
63
64 1
        if ($keepIndex) {
65 1
            $this->addCommandArgument('--keep-index');
66
        }
67
68 1
        return $this->getCommand();
69
    }
70
71
    /**
72
     * Shows stash list
73
     *
74
     * @param array|null $options
75
     *
76
     * @return string
77
     */
78 1
    public function list(array $options = null)
79
    {
80 1
        $this->clearAll();
81 1
        $this->addCommandName(self::STASH_COMMAND . ' list');
82 1
        if (null !== $options) {
83 1
            $this->addCommandSubject($options);
0 ignored issues
show
Documentation introduced by
$options is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
84
        }
85 1
        return $this->getCommand();
86
    }
87
88
    /**
89
     * Shows details for a specific stash
90
     *
91
     * @param string $stash
92
     *
93
     * @return string
94
     */
95 1
    public function show($stash)
96
    {
97 1
        $stash = $this->normalizeStashName($stash);
98 1
        $this->clearAll();
99 1
        $this->addCommandName(self::STASH_COMMAND . ' show');
100 1
        $this->addCommandSubject($stash);
101 1
        return $this->getCommand();
102
    }
103
104
    /**
105
     * Drops a stash
106
     *
107
     * @param string $stash
108
     *
109
     * @return string
110
     */
111 1
    public function drop($stash)
112
    {
113 1
        $stash = $this->normalizeStashName($stash);
114 1
        $this->clearAll();
115 1
        $this->addCommandName(self::STASH_COMMAND . ' drop');
116 1
        $this->addCommandSubject($stash);
117 1
        return $this->getCommand();
118
    }
119
120
    /**
121
     * Applies a stash
122
     *
123
     * @param string $stash
124
     * @param boolean $index
125
     *
126
     * @return string
127
     */
128 1
    public function apply($stash, $index = false)
129
    {
130 1
        $stash = $this->normalizeStashName($stash);
131 1
        $this->clearAll();
132 1
        $this->addCommandName(self::STASH_COMMAND . ' apply');
133 1
        $this->addCommandSubject($stash);
134 1
        if ($index) {
135 1
            $this->addCommandArgument('--index');
136
        }
137 1
        return $this->getCommand();
138
    }
139
140
    /**
141
     * Applies a stash, then removes it from the stash
142
     *
143
     * @param string $stash
144
     * @param boolean $index
145
     *
146
     * @return string
147
     */
148 1
    public function pop($stash, $index = false)
149
    {
150 1
        $stash = $this->normalizeStashName($stash);
151 1
        $this->clearAll();
152 1
        $this->addCommandName(self::STASH_COMMAND . ' pop');
153 1
        $this->addCommandSubject($stash);
154 1
        if ($index) {
155 1
            $this->addCommandArgument('--index');
156
        }
157 1
        return $this->getCommand();
158
    }
159
160
    /**
161
     *  Creates and checks out a new branch named <branchname> starting from the commit at which the <stash> was originally created
162
     *
163
     * @param string $branch
164
     * @param string $stash
165
     */
166 1
    public function branch($branch, $stash)
167
    {
168 1
        $stash = $this->normalizeStashName($stash);
169 1
        $this->clearAll();
170 1
        $this->addCommandName(self::STASH_COMMAND . ' branch');
171 1
        $this->addCommandSubject($branch);
172 1
        $this->addCommandSubject2($stash);
173 1
        return $this->getCommand();
174
    }
175
176
    /**
177
     *  Remove all the stashed states.
178
     *
179
     */
180 1
    public function clear()
181
    {
182 1
        $this->clearAll();
183 1
        $this->addCommandName(self::STASH_COMMAND . ' clear');
184 1
        return $this->getCommand();
185
    }
186
187
    /**
188
     * Create a stash (which is a regular commit object) and return its object name, without storing it anywhere in the
189
     * ref namespace.
190
     *
191
     */
192 1
    public function create()
193
    {
194 1
        $this->clearAll();
195 1
        $this->addCommandName(self::STASH_COMMAND . ' create');
196 1
        return $this->getCommand();
197
    }
198
199
    /**
200
     * @param $stash
201
     *
202
     * @return string
203
     */
204 5
    private function normalizeStashName($stash)
205
    {
206 5
        if (0 !== strpos($stash, 'stash@{')) {
207 5
            $stash = 'stash@{' . $stash . '}';
208
        }
209 5
        return $stash;
210
    }
211
212
}
213