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

DropboxHttpClientFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 30
ccs 6
cts 8
cp 0.75
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A make() 0 20 4
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