UsageApi::getFieldsString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
1
<?php namespace Magestead\Service;
2
3
/**
4
 * Class UsageApi
5
 * @package Magestead\Service
6
 */
7
class UsageApi
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $_apiUrl = "https://api.magestead.com/v1/usage";
13
//    protected $_apiUrl = "http://magestead-api.app/v1/usage";
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
14
15
    /**
16
     * @var array
17
     */
18
    protected $_params = [];
19
20
    /**
21
     * UsageApi constructor.
22
     * @param $data
23
     */
24
    public function __construct($data)
25
    {
26
        $this->_params['os_type']               = urlencode($data['os']);
27
        $this->_params['server_type']           = urlencode($data['server']);
28
        $this->_params['php_version']           = urlencode($data['phpver']);
29
        $this->_params['application_version']   = urlencode($data['app']);
30
        $this->_params['vm_memory_limit']       = urlencode($data['memory_limit']);
31
        $this->_params['vm_cpu_count']          = urlencode($data['cpus']);
32
        $this->_params['ip_address']            = urlencode($data['ip_address']);
33
        $this->_params['box']                   = urlencode($data['box']);
34
        $this->_params['locale']                = urlencode($data['locale']);
35
        $this->_params['default_currency']      = urlencode($data['default_currency']);
36
    }
37
38
    /**
39
     *
40
     */
41
    public function send()
42
    {
43
        $fields_string = $this->getFieldsString();
44
45
        $ch = curl_init();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $ch. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
46
47
        curl_setopt($ch,CURLOPT_URL, $this->_apiUrl);
48
        curl_setopt($ch,CURLOPT_POST, count($this->_params));
49
        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
50
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
51
52
        $result = curl_exec($ch);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
53
54
        curl_close($ch);
55
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    protected function getFieldsString()
62
    {
63
        $fields_string = '';
64
        foreach ($this->_params as $key => $value) {
65
            $fields_string .= $key . '=' . $value . '&';
66
        }
67
        rtrim($fields_string, '&');
68
        return $fields_string;
69
    }
70
}