Completed
Push — master ( ee11be...6aaa22 )
by Sergey
04:48 queued 02:39
created

SmsIntel::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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