Completed
Push — master ( 03e26c...a0308c )
by Frederik
9s
created

AppendCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

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