HttpClient::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
/*
3
 * This file is part of the FirebaseCloudMessagingBundle.
4
 *
5
 * (c) Artem Henvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Fresh\FirebaseCloudMessagingBundle\Client;
14
15
use GuzzleHttp\Client as GuzzleClient;
16
17
/**
18
 * Class HttpClient.
19
 *
20
 * @author Artem Henvald <[email protected]>
21
 */
22
final class HttpClient extends GuzzleClient
23
{
24
    private const DEFAULT_ENDPOINT = 'https://fcm.googleapis.com/fcm/send';
25
26
    private const DEFAULT_GUZZLE_TIMEOUT = 50;
27
28
    /**
29
     * @param string $serverKey
30
     * @param string $endpoint
31
     * @param int    $guzzleTimeOut
32
     */
33
    public function __construct(string $serverKey, string $endpoint = self::DEFAULT_ENDPOINT, int $guzzleTimeOut = self::DEFAULT_GUZZLE_TIMEOUT)
34
    {
35
        $options = [
36
            'base_uri' => \rtrim($endpoint, '/'),
37
            'timeout' => $guzzleTimeOut,
38
            'http_errors' => false,
39
            'headers' => [
40
                'Authorization' => \sprintf('key=%s', $serverKey),
41
                'Content-Type' => 'application/json',
42
            ],
43
            'version' => 2.0,
44
        ];
45
46
        parent::__construct($options);
47
    }
48
}
49