Completed
Push — master ( 72cf95...b4fc03 )
by Artem
08:38
created

HttpClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
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
    private const DEFAULT_GUZZLE_TIMEOUT = 50;
26
27
    /**
28
     * @param string $serverKey
29
     * @param string $endpoint
30
     * @param int    $guzzleTimeOut
31
     */
32
    public function __construct(string $serverKey, string $endpoint = self::DEFAULT_ENDPOINT, int $guzzleTimeOut = self::DEFAULT_GUZZLE_TIMEOUT)
33
    {
34
        $options = [
35
            'base_uri' => \rtrim($endpoint, '/'),
36
            'timeout' => $guzzleTimeOut,
37
            'http_errors' => false,
38
            'headers' => [
39
                'Authorization' => \sprintf('key=%s', $serverKey),
40
                'Content-Type' => 'application/json',
41
            ],
42
        ];
43
44
        parent::__construct($options);
45
    }
46
}
47