Completed
Push — master ( 748f90...5c1aea )
by Luke
08:07
created
src/CSVelte/Flavor.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -191,8 +191,9 @@
 block discarded – undo
191 191
      */
192 192
     protected function assertValidAttribute($attr)
193 193
     {
194
-        if (!property_exists(self::class, $attr))
195
-            throw new InvalidArgumentException("Unknown attribute: " . $attr);
194
+        if (!property_exists(self::class, $attr)) {
195
+                    throw new InvalidArgumentException("Unknown attribute: " . $attr);
196
+        }
196 197
     }
197 198
 
198 199
     /**
Please login to merge, or discard this patch.
src/CSVelte/Table/AbstractRow.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -151,7 +151,9 @@  discard block
 block discarded – undo
151 151
     public function next()
152 152
     {
153 153
         $this->position++;
154
-        if ($this->valid()) return $this->current();
154
+        if ($this->valid()) {
155
+            return $this->current();
156
+        }
155 157
     }
156 158
 
157 159
     /**
@@ -163,7 +165,9 @@  discard block
 block discarded – undo
163 165
     public function rewind()
164 166
     {
165 167
         $this->position = 0;
166
-        if ($this->valid()) return $this->current();
168
+        if ($this->valid()) {
169
+            return $this->current();
170
+        }
167 171
     }
168 172
 
169 173
     /**
Please login to merge, or discard this patch.
src/CSVelte/Traits/IsReadable.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,9 @@
 block discarded – undo
45 45
     {
46 46
         $size = 0;
47 47
         $buffer = false;
48
-        if (!is_array($eol)) $eol = array($eol);
48
+        if (!is_array($eol)) {
49
+            $eol = array($eol);
50
+        }
49 51
         while (!$this->eof()) {
50 52
             // Using a loose equality here to match on '' and false.
51 53
             if (null == ($byte = $this->read(1))) {
Please login to merge, or discard this patch.
src/CSVelte/Utils.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -56,7 +56,9 @@  discard block
 block discarded – undo
56 56
 
57 57
     public static function average($arr)
58 58
     {
59
-        if (!is_array($arr)) throw new \InvalidArgumentException('"average" function expected array, got ' . gettype($arr));
59
+        if (!is_array($arr)) {
60
+            throw new \InvalidArgumentException('"average" function expected array, got ' . gettype($arr));
61
+        }
60 62
         return array_sum($arr) / count($arr);
61 63
     }
62 64
 
@@ -71,7 +73,9 @@  discard block
 block discarded – undo
71 73
 
72 74
     public static function mode($arr)
73 75
     {
74
-        if (!is_array($arr)) throw new \InvalidArgumentException('"mode" function expected array, got ' . gettype($arr));
76
+        if (!is_array($arr)) {
77
+            throw new \InvalidArgumentException('"mode" function expected array, got ' . gettype($arr));
78
+        }
75 79
         $vals = array();
76 80
         foreach ($arr as $key => $val) {
77 81
             $vals[$val] = self::array_get($vals, $val, 0) + 1;
Please login to merge, or discard this patch.
src/CSVelte/Reader.php 1 patch
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -104,7 +104,9 @@  discard block
 block discarded – undo
104 104
      */
105 105
     protected function setFlavor($flavor = null)
106 106
     {
107
-        if (is_array($flavor)) $flavor = new Flavor($flavor);
107
+        if (is_array($flavor)) {
108
+            $flavor = new Flavor($flavor);
109
+        }
108 110
         $taster = new Taster($this->source);
109 111
         // @todo put this inside a try/catch
110 112
         if (is_null($flavor)) {
@@ -159,7 +161,9 @@  discard block
 block discarded – undo
159 161
                     $this->header = new HeaderRow($parsed);
160 162
                 } else {
161 163
                     $this->current = new Row($parsed);
162
-                    if ($this->header) $this->current->setHeaderRow($this->header);
164
+                    if ($this->header) {
165
+                        $this->current->setHeaderRow($this->header);
166
+                    }
163 167
                 }
164 168
             } catch (EndOfFileException $e) {
165 169
                 $this->current = false;
@@ -183,7 +187,9 @@  discard block
 block discarded – undo
183 187
         $eol = $f->lineTerminator;
184 188
         try {
185 189
             do {
186
-                if (!isset($lines)) $lines = array();
190
+                if (!isset($lines)) {
191
+                    $lines = array();
192
+                }
187 193
                 if (false === ($line = $this->source->readLine($eol))) {
188 194
                     throw new EndOfFileException("End of file reached: " . $this->source->getName());
189 195
                 }
@@ -191,7 +197,9 @@  discard block
 block discarded – undo
191 197
             } while ($this->inQuotedString(end($lines), $f->quoteChar, $f->escapeChar));
192 198
         } catch (EndOfFileException $e) {
193 199
             // only throw the exception if we don't already have lines in the buffer
194
-            if (!count($lines)) throw $e;
200
+            if (!count($lines)) {
201
+                throw $e;
202
+            }
195 203
         }
196 204
         return rtrim(implode($eol, $lines), $eol);
197 205
     }
@@ -211,14 +219,18 @@  discard block
 block discarded – undo
211 219
     {
212 220
         if (!empty($line)) {
213 221
             do {
214
-                if (!isset($i)) $i = 0;
222
+                if (!isset($i)) {
223
+                    $i = 0;
224
+                }
215 225
                 $c = $line[$i++];
216 226
                 if ($this->escape) {
217 227
                     $this->escape = false;
218 228
                     continue;
219 229
                 }
220 230
                 $this->escape = ($c == $escapeChar);
221
-                if ($c == $quoteChar) $this->open = !$this->open;
231
+                if ($c == $quoteChar) {
232
+                    $this->open = !$this->open;
233
+                }
222 234
             } while ($i < strlen($line));
223 235
         }
224 236
         return $this->open;
Please login to merge, or discard this patch.
src/CSVelte/Autoloader.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,9 @@
 block discarded – undo
61 61
     {
62 62
         $paths = $this->getPaths();
63 63
         if ($rp = realpath($path)) {
64
-            if (in_array($rp, $paths)) return true;
64
+            if (in_array($rp, $paths)) {
65
+                return true;
66
+            }
65 67
             $this->paths []= $rp;
66 68
             return true;
67 69
         }
Please login to merge, or discard this patch.
src/CSVelte/Taster.php 1 patch
Braces   +36 added lines, -13 removed lines patch added patch discarded remove patch
@@ -145,7 +145,9 @@  discard block
 block discarded – undo
145 145
         try {
146 146
             list($quoteChar, $delimiter) = $this->lickQuoteAndDelim();
147 147
         } catch (TasterException $e) {
148
-            if ($e->getCode() !== TasterException::ERR_QUOTE_AND_DELIM) throw $e;
148
+            if ($e->getCode() !== TasterException::ERR_QUOTE_AND_DELIM) {
149
+                throw $e;
150
+            }
149 151
             $quoteChar = '"';
150 152
             $delimiter = $this->lickDelimiter($lineTerminator);
151 153
         }
@@ -244,7 +246,9 @@  discard block
 block discarded – undo
244 246
         foreach ($patterns as $pattern) {
245 247
             // @todo I had to add the error suppression char here because it was
246 248
             //     causing undefined offset errors with certain data sets. strange...
247
-            if (@preg_match_all($pattern, $this->sample, $matches) && $matches) break;
249
+            if (@preg_match_all($pattern, $this->sample, $matches) && $matches) {
250
+                break;
251
+            }
248 252
         }
249 253
         if ($matches) {
250 254
             $quotes = array_count_values($matches['quoteChar']);
@@ -283,7 +287,9 @@  discard block
 block discarded – undo
283 287
         $charFrequency = array();
284 288
         while ($start < count($lines)) {
285 289
             foreach ($lines as $key => $line) {
286
-                if (!trim($line)) continue;
290
+                if (!trim($line)) {
291
+                    continue;
292
+                }
287 293
                 foreach ($delimiters as $char) {
288 294
                     $freq = substr_count($line, $char);
289 295
                     $charFrequency[$char][$key] = $freq;
@@ -376,11 +382,18 @@  discard block
 block discarded – undo
376 382
         }
377 383
         $types = array_unique($freq['quoted']);
378 384
         // if quoting_styles still has QUOTE_ALL or QUOTE_NONE, then that's the one to return
379
-        if (array_key_exists(Flavor::QUOTE_ALL, $quoting_styles)) return Flavor::QUOTE_ALL;
380
-        if (array_key_exists(Flavor::QUOTE_NONE, $quoting_styles)) return Flavor::QUOTE_NONE;
385
+        if (array_key_exists(Flavor::QUOTE_ALL, $quoting_styles)) {
386
+            return Flavor::QUOTE_ALL;
387
+        }
388
+        if (array_key_exists(Flavor::QUOTE_NONE, $quoting_styles)) {
389
+            return Flavor::QUOTE_NONE;
390
+        }
381 391
         if (count($types) == 1) {
382
-            if (current($types) == self::DATA_SPECIAL) return Flavor::QUOTE_MINIMAL;
383
-            elseif (current($types) == self::DATA_NONNUMERIC) return Flavor::QUOTE_NONNUMERIC;
392
+            if (current($types) == self::DATA_SPECIAL) {
393
+                return Flavor::QUOTE_MINIMAL;
394
+            } elseif (current($types) == self::DATA_NONNUMERIC) {
395
+                return Flavor::QUOTE_NONNUMERIC;
396
+            }
384 397
         } else {
385 398
             if (array_key_exists(self::DATA_NONNUMERIC, array_flip($types))) {
386 399
                 // allow for a SMALL amount of error here
@@ -392,7 +405,9 @@  discard block
 block discarded – undo
392 405
                 $most = current($counts);
393 406
                 $least = end($counts);
394 407
                 $err_margin = $least / $most;
395
-                if ($err_margin < 1) return Flavor::QUOTE_NONNUMERIC;
408
+                if ($err_margin < 1) {
409
+                    return Flavor::QUOTE_NONNUMERIC;
410
+                }
396 411
             }
397 412
         }
398 413
         return Flavor::QUOTE_MINIMAL;
@@ -583,15 +598,23 @@  discard block
 block discarded – undo
583 598
         foreach ($types as $line_no => $cols) {
584 599
             foreach ($cols as $col_no => $col_info) {
585 600
                 extract($col_info);
586
-                if (!array_key_exists($col_no, $potential_header)) continue;
601
+                if (!array_key_exists($col_no, $potential_header)) {
602
+                    continue;
603
+                }
587 604
                 extract($potential_header[$col_no], EXTR_PREFIX_ALL, "header");
588 605
                 if ($header_type == self::TYPE_STRING) {
589 606
                     // use length
590
-                    if ($length != $header_length) $hasHeader++;
591
-                    else $hasHeader--;
607
+                    if ($length != $header_length) {
608
+                        $hasHeader++;
609
+                    } else {
610
+                        $hasHeader--;
611
+                    }
592 612
                 } else {
593
-                    if ($type != $header_type) $hasHeader++;
594
-                    else $hasHeader--;
613
+                    if ($type != $header_type) {
614
+                        $hasHeader++;
615
+                    } else {
616
+                        $hasHeader--;
617
+                    }
595 618
                 }
596 619
             }
597 620
         }
Please login to merge, or discard this patch.
src/CSVelte/IO/Stream.php 1 patch
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -225,7 +225,9 @@  discard block
 block discarded – undo
225 225
      */
226 226
     protected static function open($stream, $mode = null, $context = null)
227 227
     {
228
-        if (is_null($mode)) $mode = 'r+b';
228
+        if (is_null($mode)) {
229
+            $mode = 'r+b';
230
+        }
229 231
         if (is_string($uri = $stream)) {
230 232
             if (is_null($context)) {
231 233
                 $stream = @fopen($uri, $mode);
@@ -289,8 +291,12 @@  discard block
 block discarded – undo
289 291
      */
290 292
     public function getMetaData($key = null)
291 293
     {
292
-        if (!$this->stream) return null;
293
-        if (is_null($key)) return $this->meta;
294
+        if (!$this->stream) {
295
+            return null;
296
+        }
297
+        if (is_null($key)) {
298
+            return $this->meta;
299
+        }
294 300
         return (array_key_exists($key, $this->meta)) ? $this->meta[$key] : null;
295 301
     }
296 302
 
@@ -388,7 +394,9 @@  discard block
 block discarded – undo
388 394
      */
389 395
     public function getSize()
390 396
     {
391
-        if (!$this->stream) return null;
397
+        if (!$this->stream) {
398
+            return null;
399
+        }
392 400
         if (is_null($this->size)) {
393 401
             $stats = fstat($this->stream);
394 402
             if (array_key_exists('size', $stats)) {
@@ -422,7 +430,9 @@  discard block
 block discarded – undo
422 430
     public function read($length)
423 431
     {
424 432
         $this->assertIsReadable();
425
-        if ($this->eof()) return false;
433
+        if ($this->eof()) {
434
+            return false;
435
+        }
426 436
         return fread($this->stream, $length);
427 437
     }
428 438
 
Please login to merge, or discard this patch.
src/CSVelte/Writer.php 1 patch
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -64,7 +64,9 @@  discard block
 block discarded – undo
64 64
      */
65 65
     public function __construct(Writable $output, $flavor = null)
66 66
     {
67
-        if (!($flavor instanceof Flavor)) $flavor = new Flavor($flavor);
67
+        if (!($flavor instanceof Flavor)) {
68
+            $flavor = new Flavor($flavor);
69
+        }
68 70
         $this->flavor = $flavor;
69 71
         $this->output = $output;
70 72
     }
@@ -96,7 +98,9 @@  discard block
 block discarded – undo
96 98
         if ($this->written) {
97 99
             throw new WriterException("Cannot set header row once data has already been written. ");
98 100
         }
99
-        if (is_array($headers)) $headers = new ArrayIterator($headers);
101
+        if (is_array($headers)) {
102
+            $headers = new ArrayIterator($headers);
103
+        }
100 104
         $this->headers = $headers;
101 105
     }
102 106
 
@@ -114,7 +118,9 @@  discard block
 block discarded – undo
114 118
             $headerRow = new HeaderRow((array) $this->headers);
115 119
             $this->writeHeaderRow($headerRow);
116 120
         }
117
-        if (is_array($row)) $row = new ArrayIterator($row);
121
+        if (is_array($row)) {
122
+            $row = new ArrayIterator($row);
123
+        }
118 124
         $row = $this->prepareRow($row);
119 125
         if ($count = $this->output->writeLine($row->join($delim), $eol)) {
120 126
             $this->written++;
@@ -139,7 +145,9 @@  discard block
 block discarded – undo
139 145
      */
140 146
     public function writeRows($rows)
141 147
     {
142
-        if (is_array($rows)) $rows = new ArrayIterator($rows);
148
+        if (is_array($rows)) {
149
+            $rows = new ArrayIterator($rows);
150
+        }
143 151
         if (!($rows instanceof Iterator)) {
144 152
             throw new InvalidArgumentException('First argument for ' . __METHOD__ . ' must be iterable');
145 153
         }
@@ -148,7 +156,9 @@  discard block
 block discarded – undo
148 156
             $this->writeHeaderRow($rows->header());
149 157
         }
150 158
         foreach ($rows as $row) {
151
-            if ($this->writeRow($row)) $written++;
159
+            if ($this->writeRow($row)) {
160
+                $written++;
161
+            }
152 162
         }
153 163
         return $written;
154 164
     }
@@ -225,7 +235,9 @@  discard block
 block discarded – undo
225 235
     {
226 236
         $flvr = $this->getFlavor();
227 237
         $escapeQuote = "";
228
-        if ($isQuoted) $escapeQuote = ($flvr->doubleQuote) ? $flvr->quoteChar : $flvr->escapeChar;
238
+        if ($isQuoted) {
239
+            $escapeQuote = ($flvr->doubleQuote) ? $flvr->quoteChar : $flvr->escapeChar;
240
+        }
229 241
         // @todo Not sure what else, if anything, I'm supposed to be escaping here..
230 242
         return str_replace($flvr->quoteChar, $escapeQuote . $flvr->quoteChar, $str);
231 243
     }
Please login to merge, or discard this patch.