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

GuzzleTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 54
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setGuzzle() 0 4 1
A getGuzzle() 0 4 1
A setOptions() 0 4 1
A getOptions() 0 4 1
A getAsync() 0 6 1
A posttAsync() 0 6 1
A post() 0 6 1
A addOptions() 0 4 1
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
}