GuzzleTrait   A
last analyzed

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
lcom 1
cbo 1
dl 0
loc 54
rs 10
c 0
b 0
f 0

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