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

SmsIntel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 5
dl 0
loc 43
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 11 1
A createHttpAdapter() 0 4 1
A checkCredentials() 0 6 3
A __construct() 0 1 1
A __clone() 0 1 1
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