Passed
Push — master ( f115d8...f636e9 )
by Romain
04:41
created

ProfileRequest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 66
ccs 18
cts 19
cp 0.9474
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A buildHeaders() 0 8 2
A buildQuery() 0 12 2
A buildBody() 0 13 3
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