Passed
Push — master ( ddfab5...3c5e21 )
by David
01:22
created
src/Metadata/ImageMetadata.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
      */
41 41
     protected function setAttribute($key, $value)
42 42
     {
43
-        switch(mb_strtolower($key))
43
+        switch (mb_strtolower($key))
44 44
         {
45 45
             case 'compression':
46 46
             case 'compression lossless':
Please login to merge, or discard this patch.
src/Metadata/Metadata.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -51,19 +51,19 @@  discard block
 block discarded – undo
51 51
         $this->meta = $meta;
52 52
 
53 53
         // process each meta
54
-        foreach($this->meta as $key => $value)
54
+        foreach ($this->meta as $key => $value)
55 55
         {
56 56
             $this->setAttribute($key, $value);
57 57
         }
58 58
 
59 59
         // file name without extension if title is not detected
60
-        if(empty($this->title) && !is_null($file))
60
+        if (empty($this->title) && !is_null($file))
61 61
         {
62 62
             $this->title = preg_replace('/\..+$/', '', basename($file));
63 63
         }
64 64
 
65 65
         // use creation date as last modified if not detected
66
-        if(empty($this->updated))
66
+        if (empty($this->updated))
67 67
         {
68 68
             $this->updated = $this->created;
69 69
         }
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     public static function make($response, $file)
81 81
     {
82 82
         // an empty response throws an error
83
-        if(empty($response) || trim($response) == '')
83
+        if (empty($response) || trim($response) == '')
84 84
         {
85 85
             throw new Exception('Empty response');
86 86
         }
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
         $meta = json_decode($response);
90 90
 
91 91
         // exceptions if metadata is not valid
92
-        if(json_last_error())
92
+        if (json_last_error())
93 93
         {
94 94
             $message = function_exists('json_last_error_msg') ? json_last_error_msg() : 'Error parsing JSON response';
95 95
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
         $mime = is_array($meta->{'Content-Type'}) ? current($meta->{'Content-Type'}) : $meta->{'Content-Type'};
101 101
 
102 102
         // instance based on content type
103
-        switch(current(explode('/', $mime)))
103
+        switch (current(explode('/', $mime)))
104 104
         {
105 105
             case 'image':
106 106
                 $instance = new ImageMetadata($meta, $file);
Please login to merge, or discard this patch.
src/Metadata/DocumentMetadata.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -81,12 +81,12 @@  discard block
 block discarded – undo
81 81
     {
82 82
         $timezone = new DateTimeZone('UTC');
83 83
 
84
-        if(is_array($value))
84
+        if (is_array($value))
85 85
         {
86 86
             $value = array_shift($value);
87 87
         }
88 88
 
89
-        switch(mb_strtolower($key))
89
+        switch (mb_strtolower($key))
90 90
         {
91 91
             case 'title':
92 92
                 $this->title = $value;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 
99 99
             case 'keyword':
100 100
             case 'keywords':
101
-                if(preg_match('/,/', $value))
101
+                if (preg_match('/,/', $value))
102 102
                 {
103 103
                     $value = preg_split('/\s*,\s*/', $value);
104 104
                 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -101,8 +101,7 @@
 block discarded – undo
101 101
                 if(preg_match('/,/', $value))
102 102
                 {
103 103
                     $value = preg_split('/\s*,\s*/', $value);
104
-                }
105
-                else
104
+                } else
106 105
                 {
107 106
                     $value = preg_split('/\s+/', $value);
108 107
                 }
Please login to merge, or discard this patch.
src/Client.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public function setCallback($callback)
105 105
     {
106
-        if($callback instanceof Closure)
106
+        if ($callback instanceof Closure)
107 107
         {
108 108
             $this->callback = $callback;
109 109
         }
110
-        elseif(is_callable($callback))
110
+        elseif (is_callable($callback))
111 111
         {
112 112
             $this->callback = function($chunk) use($callback)
113 113
             {
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function setChunkSize($size)
143 143
     {
144
-        if(static::MODE == 'cli' && is_numeric($size))
144
+        if (static::MODE == 'cli' && is_numeric($size))
145 145
         {
146
-            $this->chunkSize = (int)$size;
146
+            $this->chunkSize = (int) $size;
147 147
         }
148
-        elseif(static::MODE == 'web')
148
+        elseif (static::MODE == 'web')
149 149
         {
150 150
             throw new Exception('Chunk size is not supported on web mode');
151 151
         }
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
      */
227 227
     public function getHTML($file, $callback = null)
228 228
     {
229
-        if(!is_null($callback))
229
+        if (!is_null($callback))
230 230
         {
231 231
             $this->setCallback($callback);
232 232
         }
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      */
245 245
     public function getText($file, $callback = null)
246 246
     {
247
-        if(!is_null($callback))
247
+        if (!is_null($callback))
248 248
         {
249 249
             $this->setCallback($callback);
250 250
         }
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
      */
263 263
     public function getMainText($file, $callback = null)
264 264
     {
265
-        if(!is_null($callback))
265
+        if (!is_null($callback))
266 266
         {
267 267
             $this->setCallback($callback);
268 268
         }
@@ -346,22 +346,22 @@  discard block
 block discarded – undo
346 346
     public function checkRequest($type, $file)
347 347
     {
348 348
         // no checks for getters
349
-        if(in_array($type, ['detectors', 'mime-types', 'parsers', 'version']))
349
+        if (in_array($type, ['detectors', 'mime-types', 'parsers', 'version']))
350 350
         {
351 351
             //
352 352
         }
353 353
         // invalid local file
354
-        elseif(!preg_match('/^http/', $file) && !file_exists($file))
354
+        elseif (!preg_match('/^http/', $file) && !file_exists($file))
355 355
         {
356 356
             throw new Exception("File $file can't be opened");
357 357
         }
358 358
         // invalid remote file
359
-        elseif(preg_match('/^http/', $file) && !preg_match('/200/', get_headers($file)[0]))
359
+        elseif (preg_match('/^http/', $file) && !preg_match('/200/', get_headers($file)[0]))
360 360
         {
361 361
             throw new Exception("File $file can't be opened", 2);
362 362
         }
363 363
         // download remote file if required only for integrated downloader
364
-        elseif(preg_match('/^http/', $file) && $this->downloadRemote)
364
+        elseif (preg_match('/^http/', $file) && $this->downloadRemote)
365 365
         {
366 366
             $file = $this->downloadFile($file);
367 367
         }
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 
384 384
         $fp = fopen($dest, 'w+');
385 385
 
386
-        if($fp === false)
386
+        if ($fp === false)
387 387
         {
388 388
             throw new Exception("$dest can't be opened");
389 389
         }
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
         curl_setopt($ch, CURLOPT_TIMEOUT, 5);
394 394
         curl_exec($ch);
395 395
 
396
-        if(curl_errno($ch))
396
+        if (curl_errno($ch))
397 397
         {
398 398
             throw new Exception(curl_error($ch));
399 399
         }
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 
403 403
         curl_close($ch);
404 404
 
405
-        if($code != 200)
405
+        if ($code != 200)
406 406
         {
407 407
             throw new Exception("$file can't be downloaded", $code);
408 408
         }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -77,8 +77,7 @@  discard block
 block discarded – undo
77 77
         if (preg_match('/\.jar$/', func_get_arg(0)))
78 78
         {
79 79
             return new CLIClient($param1, $param2);
80
-        }
81
-        else
80
+        } else
82 81
         {
83 82
             return new WebClient($param1, $param2, $options);
84 83
         }
@@ -106,15 +105,13 @@  discard block
 block discarded – undo
106 105
         if($callback instanceof Closure)
107 106
         {
108 107
             $this->callback = $callback;
109
-        }
110
-        elseif(is_callable($callback))
108
+        } elseif(is_callable($callback))
111 109
         {
112 110
             $this->callback = function($chunk) use($callback)
113 111
             {
114 112
                 return call_user_func_array($callback, [$chunk]);
115 113
             };
116
-        }
117
-        else
114
+        } else
118 115
         {
119 116
             throw new Exception('Invalid callback');
120 117
         }
@@ -144,12 +141,10 @@  discard block
 block discarded – undo
144 141
         if(static::MODE == 'cli' && is_numeric($size))
145 142
         {
146 143
             $this->chunkSize = (int)$size;
147
-        }
148
-        elseif(static::MODE == 'web')
144
+        } elseif(static::MODE == 'web')
149 145
         {
150 146
             throw new Exception('Chunk size is not supported on web mode');
151
-        }
152
-        else
147
+        } else
153 148
         {
154 149
             throw new Exception("$size is not a valid chunk size");
155 150
         }
Please login to merge, or discard this patch.
src/Clients/WebClient.php 2 patches
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -73,8 +73,7 @@  discard block
 block discarded – undo
73 73
         if(is_string($host) && filter_var($host, FILTER_VALIDATE_URL))
74 74
         {
75 75
             $this->setUrl($host);
76
-        }
77
-        elseif($host)
76
+        } elseif($host)
78 77
         {
79 78
             $this->setHost($host);
80 79
         }
@@ -293,8 +292,7 @@  discard block
 block discarded – undo
293 292
         if(isset($this->cache[sha1($file)][$type]))
294 293
         {
295 294
             return $this->cache[sha1($file)][$type];
296
-        }
297
-        elseif(!isset($retries[sha1($file)]))
295
+        } elseif(!isset($retries[sha1($file)]))
298 296
         {
299 297
             $retries[sha1($file)] = $this->retries;
300 298
         }
@@ -375,8 +373,7 @@  discard block
 block discarded – undo
375 373
         if(is_null($this->callback))
376 374
         {
377 375
             $this->response = curl_exec($curl);
378
-        }
379
-        else
376
+        } else
380 377
         {
381 378
             $this->response = '';
382 379
             curl_exec($curl);
Please login to merge, or discard this 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.