Comment::addAttachment()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Manavo\DoneDone;
4
5
class Comment
6
{
7
8
    /**
9
     * @var string
10
     */
11
    private $message = null;
12
13
    /**
14
     * @var array
15
     */
16
    private $attachments = [];
17
18
    /**
19
     * @param string $attachment
20
     */
21 3
    public function addAttachment($attachment)
22
    {
23 3
        $this->attachments[] = $attachment;
24 3
    }
25
26
    /**
27
     * @param string $message
28
     */
29 3
    public function setMessage($message)
30
    {
31 3
        $this->message = $message;
32 3
    }
33
34
    /**
35
     * @return array
36
     */
37 9
    public function toArray()
38
    {
39
        $data = [
40 9
            'comment' => $this->message,
41 9
        ];
42
43 9
        foreach ($this->attachments as $index => $attachment) {
44 3
            $data['attachment-' . $index] = fopen($attachment, 'r');
45 9
        }
46
47 9
        return $data;
48
    }
49
50
}
51