Test Failed
Pull Request — master (#74)
by
unknown
08:19
created

MessageEcho::getAppId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Kerox\Messenger\Model\Callback;
4
5
class MessageEcho extends Message
6
{
7
    /**
8
     * @var bool
9
     */
10
    protected $isEcho;
11
12
    /**
13
     * @var null|int
14
     */
15
    protected $appId;
16
17
    /**
18
     * @var null|string
19
     */
20
    protected $metadata;
21
22
    /**
23
     * MessageEcho constructor.
24
     *
25
     * @param bool        $isEcho
26
     * @param null|int    $appId
27
     * @param string      $messageId
28
     * @param int         $sequence
29
     * @param string|null $metadata
30
     * @param string|null $text
31
     * @param string|null $quickReply
32
     * @param array       $attachments
33
     */
34
    public function __construct(
35
        bool $isEcho,
36
        $appId,
37
        string $messageId,
38
        int $sequence,
39
        string $metadata = null,
40
        string $text = null,
41
        string $quickReply = null,
42
        array $attachments = []
43
    ) {
44
        parent::__construct($messageId, $sequence, $text, $quickReply, $attachments);
0 ignored issues
show
Documentation introduced by
$text is of type null|string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$attachments is of type array, but the function expects a null|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
46
        $this->isEcho = $isEcho;
47
        $this->appId = $appId;
48
        $this->metadata = $metadata;
49
    }
50
51
    /**
52
     * @return bool
53
     */
54
    public function isEcho(): bool
55
    {
56
        return $this->isEcho;
57
    }
58
59
    /**
60
     * @return null|int
61
     */
62
    public function getAppId()
63
    {
64
        return $this->appId;
65
    }
66
67
    /**
68
     * @return null|string
69
     */
70
    public function getMetadata()
71
    {
72
        return $this->metadata;
73
    }
74
75
    /**
76
     * @param array $callbackData
77
     *
78
     * @return \Kerox\Messenger\Model\Callback\MessageEcho
79
     */
80
    public static function create(array $callbackData)
81
    {
82
        $appId = $callbackData['app_id'] ?? null;
83
        $metadata = $callbackData['metadata'] ?? null;
84
        $text = $callbackData['text'] ?? null;
85
        $quickReply = $callbackData['quick_reply']['payload'] ?? null;
86
        $attachments = $callbackData['attachments'] ?? [];
87
88
        return new static(true, $appId, $callbackData['mid'], $callbackData['seq'], $metadata, $text, $quickReply, $attachments);
89
    }
90
}
91