Xhgui_Saver_Upload   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A save() 0 22 1
1
<?php
2
3
class Xhgui_Saver_Upload implements Xhgui_Saver_Interface
4
{
5
6
    protected $uri, $timeout;
7
8
    public function __construct($uri, $timeout)
9
    {
10
        $this->uri = $uri;
11
        $this->timeout = $timeout;
12
    }
13
14
    public function save(array $data)
15
    {
16
        $json = json_encode($data);
17
18
        $ch = curl_init($this->uri);
19
20
        $headers = array(
21
            'Accept: application/json',         // Prefer to receive JSON back
22
            'Content-Type: application/json'    // The sent data is JSON
23
        );
24
25
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
26
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
27
        curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
28
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
29
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
30
        curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
31
32
        curl_exec($ch);
33
34
        curl_close($ch);
35
    }
36
}
37