Passed
Push — master ( 565c41...d8e277 )
by Frank
02:13
created

ForgeCommand::processShow()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 12
cts 12
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 12
nc 6
nop 0
crap 4
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
     * @param array|null $configuration
29
     */
30 9 View Code Duplication
    public function __construct(Payload $payload, RealTimeClient $client, array $configuration = null)
31
    {
32 9
        $this->commandName = 'forge';
33 9
        $this->helpCommands = [
34
            'help' => 'shows this help',
35
            'show [Issue-ID]' => 'shows the issue by given [Issue-ID]',
36
        ];
37 9
        parent::__construct($payload, $client, $configuration);
38 9
    }
39
40
    /**
41
     * process show.
42
     *
43
     * @return string
44
     */
45 8
    protected function processShow() : string
46
    {
47 8
        $urlPattern = '/http[s]*:\/\/forge.typo3.org\/issues\/([\d]*)(?:.*)/i';
48 8
        $value = $this->params[1] ?? 0;
49 8
        if (preg_match_all($urlPattern, $value, $matches) > 0) {
50 4
            $issueNumber = (int) $matches[1][0];
51
        }
52 8
        $issueNumber = $issueNumber ?? $value;
53 8
        if ((int)$issueNumber === 0) {
54 2
            return 'hey, I need an issue number!';
55
        }
56 6
        $result = $this->queryForge("issues/{$issueNumber}");
57 6
        if ($result) {
58 5
            return $this->buildIssueMessage($result->issue);
59
        }
60 1
        return 'Sorry not found!';
61
    }
62
}
63