Completed
Push — master ( 7da4ff...40ec06 )
by Sergey
02:22
created

SmsIntel::checkCredentials()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 6
rs 9.4285
cc 3
eloc 3
nc 2
nop 2
1
<?php
2
3
namespace seregazhuk\SmsIntel\Factories;
4
5
use Guzzle\Http\Client;
6
use seregazhuk\SmsIntel\Sender;
7
use seregazhuk\SmsIntel\Exceptions\AuthException;
8
use seregazhuk\SmsIntel\Requests\RequestsContainer;
9
use seregazhuk\SmsIntel\Adapters\GuzzleHttpAdapter;
10
11
class SmsIntel
12
{
13
    /**
14
     * @param $login
15
     * @param $password
16
     * @return Sender
17
     */
18
    public static function create($login, $password)
19
    {
20
        self::checkCredentials($login, $password);
21
22
        $requestsContainer = new RequestsContainer(
23
            self::createHttpAdapter(),
24
            $login,
25
            $password
26
        );
27
        return new Sender($requestsContainer);
28
    }
29
30
    protected static function createHttpAdapter()
31
    {
32
        return new GuzzleHttpAdapter(new Client());
33
    }
34
35
    /**
36
     * @param string $login
37
     * @param string $password
38
     * @throws AuthException
39
     */
40
    protected static function checkCredentials($login, $password)
41
    {
42
        if (empty($login) || empty($password)) {
43
            throw new AuthException('You must provide login and password to send messages!');
44
        }
45
    }
46
}
47