Completed
Push — master ( 8b73f7...9e08cd )
by Ruben
02:59
created

Guzzle5ApiClientFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 13.33 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 8
loc 60
ccs 12
cts 28
cp 0.4286
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getApiClientClass() 0 4 1
A getGuzzleBaseUriOptionKey() 0 4 1
A createTokenSubscriber() 0 4 1
A createHttpClient() 0 9 1
A createSimple() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace MovingImage\Client\VMPro\Factory;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\ClientInterface;
7
use MovingImage\Client\VMPro\ApiClient\Guzzle5ApiClient;
8
use MovingImage\Client\VMPro\Entity\ApiCredentials;
9
use MovingImage\Client\VMPro\Manager\TokenManager;
10
use MovingImage\Client\VMPro\Subscriber\TokenSubscriber;
11
12
/**
13
 * Class Guzzle5.
14
 *
15
 * @author Ruben Knol <[email protected]>
16
 */
17
class Guzzle5ApiClientFactory extends AbstractApiClientFactory
18
{
19
    /**
20
     * Use the Guzzle5-specific API client class.
21
     *
22
     * @return string
23
     */
24 1
    protected function getApiClientClass()
25
    {
26 1
        return Guzzle5ApiClient::class;
27
    }
28
29 1
    protected function getGuzzleBaseUriOptionKey()
30
    {
31 1
        return 'base_url';
32
    }
33
34
    /**
35
     * Instantiate a TokenSubscriber instance with a TokenManager.
36
     *
37
     * @param TokenManager $tokenManager
38
     *
39
     * @return TokenSubscriber
40
     */
41 2
    public function createTokenSubscriber(TokenManager $tokenManager)
42
    {
43 2
        return new TokenSubscriber($tokenManager);
44
    }
45
46
    /**
47
     * Method to instantiate a HTTP client.
48
     *
49
     * @param string $baseUri
50
     * @param array  $subscribers
51
     * @param array  $options
52
     *
53
     * @return ClientInterface
54
     */
55 1
    public function createHttpClient($baseUri, array $subscribers = [], array $options = [])
56
    {
57 1
        return new Client(array_merge([
58 1
            'base_url' => $baseUri,
59
            'defaults' => [
60 1
                'subscribers' => $subscribers,
61 1
            ],
62 1
        ], $options));
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 View Code Duplication
    public function createSimple($baseUri, ApiCredentials $credentials)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        $tokenManager = $this->createTokenManager($baseUri, $credentials);
71
        $tokenSubscriber = $this->createTokenSubscriber($tokenManager);
72
        $httpClient = $this->createHttpClient($baseUri, [$tokenSubscriber]);
73
74
        return $this->create($httpClient, $this->createSerializer());
75
    }
76
}
77