Completed
Push — master ( c85e73...41284f )
by Dmitry
02:55
created

GuzzleProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 24
ccs 0
cts 10
cp 0
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 17 3
1
<?php
2
3
namespace Basis\Provider;
4
5
use GuzzleHttp\Client;
6
use League\Container\ServiceProvider\AbstractServiceProvider;
7
8
class GuzzleProvider extends AbstractServiceProvider
9
{
10
    protected $provides = [
11
        Client::class,
12
    ];
13
14
    public function register()
0 ignored issues
show
Coding Style introduced by
register uses the super-global variable $_SERVER 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...
15
    {
16
        $this->getContainer()->share(Client::class, function () {
17
            $headers = [
18
                'transfer-encoding' => 'chunked',
19
            ];
20
            if (array_key_exists('HTTP_X_REAL_IP', $_SERVER)) {
21
                $headers['x-real-ip'] = $_SERVER['HTTP_X_REAL_IP'];
22
            }
23
            if (array_key_exists('HTTP_X_SESSION', $_SERVER)) {
24
                $headers['x-session'] = $_SERVER['HTTP_X_SESSION'];
25
            }
26
            return new Client([
27
                'headers' => $headers
28
            ]);
29
        });
30
    }
31
}
32