Curl   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A __call() 0 8 2
1
<?php
2
3
namespace BWC\Share\Net;
4
5
/**
6
 * Class to encapsulate PHP cUrl (curl_xxx) functions for unit tests
7
 */
8
class Curl
9
{
10
    private $handle;
11
12
    /**
13
     * Constructor stores cUrl handle in object
14
     * @throws \LogicException when php curl library is not installed
15
     */
16
    public function __construct() {
17
        if (!function_exists('curl_init')) {
18
            $class = get_class($this);
19
            throw new \LogicException("Class '$class' depends on the PHP cURL library that is currently not installed");
20
        }
21
        $this->handle = curl_init();
22
    }
23
24
    /**
25
     * Magic method to execute curl_xxx calls
26
     *
27
     * @param string $name      Method name (should be camelized)
28
     * @param array  $arguments Method arguments
29
     *
30
     * @return mixed
31
     * @throws \LogicException
32
     */
33
    public function __call($name, $arguments) {
34
        if (function_exists("curl_$name")) {
35
            array_unshift($arguments, $this->handle);
36
37
            return call_user_func_array("curl_$name", $arguments);
38
        }
39
        throw new \LogicException("Function 'curl_$name' do not exist, see PHP manual.");
40
    }
41
42
}