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

AuthPlainCredentialsRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 48
c 0
b 0
f 0
ccs 0
cts 18
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A toStream() 0 8 1
A getTag() 0 4 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
    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
}