Completed
Pull Request — master (#3)
by Romain
01:47
created

MessageEcho::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
namespace Kerox\Messenger\Model\Callback;
3
4
class MessageEcho extends Message
5
{
6
7
    /**
8
     * @var bool
9
     */
10
    protected $isEcho;
11
12
    /**
13
     * @var 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 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
        int $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);
45
46
        $this->isEcho = $isEcho;
47
        $this->appId = $appId;
48
        $this->metadata = $metadata;
49
    }
50
51
    /**
52
     * @return boolean
53
     */
54
    public function isEcho(): bool
55
    {
56
        return $this->isEcho;
57
    }
58
59
    /**
60
     * @return int
61
     */
62
    public function getAppId(): int
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 $payload
77
     * @return static
78
     */
79
    public static function create(array $payload)
80
    {
81
        $metadata = $payload['metadata'] ?? null;
82
        $text = $payload['text'] ?? null;
83
        $quickReply = $payload['quick_reply']['payload'] ?? null;
84
        $attachments = $payload['attachments'] ?? [];
85
86
        return new static(true, $payload['app_id'], $payload['mid'], $payload['seq'], $metadata, $text, $quickReply, $attachments);
87
    }
88
}