Completed
Pull Request — master (#16)
by Akihito
03:28
created
src/Snidel/Log.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
      */
43 43
     private function context()
44 44
     {
45
-        $pid  = getmypid();
45
+        $pid = getmypid();
46 46
         switch ($pid) {
47 47
             case $this->ownerPid:
48 48
                 $role = 'owner';
Please login to merge, or discard this patch.
src/Snidel/Fork/Container.php 2 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     private $receivedSignal;
46 46
 
47 47
     /**
48
-     * @param   int     $ownerPid
48
+     * @param \Ackintosh\Snidel\Log $log
49 49
      */
50 50
     public function __construct(Config $config, $log)
51 51
     {
@@ -58,6 +58,7 @@  discard block
 block discarded – undo
58 58
 
59 59
     /**
60 60
      * @param   \Ackintosh\Snidel\Task
61
+     * @param \Ackintosh\Snidel\Task\Task $task
61 62
      * @return  void
62 63
      * @throws  \RuntimeException
63 64
      */
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 
139 139
         if (getmypid() === $this->config->get('ownerPid')) {
140 140
             // owner
141
-            $this->log->info('pid: ' . getmypid());
141
+            $this->log->info('pid: '.getmypid());
142 142
             $this->taskQueue    = $this->queueFactory->createTaskQueue();
143 143
             $this->resultQueue  = $this->queueFactory->createResultQueue();
144 144
 
@@ -146,18 +146,18 @@  discard block
 block discarded – undo
146 146
         } else {
147 147
             // master
148 148
             $activeWorkerSet = new ActiveWorkerSet();
149
-            $this->log->info('pid: ' . $this->masterPid);
149
+            $this->log->info('pid: '.$this->masterPid);
150 150
 
151 151
             $receivedSignal = &$this->receivedSignal;
152 152
             foreach ($this->signals as $sig) {
153
-                $this->pcntl->signal($sig, function ($sig) use ($activeWorkerSet, $receivedSignal) {
153
+                $this->pcntl->signal($sig, function($sig) use ($activeWorkerSet, $receivedSignal) {
154 154
                     $receivedSignal = $sig;
155
-                    $this->log->info('received signal: ' . $sig);
155
+                    $this->log->info('received signal: '.$sig);
156 156
 
157 157
                     if ($activeWorkerSet->count() === 0) {
158 158
                         $this->log->info('no worker is active.');
159 159
                     } else {
160
-                        $this->log->info('------> sending signal to workers. signal: ' . $sig);
160
+                        $this->log->info('------> sending signal to workers. signal: '.$sig);
161 161
                         $activeWorkerSet->terminate($sig);
162 162
                         $this->log->info('<------ sent signal');
163 163
                     }
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
                 });
166 166
             }
167 167
 
168
-            $concurrency = (int)$this->config->get('concurrency');
168
+            $concurrency = (int) $this->config->get('concurrency');
169 169
             for ($i = 0; $i < $concurrency; $i++) {
170 170
                 $activeWorkerSet->add($this->forkWorker());
171 171
             }
@@ -202,15 +202,15 @@  discard block
 block discarded – undo
202 202
 
203 203
         if (getmypid() === $this->masterPid) {
204 204
             // master
205
-            $this->log->info('forked worker. pid: ' . $worker->getPid());
205
+            $this->log->info('forked worker. pid: '.$worker->getPid());
206 206
             return $worker;
207 207
         } else {
208 208
             // worker
209 209
             // @codeCoverageIgnoreStart
210
-            $this->log->info('has forked. pid: ' . getmypid());
210
+            $this->log->info('has forked. pid: '.getmypid());
211 211
 
212 212
             foreach ($this->signals as $sig) {
213
-                $this->pcntl->signal($sig, function ($sig) {
213
+                $this->pcntl->signal($sig, function($sig) {
214 214
                     $this->receivedSignal = $sig;
215 215
                     exit;
216 216
                 }, false);
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
             $worker->setTaskQueue($this->queueFactory->createTaskQueue());
220 220
             $worker->setResultQueue($this->queueFactory->createResultQueue());
221 221
 
222
-            register_shutdown_function(function () use ($worker) {
222
+            register_shutdown_function(function() use ($worker) {
223 223
                 if ($worker->isFailedToEnqueueResult() && $this->receivedSignal === null) {
224 224
                     $worker->error();
225 225
                 }
@@ -255,14 +255,14 @@  discard block
 block discarded – undo
255 255
      */
256 256
     public function sendSignalToMaster($sig = SIGTERM)
257 257
     {
258
-        $this->log->info('----> sending signal to master. signal: ' . $sig);
258
+        $this->log->info('----> sending signal to master. signal: '.$sig);
259 259
         posix_kill($this->masterPid, $sig);
260 260
         $this->log->info('<---- sent signal.');
261 261
 
262 262
         $this->log->info('----> waiting for master shutdown.');
263 263
         $status = null;
264 264
         $this->pcntl->waitpid($this->masterPid, $status);
265
-        $this->log->info('<---- master shutdown. status: ' . $status);
265
+        $this->log->info('<---- master shutdown. status: '.$status);
266 266
         $this->masterPid = null;
267 267
     }
268 268
 
Please login to merge, or discard this patch.
src/Snidel.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
         foreach ($this->signals as $sig) {
61 61
             $this->pcntl->signal(
62 62
                 $sig,
63
-                function ($sig)  {
64
-                    $this->log->info('received signal. signo: ' . $sig);
63
+                function($sig) {
64
+                    $this->log->info('received signal. signo: '.$sig);
65 65
                     $this->setReceivedSignal($sig);
66 66
 
67 67
                     $this->log->info('--> sending a signal " to children.');
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
             );
74 74
         }
75 75
 
76
-        $this->log->info('parent pid: ' . $this->config->get('ownerPid'));
76
+        $this->log->info('parent pid: '.$this->config->get('ownerPid'));
77 77
     }
78 78
 
79 79
     /**
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
             throw $e;
100 100
         }
101 101
 
102
-        $this->log->info('queued task #' . $this->container->queuedCount());
102
+        $this->log->info('queued task #'.$this->container->queuedCount());
103 103
     }
104 104
 
105 105
     /**
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public function results()
122 122
     {
123
-        foreach($this->container->results() as $r) {
123
+        foreach ($this->container->results() as $r) {
124 124
             yield $r;
125 125
         }
126 126
 
Please login to merge, or discard this patch.
src/Snidel/IpcKey.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
     {
24 24
         $this->ownerPid = $ownerPid;
25 25
         $this->prefix   = $prefix;
26
-        $this->pathname = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $this->prefix . $this->ownerPid;
26
+        $this->pathname = sys_get_temp_dir().DIRECTORY_SEPARATOR.$this->prefix.$this->ownerPid;
27 27
         $this->semaphore = new Semaphore();
28 28
     }
29 29
 
Please login to merge, or discard this patch.
src/Snidel/AbstractQueue.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(ticks=1);
2
+declare(ticks = 1);
3 3
 
4 4
 namespace Ackintosh\Snidel;
5 5
 
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
     public function __construct(Config $config)
30 30
     {
31 31
         $this->ownerPid = $config->get('ownerPid');
32
-        $this->ipcKey   = new IpcKey($this->ownerPid, $config->get('id') . str_replace('\\', '_', get_class($this)));
32
+        $this->ipcKey   = new IpcKey($this->ownerPid, $config->get('id').str_replace('\\', '_', get_class($this)));
33 33
         $this->semaphore = new Semaphore();
34 34
         $this->id       = $this->semaphore->getQueue($this->ipcKey->generate());
35 35
         $this->stat     = $this->semaphore->statQueue($this->id);
Please login to merge, or discard this patch.