Completed
Pull Request — master (#42)
by Frederik
03:52
created

AuthPlainCredentialsRequest::toStream()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 0
cts 8
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 2
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
    public function __construct(Tag $tag,string $username, string $password)
33
    {
34
        $this->tag = $tag;
35
        $this->username = $username;
36
        $this->password = $password;
37
    }
38
39
    /**
40
     * @return StreamInterface
41
     */
42
    public function toStream(): StreamInterface
43
    {
44
        return new StringStream(
45
            base64_encode(
46
                sprintf("\0%s\0%s", $this->username, $this->password)
47
            )
48
        );
49
    }
50
51
    /**
52
     * @return Tag
53
     */
54
    public function getTag(): Tag
55
    {
56
        return $this->tag;
57
    }
58
}