Completed
Pull Request — master (#129)
by
unknown
02:29
created

ProfileRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 3
cts 3
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 string $pageToken
20
     * @param mixed  $profileSettings
21
     */
22 3
    public function __construct(string $pageToken, $profileSettings)
23
    {
24 3
        parent::__construct($pageToken);
25
26 3
        $this->profileSettings = $profileSettings;
27 3
    }
28
29
    /**
30
     * @return null|array
31
     */
32 3
    protected function buildHeaders(): ?array
33
    {
34
        $headers = [
35 3
            'Content-Type' => 'application/json',
36
        ];
37
38 3
        return \is_string($this->profileSettings) ? null : $headers;
39
    }
40
41
    /**
42
     * @return null|array|\Kerox\Messenger\Model\ProfileSettings
43
     */
44 3
    protected function buildBody()
45
    {
46 3
        $body = null;
47 3
        if ($this->profileSettings instanceof ProfileSettings) {
48 1
            $body = $this->profileSettings;
49 2
        } elseif (\is_array($this->profileSettings)) {
50
            $body = [
51 1
                'fields' => $this->profileSettings,
52
            ];
53
        }
54
55 3
        return $body;
56
    }
57
58
    /**
59
     * @return array
60
     */
61 3
    protected function buildQuery(): array
62
    {
63 3
        $query = parent::buildQuery();
64
65 3
        if (\is_string($this->profileSettings)) {
66
            $query += [
67 1
                'fields' => $this->profileSettings,
68
            ];
69
        }
70
71 3
        return $query;
72
    }
73
}
74