| Conditions | 7 |
| Paths | 9 |
| Total Lines | 31 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | protected function getValue(string $value): array |
||
| 16 | { |
||
| 17 | if (!CommandRunner::isToolInstalled('docker', $command)) { |
||
| 18 | throw new ToolNotFoundException('The cli tool "docker" has to be installed to use the "docker-name" enrichment function.'); |
||
| 19 | } |
||
| 20 | |||
| 21 | exec("docker ps --no-trunc --format='{{json .}}' 2>&1", $output, $statusCode); |
||
| 22 | |||
| 23 | if ($statusCode !== Command::SUCCESS) { |
||
| 24 | if (str_contains($output[0], 'Is the docker daemon running?')) { |
||
| 25 | ForrestLogger::warn('Docker daemon not running. Please start it to use the "docker-names" function.'); |
||
| 26 | } else { |
||
| 27 | ForrestLogger::warn($output[0]); |
||
| 28 | } |
||
| 29 | return []; |
||
| 30 | } |
||
| 31 | |||
| 32 | $names = []; |
||
| 33 | |||
| 34 | foreach ($output as $containerJson) { |
||
| 35 | $container = json_decode($containerJson, true); |
||
| 36 | if ($container) { |
||
| 37 | $names[] = $container['Names']; |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | if (count($names) == 0) { |
||
| 42 | ForrestLogger::warn('Currently there are no docker containers running. Please start one to use the "docker-names" function.'); |
||
| 43 | } |
||
| 44 | |||
| 45 | return $names; |
||
| 46 | } |
||
| 48 |