Completed
Push — master ( c63e30...778a07 )
by Ryota
05:20
created

LineMessage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 3
1
<?php
2
3
namespace NotificationChannels\Line;
4
5
use NotificationChannels\Line\Exceptions\CouldNotSendNotification;
6
use LINE\LINEBot\MessageBuilder\TextMessageBuilder;
7
8
class LineMessage implements TextMessageBuilder
9
{
10
    /** @var string[] */
11
    private $texts;
12
    /** @var array */
13
    private $message = [];
0 ignored issues
show
Unused Code introduced by
The property $message is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
14
15
    public function __construct($text, $extraTexts = null)
16
    {
17
        $extra = [];
18
        if (!is_null($extraTexts)) {
19
            $args = func_get_args();
20
            $extra = array_slice($args, 1);
21
        }
22
23
        if (count($extra) >= 4) {
24
            throw CouldNotSendNotification::exceededOfMessages(count($extra) + 1);
25
        }
26
27
        $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...
28
29
        $this->contents = $contents;
0 ignored issues
show
Bug introduced by
The property contents does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The variable $contents does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
30
    }
31
}
32