ProcessHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 38
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 12 2
A runArray() 0 12 2
1
<?php
2
3
namespace EDouna\LaravelDBBackup;
4
5
use Illuminate\Support\Facades\Log;
6
use Symfony\Component\Process\Process;
7
8
class ProcessHandler
9
{
10
    /**
11
     * @param string $command
12
     *
13
     * @return bool
14
     */
15
    public function run(string $command): bool
16
    {
17
        $process = Process::fromShellCommandline($command, null, null, null, 999.00);
18
        $process->run();
19
20
        if ($process->getExitCode() !== 0) {
21
            Log::error(sprintf('Failure in the processor. Please verify if the command is recognized. Exit code text returned: "%s". Error output: %s', $process->getExitCodeText(), $process->getErrorOutput()));
22
23
            return false;
24
        }
25
26
        return true;
27
    }
28
29
    /**
30
     * @param array $command
31
     *
32
     * @return bool
33
     */
34
    public static function runArray(array $command): bool
35
    {
36
        $process = new Process($command);
37
        $process->run();
38
39
        if ($process->getExitCode() !== 0) {
40
            Log::error(sprintf('Failure in the processor. Please verify if the command is recognized. Exit code text returned: "%s". Error output: %s', $process->getExitCodeText(), $process->getErrorOutput()));
41
42
            return false;
43
        }
44
45
        return true;
46
    }
47
}
48