OnlineTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A reguestGet() 0 19 3
getUri() 0 1 ?
1
<?php
2
/**
3
 *
4
 * PHP version 5.5
5
 *
6
 * @package TTS\Traits
7
 * @author  Sergey V.Kuzin <[email protected]>
8
 * @license MIT
9
 */
10
11
namespace TTS\Traits;
12
13
14
use GuzzleHttp\Exception\RequestException;
15
16
trait OnlineTrait
17
{
18
19
    protected $debug = false;
20
21
    public function reguestGet($params)
22
    {
23
        $headers = [
24
            'User-Agent'    => 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.872.0 Safari/535.2'
25
        ];
26
27
        $this->client = new \GuzzleHttp\Client();
0 ignored issues
show
Bug introduced by
The property client does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
29
        try {
30
            $response = $this->client->get($this->getUri(), ['debug' => $this->debug, 'query' => $params, 'headers' => $headers]);
31
        } catch (RequestException $e) {
32
            echo $e->getMessage();
33
34
            if ($e->hasResponse()) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
35
            }
36
            die('error');
0 ignored issues
show
Coding Style Compatibility introduced by
The method reguestGet() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
37
        }
38
        return $response->getBody()->getContents();
39
    }
40
41
    /**
42
     * Uri до сервера конвертации
43
     *
44
     * @return string
45
     */
46
    abstract protected function getUri();
47
}
48