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

SmsIntel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 6
Bugs 2 Features 2
Metric Value
wmc 7
c 6
b 2
f 2
lcom 0
cbo 5
dl 0
loc 42
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\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