CurlWrapper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 49
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A open() 0 8 1
A write() 0 4 1
A close() 0 6 2
A read() 0 8 2
1
<?php
2
namespace nstdio\notymo;
3
4
use nstdio\notymo\exception\ConnectionException;
5
6
/**
7
 * Class CurlWrapper
8
 *
9
 * @package nstdio\notymo
10
 * @author  Edgar Asatryan <[email protected]>
11
 */
12
class CurlWrapper implements Connection
13
{
14
    /**
15
     * @var resource
16
     */
17
    private $stream;
18
19
    /**
20
     * @inheritdoc
21
     */
22 6
    public function open(array $params, $socketAddress)
23
    {
24 6
        $this->stream = curl_init($socketAddress);
25
26 6
        curl_setopt_array($this->stream, $params);
27
28 6
        return $this;
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34 5
    public function write($option, $string)
35
    {
36 5
        curl_setopt($this->stream, $option, $string);
37 5
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 6
    public function close()
43
    {
44 6
        if (is_resource($this->stream)) {
45 6
            curl_close($this->stream);
46 6
        }
47 6
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52 1
    public function read()
53
    {
54 1
        $response = curl_exec($this->stream);
55 1
        if ($response === false) {
56
            throw new ConnectionException(curl_error($this->stream), curl_errno($this->stream));
57
        }
58 1
        return $response;
59
    }
60
}