Completed
Pull Request — master (#97)
by
unknown
03:37
created

DropboxHttpClientFactory::make()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.25

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 20
ccs 6
cts 8
cp 0.75
rs 9.2
c 1
b 0
f 0
cc 4
eloc 8
nc 4
nop 1
crap 4.25
1
<?php
2
namespace Kunnu\Dropbox\Http\Clients;
3
4
use InvalidArgumentException;
5
use GuzzleHttp\Client as Guzzle;
6
7
/**
8
 * DropboxHttpClientFactory
9
 */
10
class DropboxHttpClientFactory
11
{
12
    /**
13
     * Make HTTP Client
14
     *
15
     * @param  \Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface|\GuzzleHttp\Client|null $handler
16
     *
17
     * @return \Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface
18
     */
19 3
    public static function make($handler)
20
    {
21
        //No handler specified
22 3
        if (!$handler) {
23
            return new DropboxGuzzleHttpClient();
24
        }
25
26
        //Custom Implementation, maybe.
27 3
        if ($handler instanceof DropboxHttpClientInterface) {
28 3
            return $handler;
29
        }
30
31
        //Handler is a custom configured Guzzle Client
32 3
        if ($handler instanceof Guzzle) {
33 3
            return new DropboxGuzzleHttpClient($handler);
34
        }
35
36
        //Invalid handler
37
        throw new InvalidArgumentException('The http client handler must be an instance of GuzzleHttp\Client or an instance of Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface.');
38
    }
39
}
40