TodoComments::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace IntegerNet\TodoReminder;
4
5
class TodoComments extends \ArrayIterator
6
{
7 15
    public function __construct(TodoComment ...$comments)
8
    {
9 15
        parent::__construct($comments);
10 15
    }
11
12 3
    public function add(TodoComments $other): TodoComments
13
    {
14 3
        foreach ($other as $comment) {
15 3
            $this->append($comment);
16
        }
17 3
        return $this;
18
    }
19
20 6
    public function notEmpty(): bool
21
    {
22 6
        return $this->count() > 0;
23
    }
24
25
    public function formatText(): string
26
    {
27
        $output = '';
28
        if ($this->notEmpty()) {
29
            $output .= "The following TODO comments are NOT DONE:\n\n";
30
            foreach ($this as $comment) {
31
                /** @var TodoComment $comment */
32
                if (!isset($last) || !$comment->isInSameFile($last)) {
33
                    $output .= $comment->file() . "\n";
34
                    $output .= str_repeat('=', mb_strlen($comment->file())) . "\n\n";
35
                }
36
                $output .= $comment->formatText();
37
                $last = $comment;
38
            }
39
        }
40
        return $output;
41
    }
42
}
43