| Conditions | 6 |
| Paths | 13 |
| Total Lines | 38 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 6.2488 |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | 4 | protected function batch(Input $input): ?string |
|
| 18 | { |
||
| 19 | 4 | \assert($input->isArray()); |
|
| 20 | |||
| 21 | 4 | $children = []; |
|
| 22 | 4 | $responses = []; |
|
| 23 | 4 | foreach ($input->data() as $request) { |
|
| 24 | 4 | $pair = \stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); |
|
| 25 | |||
| 26 | 4 | $pid = \pcntl_fork(); |
|
| 27 | |||
| 28 | 4 | if (0 === $pid) { |
|
| 29 | \fclose($pair[0]); |
||
| 30 | |||
| 31 | \fwrite($pair[1], $this->single(Input::fromSafeData($request)) . "\n"); |
||
| 32 | |||
| 33 | \fclose($pair[1]); |
||
| 34 | |||
| 35 | exit(0); |
||
| 36 | } |
||
| 37 | |||
| 38 | 4 | \fclose($pair[1]); |
|
| 39 | |||
| 40 | 4 | $children[$pid] = $pair[0]; |
|
| 41 | } |
||
| 42 | |||
| 43 | 4 | while(-1 !== $pid = \pcntl_wait($status)) { |
|
| 44 | 4 | $socket = $children[$pid]; |
|
| 45 | |||
| 46 | 4 | if ('' !== $response = \trim(\fgets($socket))) { |
|
| 47 | 3 | $responses[] = $response; |
|
| 48 | } |
||
| 49 | |||
| 50 | 4 | \fclose($socket); |
|
| 51 | } |
||
| 52 | |||
| 53 | 4 | return empty($responses) ? |
|
| 54 | 4 | null : \sprintf('[%s]', \implode(',', $responses)); |
|
| 55 | } |
||
| 57 |