Completed
Pull Request — master (#29)
by
unknown
07:01
created
src/MultiCurlSequence.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -19,12 +19,12 @@  discard block
 block discarded – undo
19 19
     
20 20
     $min = PHP_INT_MAX;
21 21
     $max = 0;
22
-    foreach($this->timers as $timer)
22
+    foreach ($this->timers as $timer)
23 23
     {
24
-      if(!isset($timer['start']))
24
+      if (!isset($timer['start']))
25 25
         $timer['start'] = PHP_INT_MAX;
26 26
 
27
-      if(!isset($timer['end']))
27
+      if (!isset($timer['end']))
28 28
         $timer['end'] = 0;
29 29
 
30 30
       $min = min($timer['start'], $min);
@@ -32,14 +32,14 @@  discard block
 block discarded – undo
32 32
     }
33 33
     $this->min = $min;
34 34
     $this->max = $max;
35
-    $this->range = $max-$min;
36
-    $this->step = floatval($this->range/$this->width);
35
+    $this->range = $max - $min;
36
+    $this->step = floatval($this->range / $this->width);
37 37
   }
38 38
 
39 39
   public function renderAscii()
40 40
   {
41 41
     $tpl = '';
42
-    foreach($this->timers as $timer)
42
+    foreach ($this->timers as $timer)
43 43
      $tpl .= $this->tplAscii($timer);
44 44
     
45 45
     return $tpl;
@@ -49,16 +49,16 @@  discard block
 block discarded – undo
49 49
   {
50 50
     $lpad = $rpad = 0;
51 51
     $lspace = $chars = $rspace = '';
52
-    if($timer['start'] > $this->min)
52
+    if ($timer['start'] > $this->min)
53 53
       $lpad = intval(($timer['start'] - $this->min) / $this->step);
54
-    if($timer['end'] < $this->max)
54
+    if ($timer['end'] < $this->max)
55 55
       $rpad = intval(($this->max - $timer['end']) / $this->step);
56 56
     $mpad = $this->width - $lpad - $rpad;
57
-    if($lpad > 0)
57
+    if ($lpad > 0)
58 58
       $lspace = str_repeat(' ', $lpad);
59
-    if($mpad > 0)
59
+    if ($mpad > 0)
60 60
       $chars = str_repeat('=', $mpad);
61
-    if($rpad > 0)
61
+    if ($rpad > 0)
62 62
       $rspace = str_repeat(' ', $rpad);
63 63
     
64 64
     $tpl = <<<TPL
Please login to merge, or discard this patch.
src/MultiCurl.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 
30 30
   public function __construct()
31 31
   {
32
-    if(self::$singleton === 0)
32
+    if (self::$singleton === 0)
33 33
     {
34 34
       throw new MultiCurlException('This class cannot be instantiated by the new keyword.  You must instantiate it using: $obj = MultiCurl::getInstance();');
35 35
     }
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
   {
49 49
     $ch = curl_init($url);
50 50
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
51
-    foreach($options as $option=>$value)
51
+    foreach ($options as $option=>$value)
52 52
     {
53 53
         curl_setopt($ch, $option, $value);
54 54
     }
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 
58 58
   public function addCurl($ch)
59 59
   {
60
-    if(gettype($ch) !== 'resource')
60
+    if (gettype($ch) !== 'resource')
61 61
     {
62 62
       throw new MultiCurlInvalidParameterException('Parameter must be a valid curl handle');
63 63
     }
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
     $this->startTimer($key);
71 71
     
72 72
     // (1)
73
-    if($code === CURLM_OK || $code === CURLM_CALL_MULTI_PERFORM)
73
+    if ($code === CURLM_OK || $code === CURLM_CALL_MULTI_PERFORM)
74 74
     {
75 75
       do
76 76
       {
@@ -87,38 +87,38 @@  discard block
 block discarded – undo
87 87
 
88 88
   public function getResult($key = null)
89 89
   {
90
-    if($key != null)
90
+    if ($key != null)
91 91
     {
92
-      if(isset($this->responses[$key]['code']))
92
+      if (isset($this->responses[$key]['code']))
93 93
       {
94 94
         return $this->responses[$key];
95 95
       }
96 96
 
97 97
       $innerSleepInt = $outerSleepInt = 1;
98
-      while($this->running && ($this->execStatus == CURLM_OK || $this->execStatus == CURLM_CALL_MULTI_PERFORM))
98
+      while ($this->running && ($this->execStatus == CURLM_OK || $this->execStatus == CURLM_CALL_MULTI_PERFORM))
99 99
       {
100 100
         usleep(intval($outerSleepInt));
101
-        $outerSleepInt = intval(max(1, ($outerSleepInt*$this->sleepIncrement)));
102
-        $ms=curl_multi_select($this->mc, 0);
101
+        $outerSleepInt = intval(max(1, ($outerSleepInt * $this->sleepIncrement)));
102
+        $ms = curl_multi_select($this->mc, 0);
103 103
 
104 104
         // bug in PHP 5.3.18+ where curl_multi_select can return -1
105 105
         // https://bugs.php.net/bug.php?id=63411
106
-        if($ms === -1)
106
+        if ($ms === -1)
107 107
           usleep(100000);
108 108
 
109 109
         // see pull request https://github.com/jmathai/php-multi-curl/pull/17
110 110
         // details here http://curl.haxx.se/libcurl/c/libcurl-errors.html
111
-        if($ms >= CURLM_CALL_MULTI_PERFORM)
111
+        if ($ms >= CURLM_CALL_MULTI_PERFORM)
112 112
         {
113
-          do{
113
+          do {
114 114
             $this->execStatus = curl_multi_exec($this->mc, $this->running);
115 115
             usleep(intval($innerSleepInt));
116
-            $innerSleepInt = intval(max(1, ($innerSleepInt*$this->sleepIncrement)));
117
-          }while($this->execStatus==CURLM_CALL_MULTI_PERFORM);
116
+            $innerSleepInt = intval(max(1, ($innerSleepInt * $this->sleepIncrement)));
117
+          } while ($this->execStatus == CURLM_CALL_MULTI_PERFORM);
118 118
           $innerSleepInt = 1;
119 119
         }
120 120
         $this->storeResponses();
121
-        if(isset($this->responses[$key]['data']))
121
+        if (isset($this->responses[$key]['data']))
122 122
         {
123 123
           return $this->responses[$key];
124 124
         }
@@ -151,11 +151,11 @@  discard block
 block discarded – undo
151 151
   private function headerCallback($ch, $header)
152 152
   {
153 153
     $_header = trim($header);
154
-    $colonPos= strpos($_header, ':');
155
-    if($colonPos > 0)
154
+    $colonPos = strpos($_header, ':');
155
+    if ($colonPos > 0)
156 156
     {
157 157
       $key = substr($_header, 0, $colonPos);
158
-      $val = preg_replace('/^\W+/','',substr($_header, $colonPos));
158
+      $val = preg_replace('/^\W+/', '', substr($_header, $colonPos));
159 159
       $this->responses[$this->getKey($ch)]['headers'][$key] = $val;
160 160
     }
161 161
     return strlen($header);
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 
164 164
   private function storeResponses()
165 165
   {
166
-    while($done = curl_multi_info_read($this->mc))
166
+    while ($done = curl_multi_info_read($this->mc))
167 167
     {
168 168
       $this->storeResponse($done);
169 169
     }
@@ -173,18 +173,18 @@  discard block
 block discarded – undo
173 173
   {
174 174
     $key = $this->getKey($done['handle']);
175 175
     $this->stopTimer($key, $done);
176
-    if($isAsynchronous)
176
+    if ($isAsynchronous)
177 177
       $this->responses[$key]['data'] = curl_multi_getcontent($done['handle']);
178 178
     else
179 179
       $this->responses[$key]['data'] = curl_exec($done['handle']);
180 180
 
181 181
     $this->responses[$key]['response'] = $this->responses[$key]['data'];
182 182
 
183
-    foreach($this->properties as $name => $const)
183
+    foreach ($this->properties as $name => $const)
184 184
     {
185 185
       $this->responses[$key][$name] = curl_getinfo($done['handle'], $const);
186 186
     }
187
-    if($isAsynchronous)
187
+    if ($isAsynchronous)
188 188
       curl_multi_remove_handle($this->mc, $done['handle']);
189 189
     curl_close($done['handle']);
190 190
   }
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 
205 205
   public static function getInstance()
206 206
   {
207
-    if(self::$inst == null)
207
+    if (self::$inst == null)
208 208
     {
209 209
       self::$singleton = 1;
210 210
       self::$inst = new MultiCurl();
Please login to merge, or discard this patch.