Completed
Push — master ( 4c7c4d...1a22e3 )
by Akihito
02:56
created
src/Snidel/Log.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
Switch Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -50,15 +50,15 @@
 block discarded – undo
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,
Please login to merge, or discard this patch.
src/Snidel/Token.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
src/Snidel/MapContainer.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -137,6 +137,6 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Snidel/IpcKey.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Snidel/Result/Collection.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
src/Snidel.php 2 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
      */
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
         foreach ($this->signals as $sig) {
65 65
             $this->pcntl->signal(
66 66
                 $sig,
67
-                function ($sig) use($log, $self) {
68
-                    $log->info('received signal. signo: ' . $sig);
67
+                function($sig) use($log, $self) {
68
+                    $log->info('received signal. signo: '.$sig);
69 69
                     $self->setReceivedSignal($sig);
70 70
 
71 71
                     $log->info('--> sending a signal to children.');
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
             );
78 78
         }
79 79
 
80
-        $this->log->info('parent pid: ' . $this->ownerPid);
80
+        $this->log->info('parent pid: '.$this->ownerPid);
81 81
     }
82 82
 
83 83
     /**
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
             throw $e;
116 116
         }
117 117
 
118
-        $this->log->info('queued task #' . $this->container->queuedCount());
118
+        $this->log->info('queued task #'.$this->container->queuedCount());
119 119
     }
120 120
 
121 121
     /**
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 
143 143
         if (getmypid() === $this->ownerPid) {
144 144
             // parent
145
-            $this->log->info('created child process. pid: ' . $fork->getPid());
145
+            $this->log->info('created child process. pid: '.$fork->getPid());
146 146
         } else {
147 147
             // @codeCoverageIgnoreStart
148 148
             // child
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
              */
156 156
             $log = $this->log;
157 157
             $resultHasWritten = false;
158
-            register_shutdown_function(function () use (&$resultHasWritten, $fork, $task, $log, $token) {
158
+            register_shutdown_function(function() use (&$resultHasWritten, $fork, $task, $log, $token) {
159 159
                 if (!$resultHasWritten) {
160 160
                     $dataRepository = new DataRepository();
161 161
                     $data = $dataRepository->load(getmypid());
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
             $this->wait();
238 238
         }
239 239
         if ($tag !== null && !$this->container->hasTag($tag)) {
240
-            throw new \InvalidArgumentException('unknown tag: ' . $tag);
240
+            throw new \InvalidArgumentException('unknown tag: '.$tag);
241 241
         }
242 242
 
243 243
         return $this->container->getCollection($tag);
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
     public function sendSignalToChildren($sig)
253 253
     {
254 254
         foreach ($this->container->getChildPids() as $pid) {
255
-            $this->log->info('----> sending a signal to child. pid: ' . $pid);
255
+            $this->log->info('----> sending a signal to child. pid: '.$pid);
256 256
             posix_kill($pid, $sig);
257 257
         }
258 258
     }
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 
354 354
             $childPid = $result->getFork()->getPid();
355 355
             if ($result->isFailure()) {
356
-                $message = 'an error has occurred in child process. pid: ' . $childPid;
356
+                $message = 'an error has occurred in child process. pid: '.$childPid;
357 357
                 $this->log->error($message);
358 358
                 throw new \RuntimeException($message);
359 359
             }
Please login to merge, or discard this patch.
src/Snidel/Fork/Container.php 2 patches
Doc Comments   +9 added lines, -4 removed lines patch added patch discarded remove patch
@@ -54,6 +54,7 @@  discard block
 block discarded – undo
54 54
 
55 55
     /**
56 56
      * @param   int     $ownerPid
57
+     * @param \Ackintosh\Snidel\Log $log
57 58
      */
58 59
     public function __construct($ownerPid, $log, $concurrency = 5)
59 60
     {
@@ -69,6 +70,7 @@  discard block
 block discarded – undo
69 70
 
70 71
     /**
71 72
      * @param   \Ackintosh\Snidel\Task
73
+     * @param \Ackintosh\Snidel\Task\Task $task
72 74
      * @return  void
73 75
      * @throws  \RuntimeException
74 76
      */
@@ -90,7 +92,7 @@  discard block
 block discarded – undo
90 92
     }
91 93
 
92 94
     /**
93
-     * @return  \Ackintosh\Snidel\Fork\Fork
95
+     * @return  Result
94 96
      */
95 97
     private function dequeue()
96 98
     {
@@ -304,7 +306,7 @@  discard block
 block discarded – undo
304 306
     }
305 307
 
306 308
     /**
307
-     * @return  array
309
+     * @return  integer[]
308 310
      */
309 311
     public function getChildPids()
310 312
     {
@@ -315,13 +317,16 @@  discard block
 block discarded – undo
315 317
      * return fork
316 318
      *
317 319
      * @param   int     $pid
318
-     * @return  \Ackintosh\Snidel\Fork\Fork
320
+     * @return  Result
319 321
      */
320 322
     public function get($pid)
321 323
     {
322 324
         return $this->results[$pid];
323 325
     }
324 326
 
327
+    /**
328
+     * @param string $tag
329
+     */
325 330
     public function getCollection($tag = null)
326 331
     {
327 332
         if ($tag === null) {
@@ -364,7 +369,7 @@  discard block
 block discarded – undo
364 369
     }
365 370
 
366 371
     /**
367
-     * @return  \Ackintosh\Sniden\Error
372
+     * @return  Error
368 373
      */
369 374
     public function getError()
370 375
     {
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 
143 143
         if ($pid) {
144 144
             // owner
145
-            $this->log->info('pid: ' . getmypid());
145
+            $this->log->info('pid: '.getmypid());
146 146
 
147 147
             return $this->masterPid;
148 148
         } elseif ($pid === -1) {
@@ -150,15 +150,15 @@  discard block
 block discarded – undo
150 150
         } else {
151 151
             // master
152 152
             $taskQueue = new TaskQueue($this->ownerPid);
153
-            $this->log->info('pid: ' . $this->masterPid);
153
+            $this->log->info('pid: '.$this->masterPid);
154 154
 
155 155
             $log    = $this->log;
156 156
             $pcntl  = $this->pcntl;
157 157
             foreach ($this->signals as $sig) {
158
-                $this->pcntl->signal($sig, function ($sig) use ($log, $pcntl) {
159
-                    $log->info('received signal: ' . $sig);
158
+                $this->pcntl->signal($sig, function($sig) use ($log, $pcntl) {
159
+                    $log->info('received signal: '.$sig);
160 160
                     foreach (array_keys($this->workerPids) as $pid) {
161
-                        $log->info('------> sending signal to worker. signal: ' . $sig);
161
+                        $log->info('------> sending signal to worker. signal: '.$sig);
162 162
                         posix_kill($pid, $sig);
163 163
                         $log->info('<------ sent signal');
164 164
                         $status = null;
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
             }
170 170
 
171 171
             while ($task = $taskQueue->dequeue()) {
172
-                $this->log->info('dequeued task #' . $taskQueue->dequeuedCount());
172
+                $this->log->info('dequeued task #'.$taskQueue->dequeuedCount());
173 173
                 if (count($this->workerPids) >= $this->concurrency) {
174 174
                     $status = null;
175 175
                     $workerPid = $this->pcntl->waitpid(-1, $status);
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
 
201 201
         if (getmypid() === $this->masterPid) {
202 202
             // master
203
-            $this->log->info('forked worker. pid: ' . $fork->getPid());
203
+            $this->log->info('forked worker. pid: '.$fork->getPid());
204 204
             return $fork->getPid();
205 205
         } else {
206 206
             // worker
207
-            $this->log->info('has forked. pid: ' . getmypid());
207
+            $this->log->info('has forked. pid: '.getmypid());
208 208
             // @codeCoverageIgnoreStart
209 209
 
210 210
             foreach ($this->signals as $sig) {
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 
214 214
             $resultQueue = new ResultQueue($this->ownerPid);
215 215
             $resultHasQueued = false;
216
-            register_shutdown_function(function () use (&$resultHasQueued, $fork, $task, $resultQueue) {
216
+            register_shutdown_function(function() use (&$resultHasQueued, $fork, $task, $resultQueue) {
217 217
                 if (!$resultHasQueued) {
218 218
                     $result = new Result();
219 219
                     $result->setError(error_get_last());
@@ -257,13 +257,13 @@  discard block
 block discarded – undo
257 257
      */
258 258
     public function sendSignalToMaster($sig = SIGTERM)
259 259
     {
260
-        $this->log->info('----> sending signal to master. signal: ' . $sig);
260
+        $this->log->info('----> sending signal to master. signal: '.$sig);
261 261
         posix_kill($this->masterPid, $sig);
262 262
         $this->log->info('<---- sent signal.');
263 263
 
264 264
         $status = null;
265 265
         $this->pcntl->waitpid($this->masterPid, $status);
266
-        $this->log->info('. status: ' . $status);
266
+        $this->log->info('. status: '.$status);
267 267
         $this->masterPid = null;
268 268
     }
269 269
 
Please login to merge, or discard this patch.