Completed
Push — master ( d30d8a...80cd4c )
by Dan
02:22
created

GuzzleFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A newClient() 0 6 1
A createHandlerStack() 0 9 1
1
<?php
2
namespace Nopolabs\Yabot\Guzzle;
3
4
use GuzzleHttp\Client;
5
use GuzzleHttp\Handler\CurlMultiHandler;
6
use GuzzleHttp\HandlerStack;
7
use GuzzleHttp\Middleware;
8
9
class GuzzleFactory
10
{
11
    public static function newClient(CurlMultiHandler $handler, array $config) : Client
12
    {
13
        $config['handler'] = self::createHandlerStack($handler);
14
15
        return new Client($config);
16
    }
17
18
    /**
19
     * Like HandlerStack::create() except no http_errors
20
     * @return HandlerStack
21
     */
22
    public static function createHandlerStack(CurlMultiHandler $handler) : HandlerStack
23
    {
24
        $stack = new HandlerStack($handler);
25
        $stack->push(Middleware::redirect(), 'allow_redirects');
26
        $stack->push(Middleware::cookies(), 'cookies');
27
        $stack->push(Middleware::prepareBody(), 'prepare_body');
28
29
        return $stack;
30
    }
31
}