Completed
Pull Request — master (#37)
by Vitaliy
07:07 queued 04:03
created

DebugHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
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 18
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isDebug() 0 4 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()
1 ignored issue
show
Coding Style introduced by
isDebug uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
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