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

CurlWrapper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 15.79%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 40
ccs 3
cts 19
cp 0.1579
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A open() 0 8 1
A write() 0 4 1
A close() 0 6 2
A read() 0 4 1
A __construct() 0 6 3
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
}