AppendCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 72
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A createStream() 0 12 3
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\FlagParenthesizedList;
7
use Genkgo\Mail\Protocol\Imap\MailboxName;
8
use Genkgo\Mail\Protocol\Imap\Tag;
9
use Genkgo\Mail\Stream\StringStream;
10
use Genkgo\Mail\StreamInterface;
11
12
final class AppendCommand extends AbstractCommand
13
{
14
    /**
15
     * @var Tag
16
     */
17
    private $tag;
18
19
    /**
20
     * @var MailboxName
21
     */
22
    private $mailbox;
23
24
    /**
25
     * @var FlagParenthesizedList|null
26
     */
27
    private $flags;
28
29
    /**
30
     * @var int
31
     */
32
    private $size;
33
34
    /**
35
     * @var \DateTimeImmutable|null
36
     */
37
    private $internalDate;
38
39
    /**
40
     * @param Tag $tag
41
     * @param MailboxName $mailbox
42
     * @param int $size
43
     * @param FlagParenthesizedList|null $flags
44
     * @param \DateTimeImmutable|null $internalDate
45
     */
46 5
    public function __construct(
47
        Tag $tag,
48
        MailboxName $mailbox,
49
        int $size,
50
        FlagParenthesizedList $flags = null,
51
        \DateTimeImmutable $internalDate = null
52
    ) {
53 5
        $this->tag = $tag;
54 5
        $this->mailbox = $mailbox;
55 5
        $this->flags = $flags;
56 5
        $this->size = $size;
57 5
        $this->internalDate = $internalDate;
58 5
    }
59
60
    /**
61
     * @return StreamInterface
62
     */
63 5
    protected function createStream(): StreamInterface
64
    {
65 5
        return new StringStream(
66 5
            \sprintf(
67 5
                'APPEND %s %s%s{%s}',
68 5
                (string)$this->mailbox,
69 5
                $this->flags ? (string)$this->flags . ' ' : '',
70 5
                $this->internalDate ? '"'.$this->internalDate->format('d-D-Y H:i:sO') . '" ' : '',
71 5
                (string)$this->size
72
            )
73
        );
74
    }
75
76
    /**
77
     * @return Tag
78
     */
79 5
    public function getTag(): Tag
80
    {
81 5
        return $this->tag;
82
    }
83
}
84