| Total Complexity | 12 |
| Total Lines | 67 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class Runner |
||
| 8 | { |
||
| 9 | private bool $timeout = false; |
||
| 10 | |||
| 11 | private static ?Runner $instance = null; |
||
| 12 | |||
| 13 | static public function getInstance(): Runner |
||
| 14 | { |
||
| 15 | if (self::$instance === null) { |
||
| 16 | self::$instance = new self(); |
||
| 17 | } |
||
| 18 | |||
| 19 | return self::$instance; |
||
|
|
|||
| 20 | } |
||
| 21 | |||
| 22 | public function __construct() |
||
| 23 | { |
||
| 24 | $process = $this->run('timeout --version'); |
||
| 25 | if ($process->isSuccessful()) { |
||
| 26 | $this->timeout = true; |
||
| 27 | } else { |
||
| 28 | $this->timeout = false; |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | public function run($command, $killAfterSeconds = 5): Process |
||
| 33 | { |
||
| 34 | if ($this->timeout) { |
||
| 35 | $shellCommandLine = "timeout --kill-after=" . $killAfterSeconds . "s 1m " . $command; |
||
| 36 | } else { |
||
| 37 | $shellCommandLine = $command; |
||
| 38 | } |
||
| 39 | |||
| 40 | $process = Process::fromShellCommandline($shellCommandLine); |
||
| 41 | |||
| 42 | $process->run(); |
||
| 43 | |||
| 44 | return $process; |
||
| 45 | } |
||
| 46 | |||
| 47 | public function commandExists(string $command): bool |
||
| 48 | { |
||
| 49 | $which = $this->run('which ' . $command)->getOutput(); |
||
| 50 | if (empty($which)) { |
||
| 51 | return false; |
||
| 52 | } |
||
| 53 | |||
| 54 | return true; |
||
| 55 | } |
||
| 56 | |||
| 57 | public static function outputToArray(string $output): array |
||
| 60 | } |
||
| 61 | |||
| 62 | public function getFileContents(string $path, bool $asArray = false): string|false|array |
||
| 63 | { |
||
| 64 | if ($asArray) { |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | public function fileExists(string $path): bool |
||
| 74 | } |
||
| 75 | } |