Completed
Pull Request — master (#37)
by Vitaliy
06:49 queued 04:18
created

DebugHelper::addDebugOptionsToHttpClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
namespace Xsolla\SDK\Tests\Helper;
4
5
use Guzzle\Common\Event;
6
use Guzzle\Http\Client;
7
8
class DebugHelper
9
{
10
    public static function isDebug()
11
    {
12
        global $argv;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
13
14
        return in_array('--debug', $argv, true);
15
    }
16
17
    public static function addDebugOptionsToHttpClient(Client $guzzleClient)
18
    {
19
        $guzzleClient->setDefaultOption('debug', true);
20
        $echoCb = function (Event $event) {
21
            echo (string) $event['request'].PHP_EOL;
22
            echo (string) $event['response'].PHP_EOL;
23
        };
24
        $guzzleClient->getEventDispatcher()->addListener('request.complete', $echoCb);
25
        $guzzleClient->getEventDispatcher()->addListener('request.exception', $echoCb);
26
    }
27
}
28