Completed
Push — master ( ae6482...598fcc )
by Mark
01:22
created

Xhgui_Saver_Upload   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A save() 0 21 1
1
<?php
2
3
class Xhgui_Saver_Upload implements Xhgui_Saver_Interface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
    protected $uri;
7
8
    public function __construct($uri)
9
    {
10
        $this->uri = $uri;
11
    }
12
13
    public function save($data)
14
    {
15
        $json = json_encode($data);
16
17
        $ch = curl_init($this->uri);
18
19
        $headers = array(
20
            'Accept: application/json',         // Prefer to receive JSON back
21
            'Content-Type: application/json'    // The sent data is JSON
22
        );
23
24
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
25
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
26
        curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
27
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
28
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
29
30
        curl_exec($ch);
31
32
        curl_close($ch);
33
    }
34
}
35