| @@ -49,7 +49,7 @@ | ||
| 49 | 49 | $type, | 
| 50 | 50 | $pid, | 
| 51 | 51 | ($this->ownerPid === $pid) ? 'p' : 'c', | 
| 52 | - $message . PHP_EOL | |
| 52 | + $message.PHP_EOL | |
| 53 | 53 | ) | 
| 54 | 54 | ); | 
| 55 | 55 | } | 
| @@ -50,15 +50,15 @@ | ||
| 50 | 50 | } | 
| 51 | 51 | $pid = getmypid(); | 
| 52 | 52 |          switch (true) { | 
| 53 | - case $this->ownerPid === $pid: | |
| 54 | - $role = 'owner'; | |
| 55 | - break; | |
| 56 | - case $this->masterPid === $pid: | |
| 57 | - $role = 'master'; | |
| 58 | - break; | |
| 59 | - default: | |
| 60 | - $role = 'worker'; | |
| 61 | - break; | |
| 53 | + case $this->ownerPid === $pid: | |
| 54 | + $role = 'owner'; | |
| 55 | + break; | |
| 56 | + case $this->masterPid === $pid: | |
| 57 | + $role = 'master'; | |
| 58 | + break; | |
| 59 | + default: | |
| 60 | + $role = 'worker'; | |
| 61 | + break; | |
| 62 | 62 | } | 
| 63 | 63 | fputs( | 
| 64 | 64 | $this->destination, | 
| @@ -28,7 +28,7 @@ | ||
| 28 | 28 |      { | 
| 29 | 29 | $this->ownerPid = $ownerPid; | 
| 30 | 30 | $this->concurrency = $concurrency; | 
| 31 | - $this->ipcKey = new IpcKey($ownerPid, 'snidel_token_' . uniqid((string) mt_rand(1, 100), true)); | |
| 31 | + $this->ipcKey = new IpcKey($ownerPid, 'snidel_token_'.uniqid((string) mt_rand(1, 100), true)); | |
| 32 | 32 | $this->id = msg_get_queue($this->ipcKey->generate()); | 
| 33 | 33 | $this->initializeQueue(); | 
| 34 | 34 | } | 
| @@ -137,6 +137,6 @@ | ||
| 137 | 137 | return $index; | 
| 138 | 138 | } | 
| 139 | 139 | |
| 140 | -        throw new MapContainerException('childPid not found. pid: ' . $childPid); | |
| 140 | +        throw new MapContainerException('childPid not found. pid: '.$childPid); | |
| 141 | 141 | } | 
| 142 | 142 | } | 
| @@ -26,7 +26,7 @@ discard block | ||
| 26 | 26 | */ | 
| 27 | 27 | public function generate() | 
| 28 | 28 |      { | 
| 29 | - $pathname = '/tmp/' . $this->prefix . $this->ownerPid; | |
| 29 | + $pathname = '/tmp/'.$this->prefix.$this->ownerPid; | |
| 30 | 30 |          if (!file_exists($pathname)) { | 
| 31 | 31 | touch($pathname); | 
| 32 | 32 | } | 
| @@ -52,8 +52,8 @@ discard block | ||
| 52 | 52 | */ | 
| 53 | 53 | public function delete() | 
| 54 | 54 |      { | 
| 55 | -        if (file_exists('/tmp/' . $this->prefix . $this->ownerPid)) { | |
| 56 | -            unlink('/tmp/' . $this->prefix . $this->ownerPid); | |
| 55 | +        if (file_exists('/tmp/'.$this->prefix.$this->ownerPid)) { | |
| 56 | +            unlink('/tmp/'.$this->prefix.$this->ownerPid); | |
| 57 | 57 | } | 
| 58 | 58 | } | 
| 59 | 59 | } | 
| @@ -26,7 +26,7 @@ | ||
| 26 | 26 | public function toArray() | 
| 27 | 27 |      { | 
| 28 | 28 | return array_map( | 
| 29 | -            function ($result) { | |
| 29 | +            function($result) { | |
| 30 | 30 | return $result->getReturn(); | 
| 31 | 31 | }, | 
| 32 | 32 | $this->results | 
| @@ -126,7 +126,7 @@ discard block | ||
| 126 | 126 | * @param mixed $args | 
| 127 | 127 | * @param string $tag | 
| 128 | 128 | * @param \Ackintosh\Snidel\Token $token | 
| 129 | - * @return void | |
| 129 | + * @return null|integer | |
| 130 | 130 | * @throws \RuntimeException | 
| 131 | 131 | */ | 
| 132 | 132 | private function forkChild(Token $token, $callable, $args = array(), $tag = null) | 
| @@ -313,6 +313,7 @@ discard block | ||
| 313 | 313 | * fork the first processing of the map container | 
| 314 | 314 | * | 
| 315 | 315 | * @param \Ackintosh\Snidel\MapContainer | 
| 316 | + * @param Token $token | |
| 316 | 317 | * @return void | 
| 317 | 318 | * @throws \RuntimeException | 
| 318 | 319 | */ | 
| @@ -61,8 +61,8 @@ discard block | ||
| 61 | 61 |          foreach ($this->signals as $sig) { | 
| 62 | 62 | $this->pcntl->signal( | 
| 63 | 63 | $sig, | 
| 64 | -                function ($sig) use($log, $self) { | |
| 65 | -                    $log->info('received signal. signo: ' . $sig); | |
| 64 | +                function($sig) use($log, $self) { | |
| 65 | +                    $log->info('received signal. signo: '.$sig); | |
| 66 | 66 | $self->setReceivedSignal($sig); | 
| 67 | 67 | |
| 68 | 68 |                      $log->info('--> sending a signal " to children.'); | 
| @@ -74,7 +74,7 @@ discard block | ||
| 74 | 74 | ); | 
| 75 | 75 | } | 
| 76 | 76 | |
| 77 | -        $this->log->info('parent pid: ' . $this->ownerPid); | |
| 77 | +        $this->log->info('parent pid: '.$this->ownerPid); | |
| 78 | 78 | } | 
| 79 | 79 | |
| 80 | 80 | /** | 
| @@ -112,7 +112,7 @@ discard block | ||
| 112 | 112 | throw $e; | 
| 113 | 113 | } | 
| 114 | 114 | |
| 115 | -        $this->log->info('queued task #' . $this->container->queuedCount()); | |
| 115 | +        $this->log->info('queued task #'.$this->container->queuedCount()); | |
| 116 | 116 | } | 
| 117 | 117 | |
| 118 | 118 | /** | 
| @@ -139,7 +139,7 @@ discard block | ||
| 139 | 139 | |
| 140 | 140 |          if (getmypid() === $this->ownerPid) { | 
| 141 | 141 | // parent | 
| 142 | -            $this->log->info('created child process. pid: ' . $fork->getPid()); | |
| 142 | +            $this->log->info('created child process. pid: '.$fork->getPid()); | |
| 143 | 143 |          } else { | 
| 144 | 144 | // @codeCoverageIgnoreStart | 
| 145 | 145 | // child | 
| @@ -152,7 +152,7 @@ discard block | ||
| 152 | 152 | */ | 
| 153 | 153 | $log = $this->log; | 
| 154 | 154 | $resultHasWritten = false; | 
| 155 | -            register_shutdown_function(function () use (&$resultHasWritten, $fork, $task, $log, $token) { | |
| 155 | +            register_shutdown_function(function() use (&$resultHasWritten, $fork, $task, $log, $token) { | |
| 156 | 156 |                  if (!$resultHasWritten) { | 
| 157 | 157 | $dataRepository = new DataRepository(); | 
| 158 | 158 | $data = $dataRepository->load(getmypid()); | 
| @@ -234,7 +234,7 @@ discard block | ||
| 234 | 234 | $this->wait(); | 
| 235 | 235 | } | 
| 236 | 236 |          if ($tag !== null && !$this->container->hasTag($tag)) { | 
| 237 | -            throw new \InvalidArgumentException('unknown tag: ' . $tag); | |
| 237 | +            throw new \InvalidArgumentException('unknown tag: '.$tag); | |
| 238 | 238 | } | 
| 239 | 239 | |
| 240 | 240 | return $this->container->getCollection($tag); | 
| @@ -249,7 +249,7 @@ discard block | ||
| 249 | 249 | public function sendSignalToChildren($sig) | 
| 250 | 250 |      { | 
| 251 | 251 |          foreach ($this->container->getChildrend() as $child) { | 
| 252 | -            $this->log->info('----> sending a signal to child. pid: ' . $child->getPid()); | |
| 252 | +            $this->log->info('----> sending a signal to child. pid: '.$child->getPid()); | |
| 253 | 253 | posix_kill($child->getPid(), $sig); | 
| 254 | 254 | } | 
| 255 | 255 | } | 
| @@ -350,7 +350,7 @@ discard block | ||
| 350 | 350 | |
| 351 | 351 | $childPid = $result->getFork()->getPid(); | 
| 352 | 352 |              if ($result->isFailure()) { | 
| 353 | - $message = 'an error has occurred in child process. pid: ' . $childPid; | |
| 353 | + $message = 'an error has occurred in child process. pid: '.$childPid; | |
| 354 | 354 | $this->log->error($message); | 
| 355 | 355 | throw new \RuntimeException($message); | 
| 356 | 356 | } | 
| @@ -149,24 +149,24 @@ discard block | ||
| 149 | 149 | |
| 150 | 150 |          if (getmypid() === $this->ownerPid) { | 
| 151 | 151 | // owner | 
| 152 | -            $this->log->info('pid: ' . getmypid()); | |
| 152 | +            $this->log->info('pid: '.getmypid()); | |
| 153 | 153 | |
| 154 | 154 | return $this->masterPid; | 
| 155 | 155 |          } else { | 
| 156 | 156 | // master | 
| 157 | 157 | $taskQueue = new TaskQueue($this->ownerPid); | 
| 158 | 158 | $activeWorkerSet = new ActiveWorkerSet(); | 
| 159 | -            $this->log->info('pid: ' . $this->masterPid); | |
| 159 | +            $this->log->info('pid: '.$this->masterPid); | |
| 160 | 160 | |
| 161 | 161 | $log = $this->log; | 
| 162 | 162 |              foreach ($this->signals as $sig) { | 
| 163 | -                $this->pcntl->signal($sig, function ($sig) use ($log, $activeWorkerSet) { | |
| 164 | -                    $log->info('received signal: ' . $sig); | |
| 163 | +                $this->pcntl->signal($sig, function($sig) use ($log, $activeWorkerSet) { | |
| 164 | +                    $log->info('received signal: '.$sig); | |
| 165 | 165 | |
| 166 | 166 |                      if ($activeWorkerSet->count() === 0) { | 
| 167 | 167 |                          $log->info('no worker is active.'); | 
| 168 | 168 |                      } else { | 
| 169 | -                        $log->info('------> sending signal to workers. signal: ' . $sig); | |
| 169 | +                        $log->info('------> sending signal to workers. signal: '.$sig); | |
| 170 | 170 | $activeWorkerSet->terminate($sig); | 
| 171 | 171 |                          $log->info('<------ sent signal'); | 
| 172 | 172 | } | 
| @@ -175,7 +175,7 @@ discard block | ||
| 175 | 175 | } | 
| 176 | 176 | |
| 177 | 177 |              while ($task = $taskQueue->dequeue()) { | 
| 178 | -                $this->log->info('dequeued task #' . $taskQueue->dequeuedCount()); | |
| 178 | +                $this->log->info('dequeued task #'.$taskQueue->dequeuedCount()); | |
| 179 | 179 |                  if ($activeWorkerSet->count() >= $this->concurrency) { | 
| 180 | 180 | $status = null; | 
| 181 | 181 | $workerPid = $this->pcntl->waitpid(-1, $status); | 
| @@ -209,11 +209,11 @@ discard block | ||
| 209 | 209 | |
| 210 | 210 |          if (getmypid() === $this->masterPid) { | 
| 211 | 211 | // master | 
| 212 | -            $this->log->info('forked worker. pid: ' . $worker->getPid()); | |
| 212 | +            $this->log->info('forked worker. pid: '.$worker->getPid()); | |
| 213 | 213 | return $worker; | 
| 214 | 214 |          } else { | 
| 215 | 215 | // worker | 
| 216 | -            $this->log->info('has forked. pid: ' . getmypid()); | |
| 216 | +            $this->log->info('has forked. pid: '.getmypid()); | |
| 217 | 217 | // @codeCoverageIgnoreStart | 
| 218 | 218 | |
| 219 | 219 |              foreach ($this->signals as $sig) { | 
| @@ -223,7 +223,7 @@ discard block | ||
| 223 | 223 | $worker->setResultQueue(new ResultQueue($this->ownerPid)); | 
| 224 | 224 | |
| 225 | 225 | $resultHasQueued = false; | 
| 226 | -            register_shutdown_function(function () use (&$resultHasQueued, $worker) { | |
| 226 | +            register_shutdown_function(function() use (&$resultHasQueued, $worker) { | |
| 227 | 227 |                  if (!$resultHasQueued) { | 
| 228 | 228 | $worker->error(); | 
| 229 | 229 | } | 
| @@ -260,13 +260,13 @@ discard block | ||
| 260 | 260 | */ | 
| 261 | 261 | public function sendSignalToMaster($sig = SIGTERM) | 
| 262 | 262 |      { | 
| 263 | -        $this->log->info('----> sending signal to master. signal: ' . $sig); | |
| 263 | +        $this->log->info('----> sending signal to master. signal: '.$sig); | |
| 264 | 264 | posix_kill($this->masterPid, $sig); | 
| 265 | 265 |          $this->log->info('<---- sent signal.'); | 
| 266 | 266 | |
| 267 | 267 | $status = null; | 
| 268 | 268 | $this->pcntl->waitpid($this->masterPid, $status); | 
| 269 | -        $this->log->info('. status: ' . $status); | |
| 269 | +        $this->log->info('. status: '.$status); | |
| 270 | 270 | $this->masterPid = null; | 
| 271 | 271 | } | 
| 272 | 272 | |
| @@ -59,6 +59,7 @@ discard block | ||
| 59 | 59 | |
| 60 | 60 | /** | 
| 61 | 61 | * @param int $ownerPid | 
| 62 | + * @param \Ackintosh\Snidel\Log $log | |
| 62 | 63 | */ | 
| 63 | 64 | public function __construct($ownerPid, $log, $concurrency = 5) | 
| 64 | 65 |      { | 
| @@ -74,6 +75,7 @@ discard block | ||
| 74 | 75 | |
| 75 | 76 | /** | 
| 76 | 77 | * @param \Ackintosh\Snidel\Task | 
| 78 | + * @param \Ackintosh\Snidel\Task\Task $task | |
| 77 | 79 | * @return void | 
| 78 | 80 | * @throws \RuntimeException | 
| 79 | 81 | */ | 
| @@ -95,7 +97,7 @@ discard block | ||
| 95 | 97 | } | 
| 96 | 98 | |
| 97 | 99 | /** | 
| 98 | - * @return \Ackintosh\Snidel\Fork\Fork | |
| 100 | + * @return Result | |
| 99 | 101 | */ | 
| 100 | 102 | private function dequeue() | 
| 101 | 103 |      { | 
| @@ -345,7 +347,7 @@ discard block | ||
| 345 | 347 | } | 
| 346 | 348 | |
| 347 | 349 | /** | 
| 348 | - * @return array | |
| 350 | + * @return Fork[] | |
| 349 | 351 | */ | 
| 350 | 352 | public function getChildren() | 
| 351 | 353 |      { | 
| @@ -356,13 +358,16 @@ discard block | ||
| 356 | 358 | * return fork | 
| 357 | 359 | * | 
| 358 | 360 | * @param int $pid | 
| 359 | - * @return \Ackintosh\Snidel\Fork\Fork | |
| 361 | + * @return Result | |
| 360 | 362 | */ | 
| 361 | 363 | public function get($pid) | 
| 362 | 364 |      { | 
| 363 | 365 | return $this->results[$pid]; | 
| 364 | 366 | } | 
| 365 | 367 | |
| 368 | + /** | |
| 369 | + * @param string $tag | |
| 370 | + */ | |
| 366 | 371 | public function getCollection($tag = null) | 
| 367 | 372 |      { | 
| 368 | 373 |          if ($tag === null) { | 
| @@ -405,7 +410,7 @@ discard block | ||
| 405 | 410 | } | 
| 406 | 411 | |
| 407 | 412 | /** | 
| 408 | - * @return \Ackintosh\Sniden\Error | |
| 413 | + * @return Error | |
| 409 | 414 | */ | 
| 410 | 415 | public function getError() | 
| 411 | 416 |      { |