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 (#9)
by Gallice
03:41 queued 55s
created

RequestOptionsFactory::createForMessage()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 41
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 2

Importance

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