Failed Conditions
Push — master ( 37c7e1...8f957f )
by Zbigniew
05:34
created

SharepCommandProcessor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the zibios/sharep.
7
 *
8
 * (c) Zbigniew Ślązak
9
 */
10
11
namespace App\Slack\SlashCommand\Sharep;
12
13
use App\Slack\MessageBuilder\Layout;
14
use App\Slack\SlashCommand\CommandData;
15
use App\Slack\SlashCommand\CommandProcessorInterface;
16
use App\Slack\SlashCommand\TaskProcessorInterface;
17
18
class SharepCommandProcessor implements CommandProcessorInterface
19
{
20
    public const COMMAND = '/sharep';
21
    /** @var SharepReleaseTaskProcessor */
22
    private $releaseTaskProcessor;
23
    /** @var SharepHelpMessage */
24
    private $sharepHelpMessage;
25
26 3
    public function __construct(SharepReleaseTaskProcessor $releaseTaskProcessor, SharepHelpMessage $sharepHelpMessage)
27
    {
28 3
        $this->releaseTaskProcessor = $releaseTaskProcessor;
29 3
        $this->sharepHelpMessage = $sharepHelpMessage;
30 3
    }
31
32 2
    public function process(CommandData $commandData): Layout
33
    {
34
        /** @var TaskProcessorInterface $taskProcessor */
35 2
        foreach ($this->getTaskProcessors() as $taskProcessor) {
36 2
            if ($taskProcessor->supports($commandData)) {
37 1
                return $taskProcessor->process($commandData);
38
            }
39
        }
40
41 1
        return $this->sharepHelpMessage->generate();
42
    }
43
44 2
    private function getTaskProcessors(): array
45
    {
46
        $taskProcessors = [
47 2
            $this->releaseTaskProcessor,
48
        ];
49
50 2
        return $taskProcessors;
51
    }
52
}
53