|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* GitElephant - An abstraction layer for git written in PHP |
|
5
|
|
|
* Copyright (C) 2013 Matteo Giachino |
|
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 3 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 |
|
18
|
|
|
* along with this program. If not, see [http://www.gnu.org/licenses/]. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace GitElephant\Command; |
|
22
|
|
|
|
|
23
|
|
|
use GitElephant\Objects\Tag; |
|
24
|
|
|
use GitElephant\Repository; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Tag command generator |
|
28
|
|
|
* |
|
29
|
|
|
* @author Matteo Giachino <[email protected]> |
|
30
|
|
|
*/ |
|
31
|
|
|
class TagCommand extends BaseCommand |
|
32
|
|
|
{ |
|
33
|
|
|
public const TAG_COMMAND = 'tag'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* constructor |
|
37
|
|
|
* |
|
38
|
|
|
* @param \GitElephant\Repository $repo The repository object this command |
|
39
|
|
|
* will interact with |
|
40
|
|
|
*/ |
|
41
|
28 |
|
public function __construct(Repository $repo = null) |
|
42
|
|
|
{ |
|
43
|
28 |
|
parent::__construct($repo); |
|
44
|
28 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Create a new tag |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $name The new tag name |
|
50
|
|
|
* @param string|null $startPoint the new tag start point. |
|
51
|
|
|
* @param string|null $message the tag message |
|
52
|
|
|
* |
|
53
|
|
|
* @throws \RuntimeException |
|
54
|
|
|
* @return string the command |
|
55
|
|
|
*/ |
|
56
|
27 |
|
public function create(string $name, $startPoint = null, $message = null): string |
|
57
|
|
|
{ |
|
58
|
27 |
|
$this->clearAll(); |
|
59
|
27 |
|
$this->addCommandName(self::TAG_COMMAND); |
|
60
|
|
|
|
|
61
|
27 |
|
if (null !== $message) { |
|
62
|
|
|
$this->addCommandArgument('-m'); |
|
63
|
|
|
$this->addCommandArgument($message); |
|
64
|
|
|
} |
|
65
|
27 |
|
if (null !== $startPoint) { |
|
66
|
2 |
|
$this->addCommandArgument($name); |
|
67
|
2 |
|
$this->addCommandSubject($startPoint); |
|
68
|
|
|
} else { |
|
69
|
26 |
|
$this->addCommandSubject($name); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
27 |
|
return $this->getCommand(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Lists tags |
|
77
|
|
|
* |
|
78
|
|
|
* @throws \RuntimeException |
|
79
|
|
|
* @return string the command |
|
80
|
|
|
*/ |
|
81
|
28 |
|
public function listTags(): string |
|
82
|
|
|
{ |
|
83
|
28 |
|
$this->clearAll(); |
|
84
|
28 |
|
$this->addCommandName(self::TAG_COMMAND); |
|
85
|
|
|
|
|
86
|
28 |
|
return $this->getCommand(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Lists tags |
|
91
|
|
|
* |
|
92
|
|
|
* @deprecated This method uses an unconventional name but is being left in |
|
93
|
|
|
* place to remain compatible with existing code relying on it. |
|
94
|
|
|
* New code should be written to use listTags(). |
|
95
|
|
|
* |
|
96
|
|
|
* @throws \RuntimeException |
|
97
|
|
|
* @return string the command |
|
98
|
|
|
*/ |
|
99
|
|
|
public function lists(): string |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->listTags(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Delete a tag |
|
106
|
|
|
* |
|
107
|
|
|
* @param string|Tag $tag The name of tag, or the Tag instance to delete |
|
108
|
|
|
* |
|
109
|
|
|
* @throws \RuntimeException |
|
110
|
|
|
* @return string the command |
|
111
|
|
|
*/ |
|
112
|
1 |
|
public function delete($tag): string |
|
113
|
|
|
{ |
|
114
|
1 |
|
$this->clearAll(); |
|
115
|
1 |
|
$this->addCommandName(self::TAG_COMMAND); |
|
116
|
|
|
|
|
117
|
1 |
|
$name = $tag; |
|
118
|
1 |
|
if ($tag instanceof Tag) { |
|
119
|
1 |
|
$name = $tag->getName(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
1 |
|
$this->addCommandArgument('-d'); |
|
123
|
1 |
|
$this->addCommandSubject($name); |
|
|
|
|
|
|
124
|
|
|
|
|
125
|
1 |
|
return $this->getCommand(); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.