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

DebugHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isDebug() 0 6 1
A addDebugOptionsToHttpClient() 0 10 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