| Total Complexity | 6 |
| Total Lines | 76 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class Process implements ProcessInterface |
||
| 13 | { |
||
| 14 | const LINUX_STYLE = 'linux'; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var ProcessInterface |
||
| 18 | */ |
||
| 19 | protected $process; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var LoggerInterface |
||
| 23 | */ |
||
| 24 | protected $logger; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Process constructor. |
||
| 28 | * |
||
| 29 | * @param string $style |
||
| 30 | 25 | * @param LoggerInterface|null $logger |
|
| 31 | */ |
||
| 32 | 25 | public function __construct(string $style = self::LINUX_STYLE, LoggerInterface $logger = null) |
|
| 33 | 25 | { |
|
| 34 | 25 | if ($logger === null) { |
|
| 35 | 25 | $logger = new NullLogger(); |
|
| 36 | 25 | } |
|
| 37 | 25 | $this->process = $this->getProcess($style, $logger); |
|
| 38 | $this->logger = $logger; |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Create "internal styled" process. |
||
| 43 | * |
||
| 44 | * @param string $style |
||
| 45 | * @param LoggerInterface $logger |
||
| 46 | * |
||
| 47 | 25 | * @throws UnsupportedSystemException |
|
| 48 | */ |
||
| 49 | protected function getProcess(string $style, LoggerInterface $logger): ProcessInterface |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Check whether a pid is running. |
||
| 65 | * |
||
| 66 | * @throws Exception\InvalidArgumentException |
||
| 67 | * |
||
| 68 | * @param int $pid |
||
| 69 | */ |
||
| 70 | 16 | public function isRunning(int $pid): bool |
|
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Kill a process. |
||
| 77 | * |
||
| 78 | * @throws Exception\InvalidArgumentException |
||
| 79 | * |
||
| 80 | * @param int $pid |
||
| 81 | * @param bool $wait |
||
| 82 | * |
||
| 83 | * @return bool |
||
| 84 | */ |
||
| 85 | 14 | public function kill(int $pid, bool $wait = false): bool |
|
| 90 |