Completed
Push — master ( 46d274...68dfed )
by Akihito
02:24
created
src/Snidel/ForkCollection.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
     public function toArray()
21 21
     {
22 22
         return array_map(
23
-            function ($fork) {
23
+            function($fork) {
24 24
                 return $fork->getResult()->getReturn();
25 25
             },
26 26
             $this->forks
Please login to merge, or discard this patch.
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 !== null && $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 !== null && $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/ResultQueue.php 2 patches
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\IpcKey;
5
-use Opis\Closure\SerializableClosure;
6 5
 
7 6
 class ResultQueue
8 7
 {
Please login to merge, or discard this patch.
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -11,6 +11,9 @@
 block discarded – undo
11 11
     private $queuedCount = 0;
12 12
     private $dequeuedCount = 0;
13 13
 
14
+    /**
15
+     * @param integer $ownerPid
16
+     */
14 17
     public function __construct($ownerPid)
15 18
     {
16 19
         $this->ownerPid = $ownerPid;
Please login to merge, or discard this patch.
src/Snidel/TaskQueue.php 1 patch
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -11,6 +11,9 @@
 block discarded – undo
11 11
     private $queuedCount = 0;
12 12
     private $dequeuedCount = 0;
13 13
 
14
+    /**
15
+     * @param integer $ownerPid
16
+     */
14 17
     public function __construct($ownerPid)
15 18
     {
16 19
         $this->ownerPid = $ownerPid;
Please login to merge, or discard this patch.
src/Snidel/ForkContainer.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -98,8 +98,8 @@
 block discarded – undo
98 98
      */
99 99
     private function getCollectionWithTag($tag)
100 100
     {
101
-        $collection = array_filter($this->forks, function ($fork) use ($tag) {
102
-            return $fork->getTag() ===  $tag;
101
+        $collection = array_filter($this->forks, function($fork) use ($tag) {
102
+            return $fork->getTag() === $tag;
103 103
         });
104 104
 
105 105
         return new ForkCollection($collection);
Please login to merge, or discard this patch.
src/Snidel/Task.php 1 patch
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
     /**
17 17
      * @param   callable    $callable
18 18
      * @param   array       $args
19
-     * @param   string      $string
19
+     * @param string|null $tag
20 20
      */
21 21
     public function __construct($callable, $args, $tag)
22 22
     {
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
     }
61 61
 
62 62
     /**
63
-     * @return  string|null
63
+     * @return  string
64 64
      */
65 65
     public function getTag()
66 66
     {
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
@@ -180,6 +180,7 @@  discard block
 block discarded – undo
180 180
      * fork worker process
181 181
      *
182 182
      * @param   \Ackintosh\Snidel\Task
183
+     * @param Task $task
183 184
      * @return  void
184 185
      * @throws  \RuntimeException
185 186
      */
@@ -239,7 +240,7 @@  discard block
 block discarded – undo
239 240
      * @param   mixed                       $args
240 241
      * @param   string                      $tag
241 242
      * @param   \Ackintosh\Snidel\Token     $token
242
-     * @return  void
243
+     * @return  integer
243 244
      * @throws  \RuntimeException
244 245
      */
245 246
     public function forkSimply($callable, $args = array(), $tag = null, Token $token = null)
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
         foreach ($this->signals as $sig) {
86 86
             $this->pcntl->signal(
87 87
                 $sig,
88
-                function ($sig) use($log, $token, $self) {
89
-                    $log->info('received signal. signo: ' . $sig);
88
+                function($sig) use($log, $token, $self) {
89
+                    $log->info('received signal. signo: '.$sig);
90 90
                     $self->setReceivedSignal($sig);
91 91
 
92 92
                     $log->info('--> sending a signal to children.');
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
             );
103 103
         }
104 104
 
105
-        $this->log->info('parent pid: ' . $this->ownerPid);
105
+        $this->log->info('parent pid: '.$this->ownerPid);
106 106
     }
107 107
 
108 108
     /**
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
             throw $e;
139 139
         }
140 140
 
141
-        $this->log->info('queued task #' . $this->forkContainer->queuedCount());
141
+        $this->log->info('queued task #'.$this->forkContainer->queuedCount());
142 142
     }
143 143
 
144 144
     /**
@@ -154,20 +154,20 @@  discard block
 block discarded – undo
154 154
 
155 155
         if ($pid) {
156 156
             // owner
157
-            $this->log->info('pid: ' . getmypid());
157
+            $this->log->info('pid: '.getmypid());
158 158
         } elseif ($pid === -1) {
159 159
             // error
160 160
         } else {
161 161
             // master
162 162
             $taskQueue = new TaskQueue($this->ownerPid);
163
-            $this->log->info('pid: ' . $this->masterProcessId);
163
+            $this->log->info('pid: '.$this->masterProcessId);
164 164
 
165 165
             foreach ($this->signals as $sig) {
166 166
                 $this->pcntl->signal($sig, SIG_DFL, true);
167 167
             }
168 168
 
169 169
             while ($task = $taskQueue->dequeue()) {
170
-                $this->log->info('dequeued task #' . $taskQueue->dequeuedCount());
170
+                $this->log->info('dequeued task #'.$taskQueue->dequeuedCount());
171 171
                 if ($this->token->accept()) {
172 172
                     $this->forkWorker($task);
173 173
                 }
@@ -196,10 +196,10 @@  discard block
 block discarded – undo
196 196
 
197 197
         if (getmypid() === $this->masterProcessId) {
198 198
             // master
199
-            $this->log->info('forked worker. pid: ' . $fork->getPid());
199
+            $this->log->info('forked worker. pid: '.$fork->getPid());
200 200
         } else {
201 201
             // worker
202
-            $this->log->info('has forked. pid: ' . getmypid());
202
+            $this->log->info('has forked. pid: '.getmypid());
203 203
             // @codeCoverageIgnoreStart
204 204
 
205 205
             foreach ($this->signals as $sig) {
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
             }
208 208
 
209 209
             $resultQueue = new ResultQueue($this->ownerPid);
210
-            register_shutdown_function(function () use ($fork, $resultQueue) {
210
+            register_shutdown_function(function() use ($fork, $resultQueue) {
211 211
                 if ($fork->hasNoResult() || !$fork->isQueued()) {
212 212
                     $result = new Result();
213 213
                     $result->setFailure();
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 
259 259
         if (getmypid() === $this->ownerPid) {
260 260
             // parent
261
-            $this->log->info('created child process. pid: ' . $fork->getPid());
261
+            $this->log->info('created child process. pid: '.$fork->getPid());
262 262
             $this->childPids[] = $fork->getPid();
263 263
         } else {
264 264
             // @codeCoverageIgnoreStart
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
             $dataRepository     = $this->dataRepository;
274 274
             $log                = $this->log;
275 275
             $processToken       = $this->processToken;
276
-            register_shutdown_function(function () use ($fork, $dataRepository, $log, $processToken) {
276
+            register_shutdown_function(function() use ($fork, $dataRepository, $log, $processToken) {
277 277
                 $data = $dataRepository->load(getmypid());
278 278
                 try {
279 279
                     $data->write($fork);
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
             }
321 321
 
322 322
             if ($fork->hasNotFinishedSuccessfully()) {
323
-                $message = 'an error has occurred in child process. pid: ' . $fork->getPid();
323
+                $message = 'an error has occurred in child process. pid: '.$fork->getPid();
324 324
                 $this->log->error($message);
325 325
             }
326 326
             unset($this->childPids[array_search($fork->getPid(), $this->childPids)]);
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
         }
374 374
 
375 375
         if (!$this->forkContainer->hasTag($tag)) {
376
-            throw new \InvalidArgumentException('unknown tag: ' . $tag);
376
+            throw new \InvalidArgumentException('unknown tag: '.$tag);
377 377
         }
378 378
 
379 379
         return $this->forkContainer->getCollection($tag);
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
         }
398 398
 
399 399
         if (!$this->forkContainer->hasTag($tag)) {
400
-            throw new \InvalidArgumentException('unknown tag: ' . $tag);
400
+            throw new \InvalidArgumentException('unknown tag: '.$tag);
401 401
         }
402 402
 
403 403
         return $this->forkContainer->getCollection($tag);
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
     public function sendSignalToChildren($sig)
413 413
     {
414 414
         foreach ($this->childPids as $pid) {
415
-            $this->log->info('----> sending a signal to child. pid: ' . $pid);
415
+            $this->log->info('----> sending a signal to child. pid: '.$pid);
416 416
             posix_kill($pid, $sig);
417 417
         }
418 418
     }
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 
515 515
             $childPid = $fork->getPid();
516 516
             if ($fork->hasNotFinishedSuccessfully()) {
517
-                $message = 'an error has occurred in child process. pid: ' . $childPid;
517
+                $message = 'an error has occurred in child process. pid: '.$childPid;
518 518
                 $this->log->error($message);
519 519
                 throw new \RuntimeException($message);
520 520
             }
Please login to merge, or discard this patch.