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

SmsIntel   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

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

3 Methods

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