slince /
process
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Process Library |
||
| 4 | * @author Tao <[email protected]> |
||
| 5 | */ |
||
| 6 | namespace Slince\Process; |
||
| 7 | |||
| 8 | class Status |
||
| 9 | { |
||
| 10 | protected $status; |
||
| 11 | |||
| 12 | protected $isExited = false; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * exit code |
||
| 16 | * @var int |
||
| 17 | */ |
||
| 18 | protected $exitCode; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * error message |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $errorMessage; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * If the signal that caused the process to terminate |
||
| 28 | * @var boolean |
||
| 29 | */ |
||
| 30 | protected $isSignaled = false; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * The signal that caused the process to terminate |
||
| 34 | * @var int |
||
| 35 | */ |
||
| 36 | protected $terminateSignal; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * The process If stopped |
||
| 40 | * @var bool |
||
| 41 | */ |
||
| 42 | protected $isStopped = false; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * The signal that caused the process to stop |
||
| 46 | * @var int |
||
| 47 | */ |
||
| 48 | protected $stopSignal; |
||
| 49 | |||
| 50 | public function __construct($status) |
||
| 51 | { |
||
| 52 | $this->status = $status; |
||
| 53 | if ($this->isExited = pcntl_wifexited($status)) { |
||
| 54 | $this->exitCode = pcntl_wexitstatus($status); |
||
| 55 | $this->errorMessage = pcntl_strerror($this->exitCode); |
||
| 56 | } |
||
| 57 | if (pcntl_wifsignaled($status)) { |
||
| 58 | $this->isSignaled = true; |
||
| 59 | $this->terminateSignal = pcntl_wtermsig($status); |
||
| 60 | } |
||
| 61 | if (pcntl_wifstopped($status)) { |
||
| 62 | $this->isStopped = true; |
||
| 63 | $this->stopSignal = pcntl_wifstopped($status); |
||
|
0 ignored issues
–
show
|
|||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Checks if status code represents a normal exit. |
||
| 69 | * @return bool |
||
| 70 | */ |
||
| 71 | public function isExited() |
||
| 72 | { |
||
| 73 | return $this->isExited; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Gets the exit code if the process is exited normally |
||
| 78 | * @return int |
||
| 79 | */ |
||
| 80 | public function getExitCode() |
||
| 81 | { |
||
| 82 | return $this->exitCode; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @return string |
||
| 87 | */ |
||
| 88 | public function getErrorMessage() |
||
| 89 | { |
||
| 90 | return $this->errorMessage; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Check whether the process exits because of an signal |
||
| 95 | * return boolean |
||
| 96 | */ |
||
| 97 | public function isSignaled() |
||
| 98 | { |
||
| 99 | return $this->isSignaled; |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Gets the signal which caused the child to terminate. |
||
| 104 | * @return int |
||
| 105 | */ |
||
| 106 | public function getTerminateSignal() |
||
| 107 | { |
||
| 108 | return $this->terminateSignal; |
||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Checks whether the child process is currently stopped. |
||
| 113 | * @return bool |
||
| 114 | */ |
||
| 115 | public function isStopped() |
||
| 116 | { |
||
| 117 | return $this->isStopped; |
||
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Gets the signal which caused the child to stop. |
||
| 122 | * @return int |
||
| 123 | */ |
||
| 124 | public function getStopSignal() |
||
| 125 | { |
||
| 126 | return $this->stopSignal; |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Checks whether the process is executed successfully |
||
| 131 | * @return bool |
||
| 132 | */ |
||
| 133 | public function isSuccessful() |
||
| 134 | { |
||
| 135 | return $this->exitCode === 0; |
||
| 136 | } |
||
| 137 | } |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.