Completed
Pull Request — master (#51)
by Romain
02:30 queued 18s
created

ProfileRequest::buildBody()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

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