|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* T3Bot. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Frank Nägler <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @link http://www.t3bot.de |
|
8
|
|
|
* @link http://wiki.typo3.org/T3Bot |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace T3Bot\Commands; |
|
11
|
|
|
|
|
12
|
|
|
use Slack\Payload; |
|
13
|
|
|
use Slack\RealTimeClient; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class ForgeCommand. |
|
17
|
|
|
* |
|
18
|
|
|
* @property string commandName |
|
19
|
|
|
* @property array helpCommands |
|
20
|
|
|
*/ |
|
21
|
|
|
class ForgeCommand extends AbstractCommand |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* AbstractCommand constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param Payload $payload |
|
27
|
|
|
* @param RealTimeClient $client |
|
28
|
|
|
*/ |
|
29
|
|
View Code Duplication |
public function __construct(Payload $payload, RealTimeClient $client) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$this->commandName = 'forge'; |
|
32
|
|
|
$this->helpCommands = [ |
|
33
|
|
|
'help' => 'shows this help', |
|
34
|
|
|
'show [Issue-ID]' => 'shows the issue by given [Issue-ID]', |
|
35
|
|
|
]; |
|
36
|
|
|
parent::__construct($payload, $client); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* process show. |
|
41
|
|
|
* |
|
42
|
|
|
* @return string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function processShow() : string |
|
45
|
|
|
{ |
|
46
|
|
|
$urlPattern = '/http[s]*:\/\/forge.typo3.org\/issues\/([\d]*)(?:.*)/i'; |
|
47
|
|
|
$issueNumber = !empty($this->params[1]) ? $this->params[1] : ''; |
|
48
|
|
|
if (preg_match_all($urlPattern, $issueNumber, $matches)) { |
|
49
|
|
|
$issueNumber = (int) $matches[1][0]; |
|
50
|
|
|
} else { |
|
51
|
|
|
$issueNumber = (int) $issueNumber; |
|
52
|
|
|
} |
|
53
|
|
|
if ($issueNumber === null || $issueNumber === 0) { |
|
54
|
|
|
return 'hey, I need an issue number!'; |
|
55
|
|
|
} |
|
56
|
|
|
$result = $this->queryForge("issues/{$issueNumber}"); |
|
57
|
|
|
if ($result) { |
|
58
|
|
|
return $this->buildIssueMessage($result->issue); |
|
59
|
|
|
} |
|
60
|
|
|
return 'Sorry not found!'; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
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.