Completed
Pull Request — master (#42)
by Frederik
01:59
created

AuthPlainCredentialsRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Protocol\Imap\Request;
5
6
use Genkgo\Mail\Protocol\Imap\RequestInterface;
7
use Genkgo\Mail\Protocol\Imap\Tag;
8
use Genkgo\Mail\Stream\StringStream;
9
use Genkgo\Mail\StreamInterface;
10
11
final class AuthPlainCredentialsRequest implements RequestInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    private $username;
17
    /**
18
     * @var string
19
     */
20
    private $password;
21
    /**
22
     * @var Tag
23
     */
24
    private $tag;
25
26
    /**
27
     * AuthPlainCredentialsRequest constructor.
28
     * @param Tag $tag
29
     * @param string $username
30
     * @param string $password
31
     */
32 3
    public function __construct(Tag $tag,string $username, string $password)
33
    {
34 3
        $this->tag = $tag;
35 3
        $this->username = $username;
36 3
        $this->password = $password;
37 3
    }
38
39
    /**
40
     * @return StreamInterface
41
     */
42 3
    public function toStream(): StreamInterface
43
    {
44 3
        return new StringStream(
45 3
            base64_encode(
46 3
                sprintf("\0%s\0%s", $this->username, $this->password)
47
            )
48
        );
49
    }
50
51
    /**
52
     * @return Tag
53
     */
54 2
    public function getTag(): Tag
55
    {
56 2
        return $this->tag;
57
    }
58
}