Completed
Push — develop ( 90d434...5a25e9 )
by Michael
02:38
created

StringConverter::convert()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Crummy\Phlack\WebHook\Converter;
4
5
use Crummy\Phlack\WebHook\SlashCommand;
6
use Crummy\Phlack\WebHook\WebHook;
7
8
class StringConverter implements ConverterInterface
9
{
10
    protected $webHook = [
11
        'token'        => '',
12
        'team_id'      => '',
13
        'team_domain'  => '',
14
        'service_id'   => '',
15
        'channel_id'   => '',
16
        'channel_name' => '',
17
        'timestamp'    => 0.000000,
18
        'user_id'      => '',
19
        'user_name'    => '',
20
    ];
21
22
    protected $slashCommand = [
23
        'token'        => '',
24
        'team_id'      => '',
25
        'channel_id'   => '',
26
        'channel_name' => '',
27
        'user_id'      => '',
28
        'user_name'    => '',
29
    ];
30
31
    /**
32
     * @param $command
33
     *
34
     * @return \Crummy\Phlack\WebHook\CommandInterface
35
     */
36 2
    public function convert($command)
37
    {
38 2
        if (0 !== strpos($command, '/')) {
39 1
            return new WebHook(['text' => $command] + $this->webHook);
40
        } else {
41 1
            list($command, $text) = explode(' ', $command, 2);
42
43 1
            return new SlashCommand(['command' => $command, 'text' => $text] + $this->slashCommand);
44
        }
45
    }
46
}
47