Passed
Pull Request — master (#13)
by Matthias
02:07
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/Clients/CLIClient.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -42,12 +42,12 @@  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
         }
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
     public function request($type, $file = null)
111 111
     {
112 112
         // check if is cached
113
-        if(isset($this->cache[sha1($file)][$type]))
113
+        if (isset($this->cache[sha1($file)][$type]))
114 114
         {
115 115
             return $this->cache[sha1($file)][$type];
116 116
         }
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
         $file = parent::checkRequest($type, $file);
123 123
 
124 124
         // add last argument
125
-        if($file)
125
+        if ($file)
126 126
         {
127 127
             $arguments[] = escapeshellarg($file);
128 128
         }
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
         $response = $this->exec($command);
136 136
 
137 137
         // metadata response
138
-        if($type == 'meta')
138
+        if ($type == 'meta')
139 139
         {
140 140
             // fix for invalid? json returned only with images
141 141
             $response = str_replace(basename($file) . '"}{', '", ', $response);
142 142
 
143 143
             // on Windows, response comes in another charset
144
-            if(defined('PHP_WINDOWS_VERSION_MAJOR'))
144
+            if (defined('PHP_WINDOWS_VERSION_MAJOR'))
145 145
             {
146 146
                 $response = utf8_encode($response);
147 147
             }
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
         }
151 151
 
152 152
         // cache certain responses
153
-        if(in_array($type, ['lang', 'meta']))
153
+        if (in_array($type, ['lang', 'meta']))
154 154
         {
155 155
             $this->cache[sha1($file)][$type] = $response;
156 156
         }
@@ -175,13 +175,13 @@  discard block
 block discarded – undo
175 175
         $callback = $this->callback;
176 176
 
177 177
         // get output if command runs ok
178
-        if(is_resource($process))
178
+        if (is_resource($process))
179 179
         {
180 180
             fclose($pipes[0]);
181 181
             $this->response = '';
182
-            while($chunk = stream_get_line($pipes[1], $this->chunkSize))
182
+            while ($chunk = stream_get_line($pipes[1], $this->chunkSize))
183 183
             {
184
-                if(!is_null($callback))
184
+                if (!is_null($callback))
185 185
                 {
186 186
                     $callback($chunk);
187 187
                 }
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
         }
194 194
 
195 195
         // exception if exit value is not zero
196
-        if($exit > 0)
196
+        if ($exit > 0)
197 197
         {
198 198
             throw new Exception("Unexpected exit value ($exit) for command $command");
199 199
         }
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
     {
214 214
         // parameters for command
215 215
         $arguments = [];
216
-        switch($type)
216
+        switch ($type)
217 217
         {
218 218
             case 'html':
219 219
                 $arguments[] = '--html';
Please login to merge, or discard this patch.
src/Clients/WebClient.php 2 patches
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -70,17 +70,17 @@  discard block
 block discarded – undo
70 70
      */
71 71
     public function __construct($host = null, $port = null, $options = [])
72 72
     {
73
-        if($host)
73
+        if ($host)
74 74
         {
75 75
             $this->setHost($host);
76 76
         }
77 77
 
78
-        if($port)
78
+        if ($port)
79 79
         {
80 80
             $this->setPort($port);
81 81
         }
82 82
 
83
-        if(!empty($options))
83
+        if (!empty($options))
84 84
         {
85 85
             $this->setOptions($options);
86 86
         }
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
      */
193 193
     public function setOption($key, $value)
194 194
     {
195
-        if(in_array($key, [CURLINFO_HEADER_OUT, CURLOPT_PUT, CURLOPT_RETURNTRANSFER]))
195
+        if (in_array($key, [CURLINFO_HEADER_OUT, CURLOPT_PUT, CURLOPT_RETURNTRANSFER]))
196 196
         {
197 197
             throw new Exception("Value for cURL option $key cannot be modified", 3);
198 198
         }
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
      */
212 212
     public function setOptions($options)
213 213
     {
214
-        foreach($options as $key => $value)
214
+        foreach ($options as $key => $value)
215 215
         {
216 216
             $this->setOption($key, $value);
217 217
         }
@@ -256,11 +256,11 @@  discard block
 block discarded – undo
256 256
         static $retries = [];
257 257
 
258 258
         // check if is cached
259
-        if(isset($this->cache[sha1($file)][$type]))
259
+        if (isset($this->cache[sha1($file)][$type]))
260 260
         {
261 261
             return $this->cache[sha1($file)][$type];
262 262
         }
263
-        elseif(!isset($retries[sha1($file)]))
263
+        elseif (!isset($retries[sha1($file)]))
264 264
         {
265 265
             $retries[sha1($file)] = $this->retries;
266 266
         }
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
         $options = $this->getCurlOptions($type, $file);
276 276
 
277 277
         // sets headers
278
-        foreach($headers as $header)
278
+        foreach ($headers as $header)
279 279
         {
280 280
             $options[CURLOPT_HTTPHEADER][] = $header;
281 281
         }
@@ -287,26 +287,26 @@  discard block
 block discarded – undo
287 287
         list($response, $status) = $this->exec($options);
288 288
 
289 289
         // request completed successfully
290
-        if($status == 200)
290
+        if ($status == 200)
291 291
         {
292
-            if($type == 'meta')
292
+            if ($type == 'meta')
293 293
             {
294 294
                 $response = Metadata::make($response, $file);
295 295
             }
296 296
 
297 297
             // cache certain responses
298
-            if(in_array($type, ['lang', 'meta']))
298
+            if (in_array($type, ['lang', 'meta']))
299 299
             {
300 300
                 $this->cache[sha1($file)][$type] = $response;
301 301
             }
302 302
         }
303 303
         // request completed successfully but result is empty
304
-        elseif($status == 204)
304
+        elseif ($status == 204)
305 305
         {
306 306
             $response = null;
307 307
         }
308 308
         // retry on request failed with error 500
309
-        elseif($status == 500 && $retries[sha1($file)]--)
309
+        elseif ($status == 500 && $retries[sha1($file)]--)
310 310
         {
311 311
             $response = $this->request($type, $file);
312 312
         }
@@ -332,13 +332,13 @@  discard block
 block discarded – undo
332 332
         $curl = curl_init();
333 333
 
334 334
         // we avoid curl_setopt_array($curl, $options) because extrange Windows behaviour (issue #8)
335
-        foreach($options as $option => $value)
335
+        foreach ($options as $option => $value)
336 336
         {
337 337
             curl_setopt($curl, $option, $value);
338 338
         }
339 339
 
340 340
         // make the request
341
-        if(is_null($this->callback))
341
+        if (is_null($this->callback))
342 342
         {
343 343
             $this->response = curl_exec($curl);
344 344
         }
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
         }
350 350
 
351 351
         // exception if cURL fails
352
-        if(curl_errno($curl))
352
+        if (curl_errno($curl))
353 353
         {
354 354
             throw new Exception(curl_error($curl), curl_errno($curl));
355 355
         }
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
      */
370 370
     protected function error($status, $resource)
371 371
     {
372
-        switch($status)
372
+        switch ($status)
373 373
         {
374 374
             //  method not allowed
375 375
             case 405:
@@ -410,12 +410,12 @@  discard block
 block discarded – undo
410 410
     {
411 411
         $headers = [];
412 412
 
413
-        if(!empty($file) && preg_match('/^http/', $file))
413
+        if (!empty($file) && preg_match('/^http/', $file))
414 414
         {
415 415
             $headers[] = "fileUrl:$file";
416 416
         }
417 417
 
418
-        switch($type)
418
+        switch ($type)
419 419
         {
420 420
             case 'html':
421 421
                 $resource = 'tika';
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
         $options = $this->options;
476 476
 
477 477
         // callback
478
-        if(!is_null($this->callback))
478
+        if (!is_null($this->callback))
479 479
         {
480 480
             $callback = $this->callback;
481 481
 
@@ -491,18 +491,18 @@  discard block
 block discarded – undo
491 491
         }
492 492
 
493 493
         // remote file options
494
-        if($file && preg_match('/^http/', $file))
494
+        if ($file && preg_match('/^http/', $file))
495 495
         {
496 496
             //
497 497
         }
498 498
         // local file options
499
-        elseif($file && file_exists($file) && is_readable($file))
499
+        elseif ($file && file_exists($file) && is_readable($file))
500 500
         {
501 501
             $options[CURLOPT_INFILE] = fopen($file, 'r');
502 502
             $options[CURLOPT_INFILESIZE] = filesize($file);
503 503
         }
504 504
         // other options for specific requests
505
-        elseif(in_array($type,  ['detectors', 'mime-types', 'parsers', 'version']))
505
+        elseif (in_array($type, ['detectors', 'mime-types', 'parsers', 'version']))
506 506
         {
507 507
             $options[CURLOPT_PUT] = false;
508 508
         }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -259,8 +259,7 @@  discard block
 block discarded – undo
259 259
         if(isset($this->cache[sha1($file)][$type]))
260 260
         {
261 261
             return $this->cache[sha1($file)][$type];
262
-        }
263
-        elseif(!isset($retries[sha1($file)]))
262
+        } elseif(!isset($retries[sha1($file)]))
264 263
         {
265 264
             $retries[sha1($file)] = $this->retries;
266 265
         }
@@ -341,8 +340,7 @@  discard block
 block discarded – undo
341 340
         if(is_null($this->callback))
342 341
         {
343 342
             $this->response = curl_exec($curl);
344
-        }
345
-        else
343
+        } else
346 344
         {
347 345
             $this->response = '';
348 346
             curl_exec($curl);
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 (func_num_args() > 0 && 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.