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.
Passed
Push — master ( 15ae56...645208 )
by Gallice
03:15
created

RequestOptionsFactory::createForTyping()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Tgallice\FBMessenger;
4
5
use GuzzleHttp\RequestOptions;
6
use Tgallice\FBMessenger\Model\Message;
7
8
class RequestOptionsFactory
9
{
10
11
	/**
12
     * @param $recipientOrPhone
13
     * @param $typingIndicator
14
     * @return mixed
15
     */
16
    public static function createForTyping($recipientOrPhone, $typingIndicator) {
17
        $options = [];
18
        $data = [
19
            'recipient'     => self::createRecipientField($recipientOrPhone),
20
            'sender_action' => $typingIndicator,
21
        ];
22
        $options[RequestOptions::JSON] = $data;
23
24
        return $options;
25
    }
26
27
    /**
28
     * @param string $recipientOrPhone
29
     * @param Message $message
30
     * @param string $notificationType
31
     *
32
     * @return array
33
     */
34 6
    public static function createForMessage($recipientOrPhone, Message $message, $notificationType = NotificationType::REGULAR)
35
    {
36 6
        $options = [];
37
        $data = [
38 6
            'recipient' => self::createRecipientField($recipientOrPhone),
39 6
            'message' => $message,
40 6
            'notification_type' => $notificationType,
41 6
        ];
42
        
43 6
        if ($message->hasFileToUpload()) {
44
45
            // Create a multipart request
46 1
            $options[RequestOptions::MULTIPART] = [
47
                [
48 1
                    'name' => 'recipient',
49 1
                    'contents' => json_encode($data['recipient']),
50 1
                ],
51
                [
52 1
                    'name' => 'message',
53 1
                    'contents' => json_encode($data['message']),
54 1
                ],
55
                [
56 1
                    'name' => 'notification_type',
57 1
                    'contents' => $data['notification_type'],
58 1
                ],
59
                [
60 1
                    'name' => 'filedata',
61 1
                    'contents' => $message->getFileStream(),
62 1
                ],
63
            ];
64
65
            // Update timeout if we upload a file
66 1
            $options['timeout'] = Client::DEFAULT_FILE_UPLOAD_TIMEOUT;
67
68 1
            return $options;
69
        }
70
71 5
        $options[RequestOptions::JSON] = $data;
72
73 5
        return $options;
74
    }
75
76 8
    public static function createRecipientField($recipientOrPhone)
77
    {
78 8
        $recipientFieldName = strpos($recipientOrPhone, '+') === 0 ? 'phone_number' : 'id';
79
80 8
        return [$recipientFieldName => $recipientOrPhone];
81
    }
82
}
83