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

AppendCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
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 70
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 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\ParenthesizedList;
9
use Genkgo\Mail\Protocol\Imap\Tag;
10
use Genkgo\Mail\Stream\StringStream;
11
use Genkgo\Mail\StreamInterface;
12
13
/**
14
 * Class AppendCommand
15
 * @package Genkgo\Mail\Protocol\Imap\Request
16
 */
17
final class AppendCommand extends AbstractCommand
18
{
19
    /**
20
     * @var Tag
21
     */
22
    private $tag;
23
    /**
24
     * @var MailboxName
25
     */
26
    private $mailbox;
27
    /**
28
     * @var ParenthesizedList
29
     */
30
    private $flags;
31
    /**
32
     * @var int
33
     */
34
    private $size;
35
    /**
36
     * @var \DateTimeImmutable|null
37
     */
38
    private $internalDate;
39
40
    /**
41
     * AppendCommand constructor.
42
     * @param Tag $tag
43
     * @param MailboxName $mailbox
44
     * @param int $size
45
     * @param FlagParenthesizedList $flags
46
     * @param \DateTimeImmutable|null $internalDate
47
     */
48 4
    public function __construct(
49
        Tag $tag,
50
        MailboxName $mailbox,
51
        int $size,
52
        FlagParenthesizedList $flags = null,
53
        \DateTimeImmutable $internalDate = null
54
    )
55
    {
56 4
        $this->tag = $tag;
57 4
        $this->mailbox = $mailbox;
58 4
        $this->flags = $flags;
0 ignored issues
show
Documentation Bug introduced by
It seems like $flags can also be of type object<Genkgo\Mail\Proto...\FlagParenthesizedList>. However, the property $flags is declared as type object<Genkgo\Mail\Proto...Imap\ParenthesizedList>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
59 4
        $this->size = $size;
60 4
        $this->internalDate = $internalDate;
61 4
    }
62
63
    /**
64
     * @return StreamInterface
65
     */
66 4
    protected function createStream(): StreamInterface
67
    {
68 4
        return new StringStream(
69 4
            sprintf(
70 4
                'APPEND %s %s%s{%s}',
71 4
                (string)$this->mailbox,
72 4
                $this->flags ? (string)$this->flags . ' ' : '',
73 4
                $this->internalDate ? '"'.$this->internalDate->format('d-D-Y H:i:sO') . '" ' : '',
74 4
                (string)$this->size
75
            )
76
        );
77
    }
78
79
    /**
80
     * @return Tag
81
     */
82 4
    public function getTag(): Tag
83
    {
84 4
        return $this->tag;
85
    }
86
}