Sequencer::alert()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Crummy\Phlack\Common\Formatter;
4
5
use Crummy\Phlack\WebHook\CommandInterface;
6
7
class Sequencer implements FormatterInterface
8
{
9
    const SEQUENCE = '<%s>';
10
11
    /**
12
     * @param string $text  The text to be sequenced
13
     * @param string $label An optional label
14
     *
15
     * @return string
16
     */
17 3
    public function format($text, $label = null)
18
    {
19 3
        return $this->sequence($text, $label);
0 ignored issues
show
Bug introduced by
It seems like $label defined by parameter $label on line 17 can also be of type string; however, Crummy\Phlack\Common\For...r\Sequencer::sequence() does only seem to accept null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
20
    }
21
22
    /**
23
     * @param string $text
24
     * @param null   $label
25
     *
26
     * @return string
27
     */
28 12
    public static function sequence($text, $label = null)
29
    {
30 12
        $text = $label ? $text.'|'.$label : $text;
31
32 12
        return sprintf(static::SEQUENCE, $text);
33
    }
34
35
    /**
36
     * @param CommandInterface $command
37
     *
38
     * @return array
39
     */
40 6
    public static function command(CommandInterface $command)
41
    {
42
        return [
43 6
            'channel'   => self::sequence('#'.$command['channel_id'], $command['channel_name']),
44 6
            'user'      => self::sequence('@'.$command['user_id'], $command['user_name']),
45 6
        ];
46
    }
47
48
    /**
49
     * @param string $channel
50
     *
51
     * @return string
52
     */
53 3
    public static function alert($channel)
54
    {
55 3
        return self::sequence('!'.$channel);
56
    }
57
}
58