CommandCronManipulator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace MyBuilder\Cronos\Updater;
4
5
class CommandCronManipulator implements CronManipulator
6
{
7
    /** @var ProcessRunner */
8
    private $processRunner;
9
10
    /** @var FileSystem */
11
    private $fileSystem;
12
13
    /** @var string */
14
    private $cronCommand;
15
16
    public function __construct(ProcessRunner $processRunner, FileSystem $fileSystem, string $cronCommand = 'crontab')
17
    {
18
        $this->processRunner = $processRunner;
19
        $this->fileSystem = $fileSystem;
20
        $this->cronCommand = $cronCommand;
21
    }
22
23
    public function replace(string $contents): void
24
    {
25
        $filePath = $this->fileSystem->createTempFile('cron', $contents);
26
        $this->processRunner->run([$this->cronCommand, $filePath]);
27
        $this->fileSystem->removeFile($filePath);
28
    }
29
30
    public function getContent(): string
31
    {
32
        return $this->processRunner->run([$this->cronCommand, '-l']);
33
    }
34
}
35