Cron::format()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 3
nc 4
nop 0
1
<?php
2
3
namespace MyBuilder\Cronos\Formatter;
4
5
class Cron
6
{
7
    /** @var Header */
8
    private $header;
9
10
    /** @var mixed[] */
11
    private $lines = [];
12
13
    public function header(): Header
14
    {
15
        $this->header = new Header($this);
16
17
        return $this->header;
18
    }
19
20
    public function job(string $command): Job
21
    {
22
        $line = new Job($command, $this);
23
        $this->lines[] = $line;
24
25
        return $line;
26
    }
27
28
    public function comment(string $comment): Cron
29
    {
30
        $this->lines[] = new Comment($comment);
31
32
        return $this;
33
    }
34
35
    public function countLines(): int
36
    {
37
        return count($this->lines);
38
    }
39
40
    public function format(): string
41
    {
42
        $lines = '';
43
44
        foreach ($this->lines as $line) {
45
            $lines .= $line->format() . \PHP_EOL;
46
        }
47
48
        return (($this->hasHeader()) ? $this->header->format() . \PHP_EOL : '') . \trim($lines) . \PHP_EOL;
49
    }
50
51
    public function hasHeader(): bool
52
    {
53
        return $this->header !== null;
54
    }
55
}
56