Factory::init()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
3
namespace PeterColes\Cluster\Contracts;
4
5
abstract class Factory
6
{
7
    /**
8
     * The adapter being constructed by the factory
9
     */
10
    protected $adapter;
11
12
    /**
13
     * Initialise the adapter, including injecting an http client
14
     *
15
     * @param object $adapter
16
     * @param object $client
17
     * @return void
18
     */
19
    public function init($adapter, $client = null)
20
    {
21
        // set the server adapter
22
        $this->adapter = $adapter;
23
24
        // for ease of use we can fallback to a default http client
25
        if (!$client) {
26
            $client = new \PeterColes\Cluster\HttpClients\GuzzleHttp;
27
        }
28
29
        // initialise the http client with the authentication header options
30
        $client->initClient($this->adapter->getHeaders());
31
32
        // make the initialised http client available to the adapter
33
        $this->adapter->setClient($client);
34
    }
35
}
36