Completed
Push — master ( 1384b1...6391fe )
by Akihito
02:17
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/Task/Task.php 2 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,7 +18,6 @@  discard block
 block discarded – undo
18 18
     /**
19 19
      * @param   callable    $callable
20 20
      * @param   array       $args
21
-     * @param   string      $string
22 21
      */
23 22
     public function __construct($callable, $args, $tag)
24 23
     {
@@ -44,7 +43,7 @@  discard block
 block discarded – undo
44 43
     }
45 44
 
46 45
     /**
47
-     * @return  string|null
46
+     * @return  string
48 47
      */
49 48
     public function getTag()
50 49
     {
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,6 @@
 block discarded – undo
2 2
 namespace Ackintosh\Snidel\Task;
3 3
 
4 4
 use Ackintosh\Snidel\Task\TaskInterface;
5
-use Ackintosh\Snidel\Task\MinifiedTask;
6 5
 
7 6
 class Task implements TaskInterface
8 7
 {
Please login to merge, or discard this patch.
src/Snidel.php 2 patches
Doc Comments   +3 added lines, -2 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  integer
130 130
      * @throws  \RuntimeException
131 131
      */
132 132
     private function forkChild(Token $token, $callable, $args = array(), $tag = null)
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
      * gets results
227 227
      *
228 228
      * @param   string  $tag
229
-     * @return  \Ackintosh\Snidel\ForkCollection
229
+     * @return  Snidel\ResultCollection
230 230
      * @throws  \InvalidArgumentException
231 231
      */
232 232
     public function get($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->forkContainer->queuedCount());
118
+        $this->log->info('queued task #'.$this->forkContainer->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, $log, $token) {
158
+            register_shutdown_function(function() use (&$resultHasWritten, $fork, $log, $token) {
159 159
                 if (!$resultHasWritten) {
160 160
                     $dataRepository = new DataRepository();
161 161
                     $data = $dataRepository->load(getmypid());
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
             $this->wait();
236 236
         }
237 237
         if ($tag !== null && !$this->forkContainer->hasTag($tag)) {
238
-            throw new \InvalidArgumentException('unknown tag: ' . $tag);
238
+            throw new \InvalidArgumentException('unknown tag: '.$tag);
239 239
         }
240 240
 
241 241
         return $this->forkContainer->getCollection($tag);
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
     public function sendSignalToChildren($sig)
251 251
     {
252 252
         foreach ($this->forkContainer->getChildPids() as $pid) {
253
-            $this->log->info('----> sending a signal to child. pid: ' . $pid);
253
+            $this->log->info('----> sending a signal to child. pid: '.$pid);
254 254
             posix_kill($pid, $sig);
255 255
         }
256 256
     }
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 
352 352
             $childPid = $result->getFork()->getPid();
353 353
             if ($result->getFork()->hasNotFinishedSuccessfully()) {
354
-                $message = 'an error has occurred in child process. pid: ' . $childPid;
354
+                $message = 'an error has occurred in child process. pid: '.$childPid;
355 355
                 $this->log->error($message);
356 356
                 throw new \RuntimeException($message);
357 357
             }
Please login to merge, or discard this patch.
src/Snidel/ForkContainer.php 3 patches
Doc Comments   +8 added lines, -3 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 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 Task\Task $task
72 74
      * @return  void
73 75
      * @throws  \RuntimeException
74 76
      */
@@ -303,7 +305,7 @@  discard block
 block discarded – undo
303 305
     }
304 306
 
305 307
     /**
306
-     * @return  array
308
+     * @return  integer[]
307 309
      */
308 310
     public function getChildPids()
309 311
     {
@@ -314,13 +316,16 @@  discard block
 block discarded – undo
314 316
      * return fork
315 317
      *
316 318
      * @param   int     $pid
317
-     * @return  \Ackintosh\Snidel\Fork
319
+     * @return  Result
318 320
      */
319 321
     public function get($pid)
320 322
     {
321 323
         return $this->results[$pid];
322 324
     }
323 325
 
326
+    /**
327
+     * @param string $tag
328
+     */
324 329
     public function getCollection($tag = null)
325 330
     {
326 331
         if ($tag === null) {
@@ -363,7 +368,7 @@  discard block
 block discarded – undo
363 368
     }
364 369
 
365 370
     /**
366
-     * @return  \Ackintosh\Sniden\Error
371
+     * @return  Error
367 372
      */
368 373
     public function getError()
369 374
     {
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,6 @@
 block discarded – undo
2 2
 namespace Ackintosh\Snidel;
3 3
 
4 4
 use Ackintosh\Snidel\Fork;
5
-use Ackintosh\Snidel\ForkCollection;
6 5
 use Ackintosh\Snidel\Pcntl;
7 6
 use Ackintosh\Snidel\DataRepository;
8 7
 use Ackintosh\Snidel\Task\Queue as TaskQueue;
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 
141 141
         if ($pid) {
142 142
             // owner
143
-            $this->log->info('pid: ' . getmypid());
143
+            $this->log->info('pid: '.getmypid());
144 144
 
145 145
             return $this->masterPid;
146 146
         } elseif ($pid === -1) {
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
         } else {
149 149
             // master
150 150
             $taskQueue = new TaskQueue($this->ownerPid);
151
-            $this->log->info('pid: ' . $this->masterPid);
151
+            $this->log->info('pid: '.$this->masterPid);
152 152
 
153 153
             foreach ($this->signals as $sig) {
154 154
                 $this->pcntl->signal($sig, SIG_DFL, true);
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
             $workerCount = 0;
157 157
 
158 158
             while ($task = $taskQueue->dequeue()) {
159
-                $this->log->info('dequeued task #' . $taskQueue->dequeuedCount());
159
+                $this->log->info('dequeued task #'.$taskQueue->dequeuedCount());
160 160
                 if ($workerCount >= $this->concurrency) {
161 161
                     $status = null;
162 162
                     $this->pcntl->waitpid(-1, $status);
@@ -187,10 +187,10 @@  discard block
 block discarded – undo
187 187
 
188 188
         if (getmypid() === $this->masterPid) {
189 189
             // master
190
-            $this->log->info('forked worker. pid: ' . $fork->getPid());
190
+            $this->log->info('forked worker. pid: '.$fork->getPid());
191 191
         } else {
192 192
             // worker
193
-            $this->log->info('has forked. pid: ' . getmypid());
193
+            $this->log->info('has forked. pid: '.getmypid());
194 194
             // @codeCoverageIgnoreStart
195 195
 
196 196
             foreach ($this->signals as $sig) {
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 
200 200
             $resultQueue = new ResultQueue($this->ownerPid);
201 201
             $resultHasQueued = false;
202
-            register_shutdown_function(function () use (&$resultHasQueued, $fork, $resultQueue) {
202
+            register_shutdown_function(function() use (&$resultHasQueued, $fork, $resultQueue) {
203 203
                 if (!$resultHasQueued) {
204 204
                     $result = new Result();
205 205
                     $result->setFailure();
Please login to merge, or discard this patch.
src/Snidel/ResultCollection.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.