Completed
Push — master ( ab109e...49014d )
by Nikolay
03:44
created

AbstractRequest::getClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Korobovn\CloudPayments\Message\Request;
4
5
use Tarampampam\Wrappers\Json;
6
use Korobovn\CloudPayments\Client\CloudPaymentClientInterface;
7
use Korobovn\CloudPayments\Message\Response\ResponseInterface;
8
use Korobovn\CloudPayments\Message\Strategy\StrategyInterface;
9
use Korobovn\CloudPayments\Message\Request\Model\ModelInterface;
10
11
abstract class AbstractRequest implements RequestInterface
12
{
13
    /** @var string */
14
    protected $domain = 'https://api.cloudpayments.ru/';
15
16
    /** @var string */
17
    protected $url;
18
19
    /** @var ModelInterface */
20
    protected $model;
21
22
    /** @var StrategyInterface */
23
    protected $strategy;
24
25
    /** @var string */
26
    protected $method = 'POST';
27
28
    /** @var array */
29
    protected $headers = [
30
        'Content-Type' => 'application/json',
31
    ];
32
33
    /** @var CloudPaymentClientInterface */
34
    protected $client;
35
36
    /**
37
     * @return string
38
     */
39
    public function getUrl(): string
40
    {
41
        return rtrim($this->domain, '/') . '/' . ltrim($this->url, '/');
42
    }
43
44
    /**
45
     * @return ModelInterface
46
     */
47
    public function getModel(): ModelInterface
48
    {
49
        return $this->model;
50
    }
51
52
    /**
53
     * @return StrategyInterface
54
     */
55
    public function getStrategy(): StrategyInterface
56
    {
57
        return $this->strategy;
58
    }
59
60
    /**
61
     * @return string|null
62
     * @throws \Tarampampam\Wrappers\Exceptions\JsonEncodeDecodeException
63
     *
64
     */
65
    public function getBody(): ?string
66
    {
67
        return Json::encode($this->getModel()->toArray());
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getMethod(): string
74
    {
75
        return $this->method;
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    public function getHeaders(): array
82
    {
83
        return $this->headers;
84
    }
85
86
    /**
87
     * @param CloudPaymentClientInterface $client
88
     *
89
     * @return self
90
     */
91
    public function setClient(CloudPaymentClientInterface $client): self
92
    {
93
        $this->client = $client;
94
95
        return $this;
96
    }
97
98
    /**
99
     * @return ResponseInterface
100
     */
101
    public function send(): ResponseInterface
102
    {
103
        return $this->client->send($this);
104
    }
105
}
106