ClientFactory::buildSender()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 1
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