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

SharepCommandProcessor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 35
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A process() 0 11 3
A getTaskProcessors() 0 8 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