Completed
Push — master ( 7e8ad4...4d1224 )
by Sergey
04:31 queued 01:54
created

SmsIntel::checkCredentials()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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