ClientFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 1
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ddlzz\AmoAPI;
4
5
use ddlzz\AmoAPI\Request\Curl;
6
use ddlzz\AmoAPI\Request\DataSender;
7
8
/**
9
 * Class ClientFactory. It handles all dependencies for Client class.
10
 *
11
 * @author ddlzz
12
 */
13
class ClientFactory
14
{
15
    /**
16
     * @param CredentialsManager   $credentials
17
     * @param SettingsStorage|null $settings
18
     *
19
     * @return Client
20
     */
21 1
    public static function create(CredentialsManager $credentials, SettingsStorage $settings = null)
22
    {
23 1
        $settings = $settings ?: new SettingsStorage();
24 1
        $dataSender = self::buildSender($settings);
25
26 1
        return new Client($credentials, $dataSender, $settings);
27
    }
28
29
    /**
30
     * @param SettingsStorage $settings
31
     *
32
     * @return DataSender
33
     */
34 1
    private static function buildSender(SettingsStorage $settings)
35
    {
36 1
        return new DataSender(new Curl(), $settings);
37
    }
38
}
39