Test Setup Failed
Pull Request — master (#2)
by Solo
02:21 queued 10s
created

RequestorTrait::put()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
namespace mpyw\Cowitter\Traits;
4
5
use mpyw\Co\CoInterface;
6
use mpyw\Co\CURLException;
7
use mpyw\Cowitter\Components\StreamHandler;
8
use mpyw\Cowitter\Helpers\CurlExecutor;
9
10
trait RequestorTrait
11
{
12
    abstract protected function getInternalCurl();
13
14
    public function getAsync($endpoint, array $params = [], $return_response_object = false)
15
    {
16
        yield CoInterface::RETURN_WITH => (yield CurlExecutor::execDecodedAsync($this->getInternalCurl()->get($endpoint, $params), $return_response_object));
17
        // @codeCoverageIgnoreStart
18
    }
19
    // @codeCoverageIgnoreEnd
20
21
    public function postAsync($endpoint, array $params = [], $return_response_object = false)
22
    {
23
        yield CoInterface::RETURN_WITH => (yield CurlExecutor::execDecodedAsync($this->getInternalCurl()->post($endpoint, $params), $return_response_object));
24
        // @codeCoverageIgnoreStart
25
    }
26
    // @codeCoverageIgnoreEnd
27
28
    public function deleteAsync($endpoint, array $params = [], $return_response_object = false)
29
    {
30
        yield CoInterface::RETURN_WITH => (yield CurlExecutor::execDecodedAsync($this->getInternalCurl()->delete($endpoint, $params), $return_response_object));
31
        // @codeCoverageIgnoreStart
32
    }
33
    // @codeCoverageIgnoreEnd
34
35
    public function putAsync($endpoint, array $params = [], $return_response_object = false)
36
    {
37
        yield CoInterface::RETURN_WITH => (yield CurlExecutor::execDecodedAsync($this->getInternalCurl()->put($endpoint, $params), $return_response_object));
38
        // @codeCoverageIgnoreStart
39
    }
40
    // @codeCoverageIgnoreEnd
41
42
    public function postMultipartAsync($endpoint, array $params = [], $return_response_object = false)
43
    {
44
        yield CoInterface::RETURN_WITH => (yield CurlExecutor::execDecodedAsync($this->getInternalCurl()->postMultipart($endpoint, $params), $return_response_object));
45
        // @codeCoverageIgnoreStart
46
    }
47
    // @codeCoverageIgnoreEnd
48
49
    public function get($endpoint, array $params = [], $return_response_object = false)
50
    {
51
        return CurlExecutor::execDecoded($this->getInternalCurl()->get($endpoint, $params), $return_response_object);
52
    }
53
54
    public function post($endpoint, array $params = [], $return_response_object = false)
55
    {
56
        return CurlExecutor::execDecoded($this->getInternalCurl()->post($endpoint, $params), $return_response_object);
57
    }
58
59
    public function delete($endpoint, array $params = [], $return_response_object = false)
60
    {
61
        return CurlExecutor::execDecoded($this->getInternalCurl()->delete($endpoint, $params), $return_response_object);
62
    }
63
64
    public function put($endpoint, array $params = [], $return_response_object = false)
65
    {
66
        return CurlExecutor::execDecoded($this->getInternalCurl()->put($endpoint, $params), $return_response_object);
67
    }
68
69
    public function postMultipart($endpoint, array $params = [], $return_response_object = false)
70
    {
71
        return CurlExecutor::execDecoded($this->getInternalCurl()->postMultipart($endpoint, $params), $return_response_object);
72
    }
73
74
    public function streamingAsync($endpoint, callable $event_handler, array $params = [], callable $header_response_handler = null)
75
    {
76
        $handler = new StreamHandler($header_response_handler, $event_handler);
77
        $ch = $this->getInternalCurl()->streaming($endpoint, $params, $handler);
78
        try {
79
            yield $ch;
80
        } catch (CURLException $e) {
0 ignored issues
show
Unused Code introduced by
catch (\mpyw\Co\CURLExce... throw $e; } } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
81
            if (!$handler->isHaltedByUser()) {
82
                throw $e;
83
            }
84
        }
85
        if (!$handler->isHaltedByUser()) {
86
            throw new \UnexpectedValueException('Streaming stopped unexpectedly.');
87
        }
88
    }
89
90
    public function streaming($endpoint, callable $event_handler, array $params = [], callable $header_response_handler = null)
91
    {
92
        $handler = new StreamHandler($header_response_handler, $event_handler);
93
        $ch = $this->getInternalCurl()->streaming($endpoint, $params, $handler);
94
        $result = curl_exec($ch);
95
        if (!$handler->isHaltedByUser() && $result === false) {
96
            throw new CURLException(curl_error($ch), curl_errno($ch), $ch);
97
        }
98
        if (!$handler->isHaltedByUser()) {
99
            throw new \UnexpectedValueException('Streaming stopped unexpectedly.');
100
        }
101
    }
102
103
    public function getOutAsync($endpoint, array $params = [], $return_response_object = false)
104
    {
105
        yield CoInterface::RETURN_WITH => (yield CurlExecutor::execDecodedAsync($this->getInternalCurl()->getOut($endpoint, $params), $return_response_object));
106
        // @codeCoverageIgnoreStart
107
    }
108
    // @codeCoverageIgnoreEnd
109
110
    public function postOutAsync($endpoint, array $params = [], $return_response_object = false)
111
    {
112
        yield CoInterface::RETURN_WITH => (yield CurlExecutor::execDecodedAsync($this->getInternalCurl()->postOut($endpoint, $params), $return_response_object));
113
        // @codeCoverageIgnoreStart
114
    }
115
    // @codeCoverageIgnoreEnd
116
117
    public function postMultipartOutAsync($endpoint, array $params = [], $return_response_object = false)
118
    {
119
        yield CoInterface::RETURN_WITH => (yield CurlExecutor::execDecodedAsync($this->getInternalCurl()->postMultipartOut($endpoint, $params), $return_response_object));
120
        // @codeCoverageIgnoreStart
121
    }
122
    // @codeCoverageIgnoreEnd
123
124
    public function getOut($endpoint, array $params = [], $return_response_object = false)
125
    {
126
        return CurlExecutor::execDecoded($this->getInternalCurl()->getOut($endpoint, $params), $return_response_object);
127
    }
128
129
    public function postOut($endpoint, array $params = [], $return_response_object = false)
130
    {
131
        return CurlExecutor::execDecoded($this->getInternalCurl()->postOut($endpoint, $params), $return_response_object);
132
    }
133
134
    public function postMultipartOut($endpoint, array $params = [], $return_response_object = false)
135
    {
136
        return CurlExecutor::execDecoded($this->getInternalCurl()->postMultipartOut($endpoint, $params), $return_response_object);
137
    }
138
}
139