SoapCurl   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 43
ccs 0
cts 36
cp 0
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B send() 0 41 6
1
<?php
2
namespace Eduardokum\CorreiosPhp\Soap;
3
4
use Eduardokum\CorreiosPhp\Contracts\Soap\Soap as SoapContract;
5
6
class SoapCurl extends Soap implements SoapContract
7
{
8
    public function send($url, array $action = [], $request = '', $namespaces = [], $auth = [])
9
    {
10
        $this->request = $this->envelop($request, $namespaces);
11
        $headers = array_filter([
12
            'Content-Type: text/xml;charset=utf-8',
13
            array_key_exists('curl', $action) && !empty(trim($action['curl'])) ? sprintf('SOAPAction: "%s"', $action['curl']) : null,
14
            'Accept: text/xml',
15
            'Cache-Control: no-cache',
16
            'Pragma: no-cache',
17
            sprintf('Content-length: %s', strlen($this->request)),
18
        ]);
19
        $curl = curl_init();
20
        if ($this->proxyIP != '') {
21
            curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, true);
0 ignored issues
show
Bug introduced by
It seems like $curl can also be of type false; however, parameter $ch of curl_setopt() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

21
            curl_setopt(/** @scrutinizer ignore-type */ $curl, CURLOPT_HTTPPROXYTUNNEL, true);
Loading history...
22
            curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
23
            curl_setopt($curl, CURLOPT_PROXY, $this->proxyIP.':'.$this->proxyPort);
24
            if ($this->proxyUser != '') {
25
                curl_setopt($curl, CURLOPT_PROXYUSERPWD, $this->proxyUser.':'.$this->proxyPass);
26
                curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
27
            }
28
        }
29
        curl_setopt($curl, CURLOPT_URL, $url);
30
        curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
31
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->soapTimeout);
32
        curl_setopt($curl, CURLOPT_TIMEOUT, $this->soapTimeout + 20);
33
        curl_setopt($curl, CURLOPT_HEADER, false);
34
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
35
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
36
        curl_setopt($curl, CURLOPT_SSLVERSION, $this->soapProtocol);
37
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
38
        if ($auth) {
39
            curl_setopt($curl, CURLOPT_USERPWD, $auth['user'] . ":" . $auth['password']);
40
        }
41
        curl_setopt($curl, CURLOPT_POST, true);
42
        curl_setopt($curl, CURLOPT_POSTFIELDS, $this->request);
43
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
44
        $this->response = $response = curl_exec($curl);
0 ignored issues
show
Documentation Bug introduced by
It seems like $response = curl_exec($curl) can also be of type boolean. However, the property $response is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
Bug introduced by
It seems like $curl can also be of type false; however, parameter $ch of curl_exec() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
        $this->response = $response = curl_exec(/** @scrutinizer ignore-type */ $curl);
Loading history...
45
        $this->soapError = curl_error($curl);
0 ignored issues
show
Bug introduced by
It seems like $curl can also be of type false; however, parameter $ch of curl_error() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
        $this->soapError = curl_error(/** @scrutinizer ignore-type */ $curl);
Loading history...
46
        $this->soapInfo = curl_getinfo($curl);
0 ignored issues
show
Bug introduced by
It seems like $curl can also be of type false; however, parameter $ch of curl_getinfo() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
        $this->soapInfo = curl_getinfo(/** @scrutinizer ignore-type */ $curl);
Loading history...
47
        curl_close($curl);
0 ignored issues
show
Bug introduced by
It seems like $curl can also be of type false; however, parameter $ch of curl_close() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
        curl_close(/** @scrutinizer ignore-type */ $curl);
Loading history...
48
        return $this->response($response);
49
    }
50
}
51