Completed
Push — releases/v0.2.1 ( c795d8...14b6b0 )
by Luke
02:51
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 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@
 block discarded – undo
56 56
     public function __construct($fields)
57 57
     {
58 58
         $this->setFields($fields)
59
-             ->rewind();
59
+                ->rewind();
60 60
     }
61 61
 
62 62
     protected function setFields($fields)
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -152,7 +152,9 @@
 block discarded – undo
152 152
     public function next()
153 153
     {
154 154
         $this->position++;
155
-        if ($this->valid()) return $this->current();
155
+        if ($this->valid()) {
156
+            return $this->current();
157
+        }
156 158
     }
157 159
 
158 160
     /**
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/Reader.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,8 +91,8 @@
 block discarded – undo
91 91
     public function __construct($input, $flavor = null)
92 92
     {
93 93
         $this->setSource($input)
94
-             ->setFlavor($flavor)
95
-             ->rewind();
94
+                ->setFlavor($flavor)
95
+                ->rewind();
96 96
     }
97 97
 
98 98
     /**
Please login to merge, or discard this 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/Exception/HeaderException.php 1 patch
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,6 @@
 block discarded – undo
19 19
 if (if $file->hasHeader()) {
20 20
     $header = $file->getHeader()
21 21
 }
22
-
23 22
  * you can instead simply call $header->getHeader() and handle this exception if
24 23
  * said file has no header
25 24
  *
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.
src/CSVelte/Taster.php 2 patches
Braces   +34 added lines, -12 removed lines patch added patch discarded remove patch
@@ -169,7 +169,9 @@  discard block
 block discarded – undo
169 169
         try {
170 170
             list($quoteChar, $delimiter) = $this->lickQuoteAndDelim();
171 171
         } catch (TasterException $e) {
172
-            if ($e->getCode() !== TasterException::ERR_QUOTE_AND_DELIM) throw $e;
172
+            if ($e->getCode() !== TasterException::ERR_QUOTE_AND_DELIM) {
173
+                throw $e;
174
+            }
173 175
             $quoteChar = '"';
174 176
             $delimiter = $this->lickDelimiter($lineTerminator);
175 177
         }
@@ -265,7 +267,9 @@  discard block
 block discarded – undo
265 267
         foreach ($patterns as $pattern) {
266 268
             // @todo I had to add the error suppression char here because it was
267 269
             //     causing undefined offset errors with certain data sets. strange...
268
-            if (@preg_match_all($pattern, $this->sample, $matches) && $matches) break;
270
+            if (@preg_match_all($pattern, $this->sample, $matches) && $matches) {
271
+                break;
272
+            }
269 273
         }
270 274
         if ($matches) {
271 275
             try {
@@ -388,7 +392,9 @@  discard block
 block discarded – undo
388 392
                  // if somehow we STILL can't come to a consensus, then fall back to a
389 393
                  // "preferred delimiters" list...
390 394
                  foreach ($this->delims as $key => $val) {
391
-                    if ($delim = array_search($val, $decision)) return $delim;
395
+                    if ($delim = array_search($val, $decision)) {
396
+                        return $delim;
397
+                    }
392 398
                  }
393 399
              }
394 400
         }
@@ -431,7 +437,9 @@  discard block
 block discarded – undo
431 437
             return $delims[collect($delims)->map(function($delim) use (&$distrib, $lines) {
432 438
                 $linedist = collect();
433 439
                 $lines->walk(function($line, $line_no) use (&$linedist, $delim) {
434
-                    if (!strlen($line)) return;
440
+                    if (!strlen($line)) {
441
+                        return;
442
+                    }
435 443
                     $sectstot = 10;
436 444
                     $sectlen = (int) (strlen($line) / $sectstot);
437 445
                     $sections = collect(str_split($line, $sectlen))
@@ -519,8 +527,12 @@  discard block
 block discarded – undo
519 527
         $quoting_styles = $quoting_styles->filter(function($val) { return (bool) $val; });
520 528
         // if quoting_styles still has QUOTE_ALL or QUOTE_NONE, then return
521 529
         // whichever of them it is, we don't need to do anything else
522
-        if ($quoting_styles->has(Flavor::QUOTE_ALL)) return Flavor::QUOTE_ALL;
523
-        if ($quoting_styles->has(Flavor::QUOTE_NONE)) return Flavor::QUOTE_NONE;
530
+        if ($quoting_styles->has(Flavor::QUOTE_ALL)) {
531
+            return Flavor::QUOTE_ALL;
532
+        }
533
+        if ($quoting_styles->has(Flavor::QUOTE_NONE)) {
534
+            return Flavor::QUOTE_NONE;
535
+        }
524 536
         if (count($types) == 1) {
525 537
             $style = $types->getValueAtPosition(0);
526 538
             if ($quoting_styles->has($style)) {
@@ -537,7 +549,9 @@  discard block
 block discarded – undo
537 549
                 if ($most = $counts->max()) {
538 550
                     $least = $counts->min();
539 551
                     $err_margin = $least / $most;
540
-                    if ($err_margin < 1) return Flavor::QUOTE_NONNUMERIC;
552
+                    if ($err_margin < 1) {
553
+                        return Flavor::QUOTE_NONNUMERIC;
554
+                    }
541 555
                 }
542 556
             }
543 557
         }
@@ -712,7 +726,9 @@  discard block
 block discarded – undo
712 726
                 $field = str_replace(self::PLACEHOLDER_DELIM, $delim, $field);
713 727
                 // @todo Need a Collection::setTableField($x, $y) method
714 728
                 //       See notes in green binder about refactoring Collection
715
-                if (!$types->has($line_no)) $types->set($line_no, collect());
729
+                if (!$types->has($line_no)) {
730
+                    $types->set($line_no, collect());
731
+                }
716 732
                 $types->get($line_no)->set($colpos, [
717 733
                     'type' => $this->lickType($this->unQuote($field)),
718 734
                     'length' => strlen($field)
@@ -735,12 +751,18 @@  discard block
 block discarded – undo
735 751
                     extract($possibleHeader->get($col_no, null, true), EXTR_PREFIX_ALL, "header");
736 752
                     if ($header_type == self::TYPE_STRING) {
737 753
                         // use length
738
-                        if ($length != $header_length) $hasHeader++;
739
-                        else $hasHeader--;
754
+                        if ($length != $header_length) {
755
+                            $hasHeader++;
756
+                        } else {
757
+                            $hasHeader--;
758
+                        }
740 759
                     } else {
741 760
                         // use data type
742
-                        if ($type != $header_type) $hasHeader++;
743
-                        else $hasHeader--;
761
+                        if ($type != $header_type) {
762
+                            $hasHeader++;
763
+                        } else {
764
+                            $hasHeader--;
765
+                        }
744 766
                     }
745 767
                 } catch (OutOfBoundsException $e) {
746 768
                     // failure...
Please login to merge, or discard this patch.
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -292,20 +292,20 @@  discard block
 block discarded – undo
292 292
         throw new TasterException("quoteChar and delimiter cannot be determined", TasterException::ERR_QUOTE_AND_DELIM);
293 293
     }
294 294
 
295
-     /**
296
-      * Take a list of likely delimiter characters and find the one that occurs
297
-      * the most consistent amount of times within the provided data.
298
-      *
299
-      * @param string $eol The character(s) used for newlines
300
-      * @return string One of four Flavor::QUOTING_* constants
301
-      * @see Flavor for possible quote style constants
302
-      * @todo Refactor this method--It needs more thorough testing against a wider
303
-      *     variety of CSV data to be sure it works reliably. And I'm sure there
304
-      *     are many performance and logic improvements that could be made. This
305
-      *     is essentially a first draft.
306
-      * @todo Can't use replaceQuotedSpecialChars rather than removeQuotedStrings
307
-      *     because the former requires u to know the delimiter
308
-      */
295
+        /**
296
+         * Take a list of likely delimiter characters and find the one that occurs
297
+         * the most consistent amount of times within the provided data.
298
+         *
299
+         * @param string $eol The character(s) used for newlines
300
+         * @return string One of four Flavor::QUOTING_* constants
301
+         * @see Flavor for possible quote style constants
302
+         * @todo Refactor this method--It needs more thorough testing against a wider
303
+         *     variety of CSV data to be sure it works reliably. And I'm sure there
304
+         *     are many performance and logic improvements that could be made. This
305
+         *     is essentially a first draft.
306
+         * @todo Can't use replaceQuotedSpecialChars rather than removeQuotedStrings
307
+         *     because the former requires u to know the delimiter
308
+         */
309 309
     protected function lickDelimiter($eol = "\n")
310 310
     {
311 311
         $frequencies = [];
@@ -382,16 +382,16 @@  discard block
 block discarded – undo
382 382
              *     which one has the best distribution, return that one.
383 383
              */
384 384
 
385
-             $decision = $dups->get($max);
386
-             try {
387
-                 return $this->guessDelimByDistribution($decision, $eol);
388
-             } catch (TasterException $e) {
389
-                 // if somehow we STILL can't come to a consensus, then fall back to a
390
-                 // "preferred delimiters" list...
391
-                 foreach ($this->delims as $key => $val) {
385
+                $decision = $dups->get($max);
386
+                try {
387
+                    return $this->guessDelimByDistribution($decision, $eol);
388
+                } catch (TasterException $e) {
389
+                    // if somehow we STILL can't come to a consensus, then fall back to a
390
+                    // "preferred delimiters" list...
391
+                    foreach ($this->delims as $key => $val) {
392 392
                     if ($delim = array_search($val, $decision)) return $delim;
393
-                 }
394
-             }
393
+                    }
394
+                }
395 395
         }
396 396
         return $delims
397 397
             ->sort()
@@ -450,8 +450,8 @@  discard block
 block discarded – undo
450 450
             })->map(function($dists) {
451 451
                 return $dists->average();
452 452
             })->sort()
453
-              ->reverse()
454
-              ->getKeyAtPosition(0)];
453
+                ->reverse()
454
+                ->getKeyAtPosition(0)];
455 455
         } catch (Exception $e) {
456 456
             throw new TasterException("delimiter cannot be determined by distribution", TasterException::ERR_DELIMITER);
457 457
         }
Please login to merge, or discard this patch.
src/CSVelte/IO/Resource.php 2 patches
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -254,7 +254,9 @@  discard block
 block discarded – undo
254 254
                 $this->getContext()
255 255
             );
256 256
             restore_error_handler();
257
-            if ($e) throw $e;
257
+            if ($e) {
258
+                throw $e;
259
+            }
258 260
         }
259 261
         return $this->isConnected();
260 262
     }
@@ -328,7 +330,9 @@  discard block
 block discarded – undo
328 330
     public function setMode($mode = null)
329 331
     {
330 332
         $this->assertNotConnected(__METHOD__);
331
-        if (is_null($mode)) $mode = "r+b";
333
+        if (is_null($mode)) {
334
+            $mode = "r+b";
335
+        }
332 336
 
333 337
         $mode = substr($mode, 0, 3);
334 338
         $rest = substr($mode, 1);
@@ -436,7 +440,9 @@  discard block
 block discarded – undo
436 440
      */
437 441
     protected function setLazy($lazy)
438 442
     {
439
-        if (is_null($lazy)) $lazy = true;
443
+        if (is_null($lazy)) {
444
+            $lazy = true;
445
+        }
440 446
         $this->lazy = (boolean) $lazy;
441 447
         return $this;
442 448
     }
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -185,10 +185,10 @@  discard block
 block discarded – undo
185 185
 
186 186
         // ok we're opening a new stream resource handle
187 187
         $this->setUri($uri)
188
-             ->setMode($mode)
189
-             ->setLazy($lazy)
190
-             ->setUseIncludePath($use_include_path)
191
-             ->setContext($context_options, $context_params);
188
+                ->setMode($mode)
189
+                ->setLazy($lazy)
190
+                ->setUseIncludePath($use_include_path)
191
+                ->setContext($context_options, $context_params);
192 192
         if (!$this->isLazy()) {
193 193
             $this->connect();
194 194
         }
@@ -351,9 +351,9 @@  discard block
 block discarded – undo
351 351
 
352 352
         $this->flag = '';
353 353
         $this->setBaseMode($base)
354
-             ->setIsPlus($plus == '+')
355
-             ->setIsText($flag == 't')
356
-             ->setIsBinary($flag == 'b');
354
+                ->setIsPlus($plus == '+')
355
+                ->setIsText($flag == 't')
356
+                ->setIsBinary($flag == 'b');
357 357
 
358 358
         return $this;
359 359
     }
Please login to merge, or discard this patch.