Completed
Push — master ( 06ea43...041713 )
by Ryota
07:46
created

LineMessage   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A buildMessage() 0 13 3
1
<?php
2
3
namespace NotificationChannels\Line;
4
5
use LINE\LINEBot\Constant\MessageType;
6
use LINE\LINEBot\MessageBuilder;
7
use NotificationChannels\Line\Exceptions\CouldNotSendNotification;
8
9
class LineMessage implements MessageBuilder
10
{
11
    /** @var string[] */
12
    private $texts;
13
    /** @var array */
14
    private $message = [];
15
16
    public function __construct($text, $extraTexts = null)
17
    {
18
        $extra = [];
19
        if (! is_null($extraTexts)) {
20
            $args = func_get_args();
21
            $extra = array_slice($args, 1);
22
        }
23
24
        if (count($extra) >= 4) {
25
            throw CouldNotSendNotification::exceededOfMessages(count($extra) + 1);
26
        }
27
28
        $this->texts = array_merge([$text], $extra);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_merge(array($text), $extra) of type array is incompatible with the declared type array<integer,string> of property $texts.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
29
    }
30
31
    /**
32
     * Builds text message structure.
33
     */
34
    public function buildMessage() : array
35
    {
36
        if (!empty($this->message)) {
37
            return $this->message;
38
        }
39
        foreach ($this->texts as $text) {
40
            $this->message[] = [
41
                'type' => MessageType::TEXT,
42
                'text' => $text,
43
            ];
44
        }
45
        return $this->message;
46
    }
47
}
48