AuthPlainCredentialsRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

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
    /**
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