CommandCronManipulator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A replace() 0 6 1
A getContent() 0 4 1
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