LoginAuthenticator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 27
ccs 0
cts 10
cp 0
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A authenticate() 0 5 1
A __construct() 0 4 1
1
<?php
2
3
namespace Kodus\Mail\SMTP\Authenticator;
4
5
use Kodus\Mail\SMTP\SMTPAuthenticator;
6
use Kodus\Mail\SMTP\SMTPClient;
7
8
/**
9
 * Use this `Authenticator` with SMTP servers that require plain login authentication.
10
 */
11
class LoginAuthenticator implements SMTPAuthenticator
12
{
13
    /**
14
     * @var string SMTP username
15
     */
16
    protected $username;
17
18
    /**
19
     * @var string SMTP password
20
     */
21
    protected $password;
22
23
    /**
24
     * @param string $username
25
     * @param string $password
26
     */
27
    public function __construct(string $username, string $password)
28
    {
29
        $this->username = $username;
30
        $this->password = $password;
31
    }
32
33
    public function authenticate(SMTPClient $client): void
34
    {
35
        $client->sendCommand("AUTH LOGIN", "334");
36
        $client->sendCommand(base64_encode($this->username), "334");
37
        $client->sendCommand(base64_encode($this->password), "235");
38
    }
39
}
40