Passed
Push — master ( 195aeb...469104 )
by Romain
36s
created

ProfileRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
namespace Kerox\Messenger\Request;
3
4
use Kerox\Messenger\Model\ProfileSettings;
5
6
class ProfileRequest extends AbstractRequest
7
{
8
9
    /**
10
     * @var mixed
11
     */
12
    protected $profileSettings;
13
14
    /**
15
     * ProfileRequest constructor.
16
     *
17
     * @param string $pageToken
18
     * @param mixed $profileSettings
19
     */
20 2
    public function __construct(string $pageToken, $profileSettings)
21
    {
22 2
        parent::__construct($pageToken);
23
24 2
        $this->profileSettings = $profileSettings;
25 2
    }
26
27
    /**
28
     * @return null|array
29
     */
30 2
    protected function buildHeaders()
31
    {
32
        $headers = [
33 2
            'Content-Type' => 'application/json',
34
        ];
35
36 2
        return (is_string($this->profileSettings)) ? null : $headers;
37
    }
38
39
    /**
40
     * @return null|array|\Kerox\Messenger\Model\ProfileSettings
41
     */
42 2
    protected function buildBody()
43
    {
44 2
        $body = null;
45 2
        if ($this->profileSettings instanceof ProfileSettings) {
46 1
            $body = $this->profileSettings;
47 1
        } elseif (is_array($this->profileSettings)) {
48
            $body = [
49
                'fields' => $this->profileSettings
50
            ];
51
        }
52
53 2
        return $body;
54
    }
55
56
    /**
57
     * @return array
58
     */
59 2
    protected function buildQuery(): array
60
    {
61 2
        $query = parent::buildQuery();
62
63 2
        if (is_string($this->profileSettings)) {
64
            $query += [
65 1
                'fields' => $this->profileSettings
66
            ];
67
        }
68
69 2
        return $query;
70
    }
71
}
72