Completed
Push — master ( 748f90...5c1aea )
by Luke
08:07
created
src/CSVelte/Writer.php 2 patches
Doc Comments   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      * likely buffer the output so that this may be called after writeRows()
91 91
      *
92 92
      * @param \Iterator|array A list of header values
93
-     * @return boolean
93
+     * @return boolean|null
94 94
      * @throws \CSVelte\Exception\WriterException
95 95
      */
96 96
     public function setHeaderRow($headers)
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      * This means taking an array of data, and converting it to a Row object
162 162
      *
163 163
      * @param \Iterator|array of data items
164
-     * @return CSVelte\Table\AbstractRow
164
+     * @return Row
165 165
      * @access protected
166 166
      */
167 167
     protected function prepareRow(Iterator $row)
@@ -189,6 +189,9 @@  discard block
 block discarded – undo
189 189
         return $this->quoteString($data);
190 190
     }
191 191
 
192
+    /**
193
+     * @param string $str
194
+     */
192 195
     protected function quoteString($str)
193 196
     {
194 197
         $flvr = $this->getFlavor();
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
     {
142 142
         if (is_array($rows)) $rows = new ArrayIterator($rows);
143 143
         if (!($rows instanceof Iterator)) {
144
-            throw new InvalidArgumentException('First argument for ' . __METHOD__ . ' must be iterable');
144
+            throw new InvalidArgumentException('First argument for '.__METHOD__.' must be iterable');
145 145
         }
146 146
         $written = 0;
147 147
         if ($rows instanceof Reader) {
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
     {
166 166
         $items = array();
167 167
         foreach ($row as $data) {
168
-            $items []= $this->prepareData($data);
168
+            $items [] = $this->prepareData($data);
169 169
         }
170 170
         $row = new Row($items);
171 171
         return $row;
@@ -193,11 +193,11 @@  discard block
 block discarded – undo
193 193
         // to use it for very long, in fact, once I finish writing the Data class
194 194
         // it is gonezo!
195 195
         $hasSpecialChars = function($s) use ($flvr) {
196
-            $specialChars = preg_quote($flvr->lineTerminator . $flvr->quoteChar . $flvr->delimiter);
196
+            $specialChars = preg_quote($flvr->lineTerminator.$flvr->quoteChar.$flvr->delimiter);
197 197
             $pattern = "/[{$specialChars}]/m";
198 198
             return preg_match($pattern, $s);
199 199
         };
200
-        switch($flvr->quoteStyle) {
200
+        switch ($flvr->quoteStyle) {
201 201
             case Flavor::QUOTE_ALL:
202 202
                 $doQuote = true;
203 203
                 break;
@@ -227,6 +227,6 @@  discard block
 block discarded – undo
227 227
         $escapeQuote = "";
228 228
         if ($isQuoted) $escapeQuote = ($flvr->doubleQuote) ? $flvr->quoteChar : $flvr->escapeChar;
229 229
         // @todo Not sure what else, if anything, I'm supposed to be escaping here..
230
-        return str_replace($flvr->quoteChar, $escapeQuote . $flvr->quoteChar, $str);
230
+        return str_replace($flvr->quoteChar, $escapeQuote.$flvr->quoteChar, $str);
231 231
     }
232 232
 }
Please login to merge, or discard this patch.
src/CSVelte/Taster.php 2 patches
Doc Comments   +6 added lines, -1 removed lines patch added patch discarded remove patch
@@ -165,6 +165,7 @@  discard block
 block discarded – undo
165 165
      * replaceQuotedSpecialChars method which (at least to me) makes more sense.
166 166
      *
167 167
      * @param string The string to replace quoted strings within
168
+     * @param string $data
168 169
      * @return string The input string with quoted strings removed
169 170
      * @access protected
170 171
      * @todo Replace code that uses this method with the replaceQuotedSpecialChars
@@ -414,7 +415,7 @@  discard block
 block discarded – undo
414 415
      * Determine whether a particular string of data has quotes around it.
415 416
      *
416 417
      * @param string The data to check
417
-     * @return boolean Whether the data is quoted or not
418
+     * @return integer Whether the data is quoted or not
418 419
      * @access protected
419 420
      */
420 421
     protected function isQuoted($data)
@@ -464,6 +465,8 @@  discard block
 block discarded – undo
464 465
      *
465 466
      * @param string The string to do the replacements on
466 467
      * @param string The delimiter character to replace
468
+     * @param string $data
469
+     * @param string $delim
467 470
      * @return string The data with replacements performed
468 471
      * @access protected
469 472
      * @todo I could probably pass in (maybe optionally) the newline character I
@@ -490,6 +493,7 @@  discard block
 block discarded – undo
490 493
      * to be practical.
491 494
      *
492 495
      * @param string The string of data to check the type of
496
+     * @param string $data
493 497
      * @return string One of the TYPE_ string constants above
494 498
      * @access protected
495 499
      * @uses \Carbon\Carbon date/time ilbrary/class
@@ -546,6 +550,7 @@  discard block
 block discarded – undo
546 550
      * @param string $delim The CSV data's delimiting char (can be a variety of chars but)
547 551
      *     typically $eol is either a comma or a tab, sometimes a pipe)
548 552
      * @param string The CSV data's end-of-line char(s) (\n \r or \r\n)
553
+     * @param string $eol
549 554
      * @return boolean True if the data (most likely) contains a header row
550 555
      * @access public
551 556
      * @todo This method needs a total refactor. It's not necessary to loop twice
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -193,16 +193,16 @@  discard block
 block discarded – undo
193 193
     {
194 194
         $str = $this->removeQuotedStrings($this->sample);
195 195
         $eols = [
196
-            self::EOL_WINDOWS => "\r\n",  // 0x0D - 0x0A - Windows, DOS OS/2
197
-            self::EOL_UNIX    => "\n",    // 0x0A -      - Unix, OSX
198
-            self::EOL_TRS80   => "\r",    // 0x0D -      - Apple ][, TRS80
196
+            self::EOL_WINDOWS => "\r\n", // 0x0D - 0x0A - Windows, DOS OS/2
197
+            self::EOL_UNIX    => "\n", // 0x0A -      - Unix, OSX
198
+            self::EOL_TRS80   => "\r", // 0x0D -      - Apple ][, TRS80
199 199
         ];
200 200
 
201 201
         $curCount = 0;
202 202
         // @todo This should return a default maybe?
203 203
         $curEol = PHP_EOL;
204
-        foreach($eols as $k => $eol) {
205
-            if( ($count = substr_count($str, $eol)) > $curCount) {
204
+        foreach ($eols as $k => $eol) {
205
+            if (($count = substr_count($str, $eol)) > $curCount) {
206 206
                 $curCount = $count;
207 207
                 $curEol = $eol;
208 208
             }
@@ -235,12 +235,12 @@  discard block
 block discarded – undo
235 235
         $patterns = [];
236 236
         // delim can be anything but line breaks, quotes, alphanumeric, underscore, backslash, or any type of spaces
237 237
         $antidelims = implode(array("\r", "\n", "\w", preg_quote('"', '/'), preg_quote("'", '/')/*, preg_quote('\\', '/')*/, preg_quote(chr(self::SPACE), '/')));
238
-        $delim = '(?P<delim>[^' . $antidelims . '])';
238
+        $delim = '(?P<delim>[^'.$antidelims.'])';
239 239
         $quote = '(?P<quoteChar>"|\'|`)'; // @todo I think MS Excel uses some strange encoding for fancy open/close quotes
240
-        $patterns[] = '/' . $delim . ' ?' . $quote . '.*?\2\1/ms'; // ,"something", - anything but whitespace or quotes followed by a possible space followed by a quote followed by anything followed by same quote, followed by same anything but whitespace
241
-        $patterns[] = '/(?:^|\n)' . $quote . '.*?\1' . $delim . ' ?/ms'; // 'something', - beginning of line or line break, followed by quote followed by anything followed by quote followed by anything but whitespace or quotes
242
-        $patterns[] = '/' . $delim . ' ?' . $quote . '.*?\2(?:^|\n)/ms'; // ,'something' - anything but whitespace or quote followed by possible space followed by quote followed by anything followed by quote, followed by end of line
243
-        $patterns[] = '/(?:^|\n)' . $quote . '.*?\2(?:$|\n)/ms'; // 'something' - beginning of line followed by quote followed by anything followed by quote followed by same quote followed by end of line
240
+        $patterns[] = '/'.$delim.' ?'.$quote.'.*?\2\1/ms'; // ,"something", - anything but whitespace or quotes followed by a possible space followed by a quote followed by anything followed by same quote, followed by same anything but whitespace
241
+        $patterns[] = '/(?:^|\n)'.$quote.'.*?\1'.$delim.' ?/ms'; // 'something', - beginning of line or line break, followed by quote followed by anything followed by quote followed by anything but whitespace or quotes
242
+        $patterns[] = '/'.$delim.' ?'.$quote.'.*?\2(?:^|\n)/ms'; // ,'something' - anything but whitespace or quote followed by possible space followed by quote followed by anything followed by quote, followed by end of line
243
+        $patterns[] = '/(?:^|\n)'.$quote.'.*?\2(?:$|\n)/ms'; // 'something' - beginning of line followed by quote followed by anything followed by quote followed by same quote followed by end of line
244 244
         foreach ($patterns as $pattern) {
245 245
             // @todo I had to add the error suppression char here because it was
246 246
             //     causing undefined offset errors with certain data sets. strange...
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
             if (array_key_exists(self::DATA_NONNUMERIC, array_flip($types))) {
386 386
                 // allow for a SMALL amount of error here
387 387
                 $counts = array(self::DATA_SPECIAL => 0, self::DATA_NONNUMERIC => 0);
388
-                array_walk($freq['quoted'], function ($val) use (&$counts) {
388
+                array_walk($freq['quoted'], function($val) use (&$counts) {
389 389
                     $counts[$val]++;
390 390
                 });
391 391
                 arsort($counts);
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
                 $day = '[0-3]?[0-9]';
512 512
                 $sep = '[\/\.\-]?';
513 513
                 $time = '([0-2]?[0-9](:[0-5][0-9]){1,2}(am|pm)?|[01]?[0-9](am|pm))';
514
-                $date = '(' . $month . $sep . $day . $sep . $year . '|' . $day . $sep . $month . $sep . $year . '|' . $year . $sep . $month . $sep . $day . ')';
514
+                $date = '('.$month.$sep.$day.$sep.$year.'|'.$day.$sep.$month.$sep.$year.'|'.$year.$sep.$month.$sep.$day.')';
515 515
                 $dt = Carbon::parse($data);
516 516
                 if ($dt->today()) {
517 517
                     // then this is most likely a time string...
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
                 }
522 522
                 if (preg_match("/^{$date}$/i", $data)) {
523 523
                     return self::TYPE_DATE;
524
-                } elseif(preg_match("/^{$date} {$time}$/i")) {
524
+                } elseif (preg_match("/^{$date} {$time}$/i")) {
525 525
                     return self::TYPE_DATETIME;
526 526
                 }
527 527
             } catch (\Exception $e) {
Please login to merge, or discard this patch.
src/CSVelte/Reader.php 2 patches
Doc Comments   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      * accept any string (or any object with a __toString() method), or an
128 128
      * SplFileObject, so long as it represents a file rather than a directory. 
129 129
      *
130
-     * @param \CSVelte\Contract\Readable|object|string|SplFileObject $input See description
130
+     * @param Readable $input See description
131 131
      * @return $this
132 132
      */
133 133
     protected function setSource($input)
@@ -328,6 +328,9 @@  discard block
 block discarded – undo
328 328
      * @todo This actually shouldn't even be necessary. Characters should be read
329 329
      *     in one at a time and a quote that follows another should just be ignored
330 330
      *     deeming this unnecessary.
331
+     * @param string $str
332
+     * @param string $esc
333
+     * @param string $quo
331 334
      */
332 335
     protected function unEscape($str, $esc, $quo)
333 336
     {
@@ -338,6 +341,7 @@  discard block
 block discarded – undo
338 341
      * Parse a line of CSV data into an array of columns
339 342
      *
340 343
      * @param string A line of CSV data to parse
344
+     * @param string $line
341 345
      * @return array An array of columns
342 346
      * @access protected
343 347
      * @internal
@@ -417,7 +421,7 @@  discard block
 block discarded – undo
417 421
     /**
418 422
      * Retrieve header row.
419 423
      *
420
-     * @return CSVelte\Table\HeaderRow|null The header row if there is one
424
+     * @return HeaderRow The header row if there is one
421 425
      */
422 426
     public function header()
423 427
     {
@@ -458,7 +462,7 @@  discard block
 block discarded – undo
458 462
     /**
459 463
      * Returns an iterator with rows from user-supplied filter functions removed
460 464
      *
461
-     * @return CSVelte\Reader\FilteredReader An iterator with filtered rows
465
+     * @return FilteredReader An iterator with filtered rows
462 466
      */
463 467
     public function filter()
464 468
     {
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
             do {
186 186
                 if (!isset($lines)) $lines = array();
187 187
                 if (false === ($line = $this->source->readLine($eol))) {
188
-                    throw new EndOfFileException("End of file reached: " . $this->source->getName());
188
+                    throw new EndOfFileException("End of file reached: ".$this->source->getName());
189 189
                 }
190 190
                 array_push($lines, rtrim($line, $eol));
191 191
             } while ($this->inQuotedString(end($lines), $f->quoteChar, $f->escapeChar));
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
      */
280 280
     protected function replaceQuotedSpecialChars($data, $delim, $quo, $eol)
281 281
     {
282
-        return preg_replace_callback('/(['. preg_quote($quo, '/') . '])(.*)\1/imsU', function($matches) use ($delim, $eol) {
282
+        return preg_replace_callback('/(['.preg_quote($quo, '/').'])(.*)\1/imsU', function($matches) use ($delim, $eol) {
283 283
             $ret = str_replace($eol, self::PLACEHOLDER_NEWLINE, $matches[0]);
284 284
             $ret = str_replace($delim, self::PLACEHOLDER_DELIM, $ret);
285 285
             return $ret;
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
      */
332 332
     protected function unEscape($str, $esc, $quo)
333 333
     {
334
-        return str_replace($esc . $quo, $quo, $str);
334
+        return str_replace($esc.$quo, $quo, $str);
335 335
     }
336 336
 
337 337
     /**
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
      */
473 473
     public function toArray()
474 474
     {
475
-        return array_map(function($row){
475
+        return array_map(function($row) {
476 476
             return $row->toArray();
477 477
         }, iterator_to_array($this));
478 478
     }
Please login to merge, or discard this patch.
src/CSVelte/Reader/FilteredIterator.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@
 block discarded – undo
73 73
 
74 74
     public function toArray()
75 75
     {
76
-        return array_map(function($row){
76
+        return array_map(function($row) {
77 77
             return $row->toArray();
78 78
         }, iterator_to_array($this));
79 79
     }
Please login to merge, or discard this patch.
src/CSVelte/Flavor.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
     protected function assertValidAttribute($attr)
193 193
     {
194 194
         if (!property_exists(self::class, $attr))
195
-            throw new InvalidArgumentException("Unknown attribute: " . $attr);
195
+            throw new InvalidArgumentException("Unknown attribute: ".$attr);
196 196
     }
197 197
 
198 198
     /**
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      */
242 242
     public function __set($attr, $val)
243 243
     {
244
-        throw new ImmutableException("Cannot change attributes on an immutable object: " . self::class . "::\$" . $attr);
244
+        throw new ImmutableException("Cannot change attributes on an immutable object: ".self::class."::\$".$attr);
245 245
     }
246 246
 
247 247
     public function toArray()
Please login to merge, or discard this patch.
src/CSVelte/Table/AbstractRow.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             } elseif ($fields instanceof Iterator) {
68 68
                 $fields = iterator_to_array($fields);
69 69
             } else {
70
-                throw new InvalidArgumentException(__CLASS__ . " requires an array, got: " . gettype($fields));
70
+                throw new InvalidArgumentException(__CLASS__." requires an array, got: ".gettype($fields));
71 71
             }
72 72
         }
73 73
         $this->fields = array_values($fields);
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
     protected function assertOffsetExists($offset)
250 250
     {
251 251
         if (!$this->offsetExists($offset)) {
252
-            throw new OutOfBoundsException("Undefined offset: " . $offset);
252
+            throw new OutOfBoundsException("Undefined offset: ".$offset);
253 253
         }
254 254
     }
255 255
 
Please login to merge, or discard this patch.
src/CSVelte/Traits/IsWritable.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function writeLine($line, $eol = PHP_EOL)
42 42
     {
43
-        return $this->write($line . $eol);
43
+        return $this->write($line.$eol);
44 44
     }
45 45
 
46 46
     /**
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     protected function assertIsWritable()
53 53
     {
54 54
         if (!$this->isWritable()) {
55
-            throw new IOException("Stream not writable: " . $this->getName(), IOException::ERR_NOT_WRITABLE);
55
+            throw new IOException("Stream not writable: ".$this->getName(), IOException::ERR_NOT_WRITABLE);
56 56
         }
57 57
     }
58 58
 
Please login to merge, or discard this patch.
src/CSVelte/Traits/IsReadable.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@
 block discarded – undo
75 75
     protected function assertIsReadable()
76 76
     {
77 77
         if (!$this->isReadable()) {
78
-            throw new IOException("Stream not readable: " . $this->getName(), IOException::ERR_NOT_READABLE);
78
+            throw new IOException("Stream not readable: ".$this->getName(), IOException::ERR_NOT_READABLE);
79 79
         }
80 80
     }
81 81
 
Please login to merge, or discard this patch.
src/CSVelte/Traits/IsSeekable.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@
 block discarded – undo
55 55
     protected function assertIsSeekable()
56 56
     {
57 57
         if (!$this->isSeekable()) {
58
-            throw new IOException("Stream not seekable: " . $this->getName(), IOException::ERR_NOT_SEEKABLE);
58
+            throw new IOException("Stream not seekable: ".$this->getName(), IOException::ERR_NOT_SEEKABLE);
59 59
         }
60 60
     }
61 61
 
Please login to merge, or discard this patch.