Completed
Push — master ( 6695d4...9bc3b7 )
by Harry
04:41
created

FileProcessTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 29
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B processFile() 0 16 5
1
<?php
2
3
namespace Graze\DataFile\Modify;
4
5
use Graze\DataFile\Helper\Process\ProcessTrait;
6
use Graze\DataFile\Node\LocalFile;
7
use Psr\Log\LogLevel;
8
use Symfony\Component\Process\Exception\ProcessFailedException;
9
10
trait FileProcessTrait
11
{
12
    use ProcessTrait;
13
14
    /**
15
     * @param LocalFile $file
16
     * @param LocalFile $output
17
     * @param string    $cmd
18
     * @param bool      $deleteOld
19
     *
20
     * @return LocalFile
21
     */
22 48
    protected function processFile(LocalFile $file, LocalFile $output, $cmd, $deleteOld = true)
23
    {
24 48
        $process = $this->getProcess($cmd);
25 48
        $process->run();
26
27 48
        if (!$process->isSuccessful() || !$output->exists()) {
28 8
            throw new ProcessFailedException($process);
29
        }
30
31 40
        if ($file->exists() && !$deleteOld) {
32 9
            $this->log(LogLevel::DEBUG, "Deleting old file: '{file}'", ['file' => $file]);
33 9
            $file->delete();
34
        }
35
36 40
        return $output;
37
    }
38
}
39