Completed
Push — master ( d6f8f2...161f55 )
by Dan
01:36
created

GuzzleTrait::posttAsync()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Nopolabs\Yabot\Helpers;
4
5
6
use GuzzleHttp\Promise\PromiseInterface;
7
use Nopolabs\Yabot\Guzzle\Guzzle;
8
use Psr\Http\Message\ResponseInterface;
9
10
trait GuzzleTrait
11
{
12
    /** @var Guzzle */
13
    private $guzzle;
14
15
    /** @var array */
16
    private $options = [];
17
18
    public function setGuzzle(Guzzle $guzzle)
19
    {
20
        $this->guzzle = $guzzle;
21
    }
22
23
    public function getGuzzle() : Guzzle
24
    {
25
        return $this->guzzle;
26
    }
27
28
    public function setOptions(array $options)
29
    {
30
        $this->options = $options;
31
    }
32
33
    public function getOptions() : array
34
    {
35
        return $this->options;
36
    }
37
38
    public function getAsync(string $uri, array $options = []) : PromiseInterface
39
    {
40
        $options = $this->addOptions($options);
41
42
        return $this->getGuzzle()->getAsync($uri, $options);
43
    }
44
45
    public function posttAsync(string $uri, array $options = []) : PromiseInterface
46
    {
47
        $options = $this->addOptions($options);
48
49
        return $this->getGuzzle()->postAsync($uri, $options);
50
    }
51
52
    public function post(string $uri, array $options = []) : ResponseInterface
53
    {
54
        $options = $this->addOptions($options);
55
56
        return $this->getGuzzle()->post($uri, $options);
57
    }
58
59
    private function addOptions(array $options) : array
60
    {
61
        return array_merge($options, $this->getOptions());
62
    }
63
}