Completed
Push — master ( 79dd3c...f666f7 )
by
unknown
10s
created

Get   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 0
dl 0
loc 62
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getEndpoint() 0 4 1
A getMethod() 0 4 1
A getParams() 0 8 2
A getContentType() 0 4 1
1
<?php
2
3
namespace Xsolve\SalesforceClient\Request;
4
5
use Xsolve\SalesforceClient\Enum\AbstractSObjectType;
6
use Xsolve\SalesforceClient\Enum\ContentType;
7
use Xsolve\SalesforceClient\Enum\RequestMethod;
8
9
class Get implements RequestInterface
10
{
11
    const ENDPOINT = '/sobjects/%s/%s/';
12
13
    /**
14
     * @var AbstractSObjectType
15
     */
16
    protected $objectType;
17
18
    /**
19
     * @var string
20
     */
21
    protected $id;
22
23
    /**
24
     * @var array
25
     */
26
    protected $params;
27
28 3
    public function __construct(AbstractSObjectType $objectType, string $id, array $params = [])
29
    {
30 3
        $this->objectType = $objectType;
31 3
        $this->id = $id;
32 3
        $this->params = $params;
33 3
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 2
    public function getEndpoint(): string
39
    {
40 2
        return sprintf(self::ENDPOINT, $this->objectType->value(), $this->id);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 2
    public function getMethod(): RequestMethod
47
    {
48 2
        return RequestMethod::GET();
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 2
    public function getParams(): array
55
    {
56 2
        if (empty($this->params)) {
57 1
            return [];
58
        }
59
60 1
        return ['fields' => implode(',', $this->params)];
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 2
    public function getContentType(): ContentType
67
    {
68 2
        return ContentType::FORM();
69
    }
70
}
71