ProfileRequest::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

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