Completed
Pull Request — master (#12)
by Robert
20:08 queued 10:09
created

ClientFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 11

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 0
cbo 11
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 22 2
1
<?php
2
3
namespace Rs\VersionEye\Http;
4
5
use Http\Client\Common\HttpMethodsClient;
6
use Http\Client\Plugin\AuthenticationPlugin;
7
use Http\Client\Plugin\DecoderPlugin;
8
use Http\Client\Plugin\ErrorPlugin;
9
use Http\Client\Plugin\PluginClient;
10
use Http\Client\Plugin\RedirectPlugin;
11
use Http\Client\Plugin\RetryPlugin;
12
use Http\Discovery\HttpClientDiscovery;
13
use Http\Discovery\MessageFactoryDiscovery;
14
use Http\Message\Authentication\QueryParam;
15
16
/**
17
 * Factory for creating Http Client.
18
 *
19
 * @author Robert Schönthal <[email protected]>
20
 */
21
class ClientFactory
22
{
23
    /**
24
     * @param string $url
25
     * @param string $token
26
     *
27
     * @return HttpClient
28
     */
29
    public static function create($url, $token)
30
    {
31
        $plugins = [
32
            new RedirectPlugin(),
0 ignored issues
show
Deprecated Code introduced by
The class Http\Client\Plugin\RedirectPlugin has been deprecated with message: since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\Plugin\RedirectPlugin} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
33
            new RetryPlugin(['retries' => 5]),
0 ignored issues
show
Deprecated Code introduced by
The class Http\Client\Plugin\RetryPlugin has been deprecated with message: since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\Plugin\RetryPlugin} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
34
            new DecoderPlugin(),
0 ignored issues
show
Deprecated Code introduced by
The class Http\Client\Plugin\DecoderPlugin has been deprecated with message: since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\Plugin\DecoderPlugin} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
35
            new ErrorPlugin(),
0 ignored issues
show
Deprecated Code introduced by
The class Http\Client\Plugin\ErrorPlugin has been deprecated with message: since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\Plugin\ErrorPlugin} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
36
        ];
37
38
        if ($token) {
39
            $plugins[] = new AuthenticationPlugin(new QueryParam([
0 ignored issues
show
Deprecated Code introduced by
The class Http\Client\Plugin\AuthenticationPlugin has been deprecated with message: since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\Plugin\AuthenticationPlugin} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
40
                'api_key' => $token,
41
            ]));
42
        }
43
44
        $client = new HttpMethodsClient(
45
            new PluginClient(HttpClientDiscovery::find(), $plugins),
0 ignored issues
show
Deprecated Code introduced by
The class Http\Client\Plugin\PluginClient has been deprecated with message: since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\PluginClient} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
46
            MessageFactoryDiscovery::find()
47
        );
48
49
        return new HttpPlugHttpAdapterClient($client, $url);
50
    }
51
}
52