Completed
Push — master ( 8bc6ad...b2c48e )
by Vitaliy
16:26 queued 13:19
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 0 Features 0
Metric Value
c 1
b 0
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
        return in_array('--debug', $GLOBALS['argv'], true);
13
    }
14
15
    public static function addDebugOptionsToHttpClient(Client $guzzleClient)
16
    {
17
        $guzzleClient->setDefaultOption('debug', true);
18
        $echoCb = function (Event $event) {
19
            echo (string) $event['request'].PHP_EOL;
20
            echo (string) $event['response'].PHP_EOL;
21
        };
22
        $guzzleClient->getEventDispatcher()->addListener('request.complete', $echoCb);
23
        $guzzleClient->getEventDispatcher()->addListener('request.exception', $echoCb);
24
    }
25
}
26