Passed
Push — master ( ddfab5...3c5e21 )
by David
01:22
created
src/Clients/WebClient.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -70,28 +70,28 @@  discard block
 block discarded – undo
70 70
      */
71 71
     public function __construct($host = null, $port = null, $options = [])
72 72
     {
73
-        if(is_string($host) && filter_var($host, FILTER_VALIDATE_URL))
73
+        if (is_string($host) && filter_var($host, FILTER_VALIDATE_URL))
74 74
         {
75 75
             $this->setUrl($host);
76 76
         }
77
-        elseif($host)
77
+        elseif ($host)
78 78
         {
79 79
             $this->setHost($host);
80 80
         }
81 81
 
82
-        if(is_numeric($port))
82
+        if (is_numeric($port))
83 83
         {
84 84
             $this->setPort($port);
85 85
         }
86 86
 
87
-        if(!empty($options))
87
+        if (!empty($options))
88 88
         {
89 89
             $this->setOptions($options);
90 90
         }
91 91
 
92 92
         $this->setDownloadRemote(true);
93 93
 
94
-        if(self::$check === true)
94
+        if (self::$check === true)
95 95
         {
96 96
             $this->check();
97 97
         }
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 
120 120
         $this->setHost($url['host']);
121 121
 
122
-        if(isset($url['port']))
122
+        if (isset($url['port']))
123 123
         {
124 124
             $this->setPort($url['port']);
125 125
         }
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
      */
230 230
     public function setOption($key, $value)
231 231
     {
232
-        if(in_array($key, [CURLINFO_HEADER_OUT, CURLOPT_PUT, CURLOPT_RETURNTRANSFER]))
232
+        if (in_array($key, [CURLINFO_HEADER_OUT, CURLOPT_PUT, CURLOPT_RETURNTRANSFER]))
233 233
         {
234 234
             throw new Exception("Value for cURL option $key cannot be modified", 3);
235 235
         }
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
      */
249 249
     public function setOptions($options)
250 250
     {
251
-        foreach($options as $key => $value)
251
+        foreach ($options as $key => $value)
252 252
         {
253 253
             $this->setOption($key, $value);
254 254
         }
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
      */
288 288
     public function check()
289 289
     {
290
-        if(self::$checked === false)
290
+        if (self::$checked === false)
291 291
         {
292 292
             // throws an exception if server is unreachable or can't connect
293 293
             $this->getVersion();
@@ -312,11 +312,11 @@  discard block
 block discarded – undo
312 312
         $this->check();
313 313
 
314 314
         // check if is cached
315
-        if(isset($this->cache[sha1($file)][$type]))
315
+        if (isset($this->cache[sha1($file)][$type]))
316 316
         {
317 317
             return $this->cache[sha1($file)][$type];
318 318
         }
319
-        elseif(!isset($retries[sha1($file)]))
319
+        elseif (!isset($retries[sha1($file)]))
320 320
         {
321 321
             $retries[sha1($file)] = $this->retries;
322 322
         }
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
         $options = $this->getCurlOptions($type, $file);
332 332
 
333 333
         // sets headers
334
-        foreach($headers as $header)
334
+        foreach ($headers as $header)
335 335
         {
336 336
             $options[CURLOPT_HTTPHEADER][] = $header;
337 337
         }
@@ -343,26 +343,26 @@  discard block
 block discarded – undo
343 343
         list($response, $status) = $this->exec($options);
344 344
 
345 345
         // request completed successfully
346
-        if($status == 200)
346
+        if ($status == 200)
347 347
         {
348
-            if($type == 'meta')
348
+            if ($type == 'meta')
349 349
             {
350 350
                 $response = Metadata::make($response, $file);
351 351
             }
352 352
 
353 353
             // cache certain responses
354
-            if(in_array($type, ['lang', 'meta']))
354
+            if (in_array($type, ['lang', 'meta']))
355 355
             {
356 356
                 $this->cache[sha1($file)][$type] = $response;
357 357
             }
358 358
         }
359 359
         // request completed successfully but result is empty
360
-        elseif($status == 204)
360
+        elseif ($status == 204)
361 361
         {
362 362
             $response = null;
363 363
         }
364 364
         // retry on request failed with error 500
365
-        elseif($status == 500 && $retries[sha1($file)]--)
365
+        elseif ($status == 500 && $retries[sha1($file)]--)
366 366
         {
367 367
             $response = $this->request($type, $file);
368 368
         }
@@ -388,13 +388,13 @@  discard block
 block discarded – undo
388 388
         $curl = curl_init();
389 389
 
390 390
         // we avoid curl_setopt_array($curl, $options) because extrange Windows behaviour (issue #8)
391
-        foreach($options as $option => $value)
391
+        foreach ($options as $option => $value)
392 392
         {
393 393
             curl_setopt($curl, $option, $value);
394 394
         }
395 395
 
396 396
         // make the request
397
-        if(is_null($this->callback))
397
+        if (is_null($this->callback))
398 398
         {
399 399
             $this->response = curl_exec($curl);
400 400
         }
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
         }
406 406
 
407 407
         // exception if cURL fails
408
-        if(curl_errno($curl))
408
+        if (curl_errno($curl))
409 409
         {
410 410
             throw new Exception(curl_error($curl), curl_errno($curl));
411 411
         }
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
      */
426 426
     protected function error($status, $resource)
427 427
     {
428
-        switch($status)
428
+        switch ($status)
429 429
         {
430 430
             //  method not allowed
431 431
             case 405:
@@ -466,12 +466,12 @@  discard block
 block discarded – undo
466 466
     {
467 467
         $headers = [];
468 468
 
469
-        if(!empty($file) && preg_match('/^http/', $file))
469
+        if (!empty($file) && preg_match('/^http/', $file))
470 470
         {
471 471
             $headers[] = "fileUrl:$file";
472 472
         }
473 473
 
474
-        switch($type)
474
+        switch ($type)
475 475
         {
476 476
             case 'html':
477 477
                 $resource = 'tika';
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
         $options = $this->options;
532 532
 
533 533
         // callback
534
-        if(!is_null($this->callback))
534
+        if (!is_null($this->callback))
535 535
         {
536 536
             $callback = $this->callback;
537 537
 
@@ -547,18 +547,18 @@  discard block
 block discarded – undo
547 547
         }
548 548
 
549 549
         // remote file options
550
-        if($file && preg_match('/^http/', $file))
550
+        if ($file && preg_match('/^http/', $file))
551 551
         {
552 552
             //
553 553
         }
554 554
         // local file options
555
-        elseif($file && file_exists($file) && is_readable($file))
555
+        elseif ($file && file_exists($file) && is_readable($file))
556 556
         {
557 557
             $options[CURLOPT_INFILE] = fopen($file, 'r');
558 558
             $options[CURLOPT_INFILESIZE] = filesize($file);
559 559
         }
560 560
         // other options for specific requests
561
-        elseif(in_array($type,  ['detectors', 'mime-types', 'parsers', 'version']))
561
+        elseif (in_array($type, ['detectors', 'mime-types', 'parsers', 'version']))
562 562
         {
563 563
             $options[CURLOPT_PUT] = false;
564 564
         }
Please login to merge, or discard this patch.
src/Clients/CLIClient.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function __construct($path = null, $java = null)
44 44
     {
45
-        if($path)
45
+        if ($path)
46 46
         {
47 47
             $this->setPath($path);
48 48
         }
49 49
 
50
-        if($java)
50
+        if ($java)
51 51
         {
52 52
             $this->setJava($java);
53 53
         }
54 54
 
55
-        if(self::$check === true)
55
+        if (self::$check === true)
56 56
         {
57 57
             $this->check();
58 58
         }
@@ -112,16 +112,16 @@  discard block
 block discarded – undo
112 112
      */
113 113
     public function check()
114 114
     {
115
-        if(self::$checked === false)
115
+        if (self::$checked === false)
116 116
         {
117 117
             // Java command must not return an error
118 118
             exec(($this->java ?: 'java') . ' -version 2> /dev/null', $output, $return);
119
-            if($return != 0)
119
+            if ($return != 0)
120 120
             {
121 121
                 throw new Exception('Java command not found');
122 122
             }
123 123
             // JAR path must exists
124
-            elseif(file_exists($this->path) == false)
124
+            elseif (file_exists($this->path) == false)
125 125
             {
126 126
                 throw new Exception('Apache Tika app JAR not found');
127 127
             }
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
         $this->check();
145 145
 
146 146
         // check if is cached
147
-        if(isset($this->cache[sha1($file)][$type]))
147
+        if (isset($this->cache[sha1($file)][$type]))
148 148
         {
149 149
             return $this->cache[sha1($file)][$type];
150 150
         }
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         $file = parent::checkRequest($type, $file);
157 157
 
158 158
         // add last argument
159
-        if($file)
159
+        if ($file)
160 160
         {
161 161
             $arguments[] = escapeshellarg($file);
162 162
         }
@@ -169,13 +169,13 @@  discard block
 block discarded – undo
169 169
         $response = $this->exec($command);
170 170
 
171 171
         // metadata response
172
-        if($type == 'meta')
172
+        if ($type == 'meta')
173 173
         {
174 174
             // fix for invalid? json returned only with images
175 175
             $response = str_replace(basename($file) . '"}{', '", ', $response);
176 176
 
177 177
             // on Windows, response comes in another charset
178
-            if(defined('PHP_WINDOWS_VERSION_MAJOR'))
178
+            if (defined('PHP_WINDOWS_VERSION_MAJOR'))
179 179
             {
180 180
                 $response = utf8_encode($response);
181 181
             }
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
         }
185 185
 
186 186
         // cache certain responses
187
-        if(in_array($type, ['lang', 'meta']))
187
+        if (in_array($type, ['lang', 'meta']))
188 188
         {
189 189
             $this->cache[sha1($file)][$type] = $response;
190 190
         }
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
         $callback = $this->callback;
210 210
 
211 211
         // get output if command runs ok
212
-        if(is_resource($process))
212
+        if (is_resource($process))
213 213
         {
214 214
             fclose($pipes[0]);
215 215
             $this->response = '';
216
-            while($chunk = stream_get_line($pipes[1], $this->chunkSize))
216
+            while ($chunk = stream_get_line($pipes[1], $this->chunkSize))
217 217
             {
218
-                if(!is_null($callback))
218
+                if (!is_null($callback))
219 219
                 {
220 220
                     $callback($chunk);
221 221
                 }
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
         }
228 228
 
229 229
         // exception if exit value is not zero
230
-        if($exit > 0)
230
+        if ($exit > 0)
231 231
         {
232 232
             throw new Exception("Unexpected exit value ($exit) for command $command");
233 233
         }
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
     {
248 248
         // parameters for command
249 249
         $arguments = [];
250
-        switch($type)
250
+        switch ($type)
251 251
         {
252 252
             case 'html':
253 253
                 $arguments[] = '--html';
Please login to merge, or discard this patch.