Completed
Push — master ( 24c6fe...cc1b0b )
by Edgar
02:01
created

CurlWrapper::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.576

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 5
cp 0.6
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 2
nop 2
crap 3.576
1
<?php
2
namespace nstdio\notymo;
3
4
/**
5
 * Class CurlWrapper
6
 *
7
 * @package nstdio\notymo
8
 * @author  Edgar Asatryan <[email protected]>
9
 */
10
class CurlWrapper implements Connection
11
{
12
    /**
13
     * @var resource
14
     */
15
    private $stream;
16
17 1
    public function __construct(array $params = array(), $socketAddress = null)
18
    {
19 1
        if (!empty($params) && $socketAddress !== null) {
20
            $this->open($params, $socketAddress);
21
        }
22 1
    }
23
24
    public function open(array $params, $socketAddress)
25
    {
26
        $this->stream = curl_init($socketAddress);
27
28
        curl_setopt_array($this->stream, $params);
29
30
        return $this;
31
    }
32
33
    public function write($option, $string)
34
    {
35
        curl_setopt($this->stream, $option, $string);
36
    }
37
38
    public function close()
39
    {
40
        if (is_resource($this->stream)) {
41
            curl_close($this->stream);
42
        }
43
    }
44
45
    public function read()
46
    {
47
        return curl_exec($this->stream);
48
    }
49
}