1 | <?php |
||
17 | class ForkHandler implements ThreadInterface |
||
18 | { |
||
19 | protected $_threadKey; |
||
20 | private $callable; |
||
21 | private $_pid; |
||
22 | |||
23 | /** |
||
24 | * constructor method |
||
25 | * |
||
26 | * @throws RuntimeException |
||
27 | * @throws InvalidArgumentException |
||
28 | */ |
||
29 | public function __construct() |
||
38 | |||
39 | /** |
||
40 | * Private function for set the method will be forked; |
||
41 | * |
||
42 | * @param callable $callable string with the function name or a array with the instance and the method name |
||
43 | * @return mixed|void |
||
44 | */ |
||
45 | public function setCallable(callable $callable) |
||
49 | |||
50 | /** |
||
51 | * Start the thread |
||
52 | * |
||
53 | * @throws RuntimeException |
||
54 | */ |
||
55 | public function execute() |
||
85 | |||
86 | /** |
||
87 | * Save the thread result in a shared memory block |
||
88 | * |
||
89 | * @param mixed $object Need to be serializable |
||
90 | */ |
||
91 | protected function saveResult($object) |
||
96 | |||
97 | /** |
||
98 | * Get the thread result from the shared memory block and erase it |
||
99 | * |
||
100 | * @return mixed |
||
101 | */ |
||
102 | public function getResult() |
||
117 | |||
118 | /** |
||
119 | * Kill a thread |
||
120 | * |
||
121 | * @param int $signal |
||
122 | * @param bool $wait |
||
123 | */ |
||
124 | public function stop($signal = SIGKILL, $wait = false) |
||
135 | |||
136 | /** |
||
137 | * Check if the forked process is alive |
||
138 | * @return bool |
||
139 | */ |
||
140 | public function isAlive() |
||
145 | |||
146 | /** |
||
147 | * Handle the signal to the thread |
||
148 | * |
||
149 | * @param int $signal |
||
150 | */ |
||
151 | private function signalHandler($signal) |
||
158 | |||
159 | public function waitFinish() |
||
163 | } |
||
164 |
This check looks for the bodies of
if
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
if
bodies can be removed. If you have an empty if but statements in theelse
branch, consider inverting the condition.could be turned into
This is much more concise to read.