LoginAuthenticator::authenticate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 2
rs 10
c 1
b 0
f 0
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