GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#8)
by
unknown
04:06
created

Message::getQuickReplies()   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 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Tgallice\FBMessenger\Message;
4
5
use Tgallice\FBMessenger\Attachment;
6
use Tgallice\FBMessenger\Attachment\Image;
7
use Tgallice\FBMessenger\NotificationType;
8
9
class Message
10
{
11
    public static $recipient_value_type = 'id';
12
13
    /**
14
     * @var string
15
     */
16
    private $recipient;
17
18
    /**
19
     * @var string|Attachment
20
     */
21
    private $messageData;
22
23
    /**
24
     * @var array
25
     */
26
    private $quickReplies;
27
    
28
    /**
29
     * @var string
30
     */
31
    private $notificationType;
32
33 9
    /**
34
     * @param string $recipientId Recipient Id
35 9
     * @param string|Attachment $messageData
36
     * @param array $quickReplies
37 9
     * @param string $notificationType
38 1
     */
39
    public function __construct($recipientId, $messageData, array $quickReplies = null, $notificationType = NotificationType::REGULAR)
40
    {
41 8
        $this->recipient = $recipientId;
42 8
43 8
        if (is_string($messageData) && mb_strlen($messageData) > 320) {
44
            throw new \InvalidArgumentException('The text message should not exceed 320 characters');
45
        }
46
47
        if(count($quickReplies) > 10) {
48 1
        	throw new \InvalidArgumentException('The quick replies should not exceed 10 elements');
49
        }
50 1
        
51
        $this->messageData = $messageData;
52
        $this->quickReplies = $quickReplies;
0 ignored issues
show
Documentation Bug introduced by
It seems like $quickReplies can be null. However, the property $quickReplies is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

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

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
53
        $this->notificationType = $notificationType;
54
    }
55
56 2
    /**
57
     * @return string
58 2
     */
59
    public function getRecipient()
60
    {
61
        return $this->recipient;
62
    }
63
64
    /**
65
     * @return string|Attachment
66
     */
67
    public function getMessageData()
68
    {
69
        return $this->messageData;
70
    }
71
    
72 3
    /**
73
     * @return array
74 3
     */
75
    public function getQuickReplies()
76
    {
77
    	return $this->quickReplies;
78
    }
79
80
    /**
81
     * @return string
82 2
     */
83
    public function getNotificationType()
84 2
    {
85
        return $this->notificationType;
86
    }
87
88 2
    /**
89 2
     * @return bool
90
     */
91 2
    public function hasFileToUpload()
92 2
    {
93 2
        return $this->messageData instanceof Image && !$this->messageData->isRemoteFile();
94 2
    }
95
96
    /**
97
     * Return the formatted message
98
     *
99
     * @return array
100
     */
101
    public function format()
102
    {
103
        $messageType = is_string($this->messageData) ? 'text' : 'attachment';
104
        
105
		$return = [
106
            'recipient' => [
107
                $this::$recipient_value_type => $this->recipient,
108
            ],
109
            'message' => [
110
                $messageType => $this->messageData,
111
            ],
112
            'notification_type' => $this->notificationType,
113
        ];
114
		
115
		if($messageType === 'text' && count($this->quickReplies) > 0) {
116
			$return['quick_replies'] = $this->quickReplies;
117
		}
118
		
119
		return $return;
120
    }
121
}
122