AuthPlainCredentialsRequest::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

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 10
c 0
b 0
f 0
cc 1
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
    /**
19
     * @var string
20
     */
21
    private $password;
22
23
    /**
24
     * @var Tag
25
     */
26
    private $tag;
27
28
    /**
29
     * @param Tag $tag
30
     * @param string $username
31
     * @param string $password
32
     */
33 5
    public function __construct(Tag $tag, string $username, string $password)
34
    {
35 5
        $this->tag = $tag;
36 5
        $this->username = $username;
37 5
        $this->password = $password;
38 5
    }
39
40
    /**
41
     * @return StreamInterface
42
     */
43 5
    public function toStream(): StreamInterface
44
    {
45 5
        return new StringStream(
46 5
            \base64_encode(
47 5
                \sprintf("\0%s\0%s", $this->username, $this->password)
48
            )
49
        );
50
    }
51
52
    /**
53
     * @return Tag
54
     */
55 4
    public function getTag(): Tag
56
    {
57 4
        return $this->tag;
58
    }
59
}
60