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 ( 645208...ecb3d3 )
by Gallice
03:07
created

RequestOptionsFactory::createForTyping()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

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