Passed
Pull Request — master (#109)
by Romain
03:30
created

ProfileRequest::buildBody()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

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