Sequencer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 5
c 3
b 2
f 0
lcom 1
cbo 0
dl 0
loc 51
ccs 11
cts 11
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 4 1
A alert() 0 4 1
A sequence() 0 6 2
A command() 0 7 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