@@ -189,6 +189,7 @@ discard block |
||
189 | 189 | * replaceQuotedSpecialChars method which (at least to me) makes more sense. |
190 | 190 | * |
191 | 191 | * @param string The string to replace quoted strings within |
192 | + * @param string $data |
|
192 | 193 | * @return string The input string with quoted strings removed |
193 | 194 | * @todo Replace code that uses this method with the replaceQuotedSpecialChars |
194 | 195 | * method instead. I think it's cleaner. |
@@ -559,7 +560,7 @@ discard block |
||
559 | 560 | * Determine whether a particular string of data has quotes around it. |
560 | 561 | * |
561 | 562 | * @param string The data to check |
562 | - * @return boolean Whether the data is quoted or not |
|
563 | + * @return integer Whether the data is quoted or not |
|
563 | 564 | */ |
564 | 565 | protected function isQuoted($data) |
565 | 566 | { |
@@ -607,6 +608,8 @@ discard block |
||
607 | 608 | * |
608 | 609 | * @param string The string to do the replacements on |
609 | 610 | * @param string The delimiter character to replace |
611 | + * @param string $data |
|
612 | + * @param string $delim |
|
610 | 613 | * @return string The data with replacements performed |
611 | 614 | * @todo I could probably pass in (maybe optionally) the newline character I |
612 | 615 | * want to replace as well. I'll do that if I need to. |
@@ -632,6 +635,7 @@ discard block |
||
632 | 635 | * to be practical. |
633 | 636 | * |
634 | 637 | * @param string The string of data to check the type of |
638 | + * @param string $data |
|
635 | 639 | * @return string One of the TYPE_ string constants above |
636 | 640 | */ |
637 | 641 | protected function lickType($data) |
@@ -215,16 +215,16 @@ discard block |
||
215 | 215 | { |
216 | 216 | $str = $this->removeQuotedStrings($this->sample); |
217 | 217 | $eols = [ |
218 | - self::EOL_WINDOWS => "\r\n", // 0x0D - 0x0A - Windows, DOS OS/2 |
|
219 | - self::EOL_UNIX => "\n", // 0x0A - - Unix, OSX |
|
220 | - self::EOL_TRS80 => "\r", // 0x0D - - Apple ][, TRS80 |
|
218 | + self::EOL_WINDOWS => "\r\n", // 0x0D - 0x0A - Windows, DOS OS/2 |
|
219 | + self::EOL_UNIX => "\n", // 0x0A - - Unix, OSX |
|
220 | + self::EOL_TRS80 => "\r", // 0x0D - - Apple ][, TRS80 |
|
221 | 221 | ]; |
222 | 222 | |
223 | 223 | $curCount = 0; |
224 | 224 | // @todo This should return a default maybe? |
225 | 225 | $curEol = PHP_EOL; |
226 | - foreach($eols as $k => $eol) { |
|
227 | - if( ($count = substr_count($str, $eol)) > $curCount) { |
|
226 | + foreach ($eols as $k => $eol) { |
|
227 | + if (($count = substr_count($str, $eol)) > $curCount) { |
|
228 | 228 | $curCount = $count; |
229 | 229 | $curEol = $eol; |
230 | 230 | } |
@@ -256,12 +256,12 @@ discard block |
||
256 | 256 | $patterns = []; |
257 | 257 | // delim can be anything but line breaks, quotes, alphanumeric, underscore, backslash, or any type of spaces |
258 | 258 | $antidelims = implode(array("\r", "\n", "\w", preg_quote('"', '/'), preg_quote("'", '/')/*, preg_quote('\\', '/')*/, preg_quote(chr(self::SPACE), '/'))); |
259 | - $delim = '(?P<delim>[^' . $antidelims . '])'; |
|
259 | + $delim = '(?P<delim>[^'.$antidelims.'])'; |
|
260 | 260 | $quote = '(?P<quoteChar>"|\'|`)'; // @todo I think MS Excel uses some strange encoding for fancy open/close quotes |
261 | - $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 |
|
262 | - $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 |
|
263 | - $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 |
|
264 | - $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 |
|
261 | + $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 |
|
262 | + $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 |
|
263 | + $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 |
|
264 | + $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 |
|
265 | 265 | foreach ($patterns as $pattern) { |
266 | 266 | // @todo I had to add the error suppression char here because it was |
267 | 267 | // causing undefined offset errors with certain data sets. strange... |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | if ($types->contains(self::DATA_NONNUMERIC)) { |
531 | 531 | // allow for a SMALL amount of error here |
532 | 532 | $counts = collect([self::DATA_SPECIAL => 0, self::DATA_NONNUMERIC => 0]); |
533 | - $freq->get('quoted')->walk(function ($type) use (&$counts) { |
|
533 | + $freq->get('quoted')->walk(function($type) use (&$counts) { |
|
534 | 534 | $counts->increment($type); |
535 | 535 | }); |
536 | 536 | // @todo is all this even necessary? seems unnecessary to me... |
@@ -651,13 +651,13 @@ discard block |
||
651 | 651 | $day = '[0-3]?[0-9]'; |
652 | 652 | $sep = '[\/\.\-]?'; |
653 | 653 | $time = '([0-2]?[0-9](:[0-5][0-9]){1,2}(am|pm)?|[01]?[0-9](am|pm))'; |
654 | - $date = '(' . $month . $sep . $day . $sep . $year . '|' . $day . $sep . $month . $sep . $year . '|' . $year . $sep . $month . $sep . $day . ')'; |
|
654 | + $date = '('.$month.$sep.$day.$sep.$year.'|'.$day.$sep.$month.$sep.$year.'|'.$year.$sep.$month.$sep.$day.')'; |
|
655 | 655 | $dt = new DateTime($data); |
656 | - $dt->setTime(0,0,0); |
|
656 | + $dt->setTime(0, 0, 0); |
|
657 | 657 | $now = new DateTime(); |
658 | - $now->setTime(0,0,0); |
|
658 | + $now->setTime(0, 0, 0); |
|
659 | 659 | $diff = $dt->diff($now); |
660 | - $diffDays = (integer) $diff->format( "%R%a" ); |
|
660 | + $diffDays = (integer) $diff->format("%R%a"); |
|
661 | 661 | if ($diffDays === 0) { |
662 | 662 | // then this is most likely a time string... |
663 | 663 | if (preg_match("/^{$time}$/i", $data)) { |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | } |
667 | 667 | if (preg_match("/^{$date}$/i", $data)) { |
668 | 668 | return self::TYPE_DATE; |
669 | - } elseif(preg_match("/^{$date} {$time}$/i")) { |
|
669 | + } elseif (preg_match("/^{$date} {$time}$/i")) { |
|
670 | 670 | return self::TYPE_DATETIME; |
671 | 671 | } |
672 | 672 | } catch (\Exception $e) { |
@@ -169,7 +169,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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... |
@@ -290,20 +290,20 @@ discard block |
||
290 | 290 | throw new TasterException("quoteChar and delimiter cannot be determined", TasterException::ERR_QUOTE_AND_DELIM); |
291 | 291 | } |
292 | 292 | |
293 | - /** |
|
294 | - * Take a list of likely delimiter characters and find the one that occurs |
|
295 | - * the most consistent amount of times within the provided data. |
|
296 | - * |
|
297 | - * @param string The character(s) used for newlines |
|
298 | - * @return string One of four Flavor::QUOTING_* constants |
|
299 | - * @see \CSVelte\Flavor for possible quote style constants |
|
300 | - * @todo Refactor this method--It needs more thorough testing against a wider |
|
301 | - * variety of CSV data to be sure it works reliably. And I'm sure there |
|
302 | - * are many performance and logic improvements that could be made. This |
|
303 | - * is essentially a first draft. |
|
304 | - * @todo Can't use replaceQuotedSpecialChars rather than removeQuotedStrings |
|
305 | - * because the former requires u to know the delimiter |
|
306 | - */ |
|
293 | + /** |
|
294 | + * Take a list of likely delimiter characters and find the one that occurs |
|
295 | + * the most consistent amount of times within the provided data. |
|
296 | + * |
|
297 | + * @param string The character(s) used for newlines |
|
298 | + * @return string One of four Flavor::QUOTING_* constants |
|
299 | + * @see \CSVelte\Flavor for possible quote style constants |
|
300 | + * @todo Refactor this method--It needs more thorough testing against a wider |
|
301 | + * variety of CSV data to be sure it works reliably. And I'm sure there |
|
302 | + * are many performance and logic improvements that could be made. This |
|
303 | + * is essentially a first draft. |
|
304 | + * @todo Can't use replaceQuotedSpecialChars rather than removeQuotedStrings |
|
305 | + * because the former requires u to know the delimiter |
|
306 | + */ |
|
307 | 307 | protected function lickDelimiter($eol = "\n") |
308 | 308 | { |
309 | 309 | $frequencies = []; |
@@ -380,16 +380,16 @@ discard block |
||
380 | 380 | * which one has the best distribution, return that one. |
381 | 381 | */ |
382 | 382 | |
383 | - $decision = $dups->get($max); |
|
384 | - try { |
|
385 | - return $this->guessDelimByDistribution($decision, $eol); |
|
386 | - } catch (TasterException $e) { |
|
387 | - // if somehow we STILL can't come to a consensus, then fall back to a |
|
388 | - // "preferred delimiters" list... |
|
389 | - foreach ($this->delims as $key => $val) { |
|
383 | + $decision = $dups->get($max); |
|
384 | + try { |
|
385 | + return $this->guessDelimByDistribution($decision, $eol); |
|
386 | + } catch (TasterException $e) { |
|
387 | + // if somehow we STILL can't come to a consensus, then fall back to a |
|
388 | + // "preferred delimiters" list... |
|
389 | + foreach ($this->delims as $key => $val) { |
|
390 | 390 | if ($delim = array_search($val, $decision)) return $delim; |
391 | - } |
|
392 | - } |
|
391 | + } |
|
392 | + } |
|
393 | 393 | } |
394 | 394 | return $delims |
395 | 395 | ->sort() |
@@ -446,8 +446,8 @@ discard block |
||
446 | 446 | })->map(function($dists) { |
447 | 447 | return $dists->average(); |
448 | 448 | })->sort() |
449 | - ->reverse() |
|
450 | - ->getKeyAtPosition(0)]; |
|
449 | + ->reverse() |
|
450 | + ->getKeyAtPosition(0)]; |
|
451 | 451 | } catch (Exception $e) { |
452 | 452 | throw new TasterException("delimiter cannot be determined by distribution", TasterException::ERR_DELIMITER); |
453 | 453 | } |
@@ -73,7 +73,7 @@ |
||
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 | } |
@@ -192,7 +192,7 @@ discard block |
||
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 |
||
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() |
@@ -191,8 +191,9 @@ |
||
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 | /** |
@@ -56,7 +56,7 @@ |
||
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) |
@@ -68,7 +68,7 @@ |
||
68 | 68 | } elseif ($fields instanceof Iterator) { |
69 | 69 | $fields = iterator_to_array($fields); |
70 | 70 | } else { |
71 | - throw new InvalidArgumentException(__CLASS__ . " requires an array, got: " . gettype($fields)); |
|
71 | + throw new InvalidArgumentException(__CLASS__." requires an array, got: ".gettype($fields)); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | $this->fields = collect(array_values($fields)); |
@@ -152,7 +152,9 @@ |
||
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 | /** |
@@ -45,7 +45,9 @@ |
||
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))) { |
@@ -91,8 +91,8 @@ |
||
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 | /** |
@@ -104,7 +104,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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; |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | */ |
284 | 284 | protected function replaceQuotedSpecialChars($data, $delim, $quo, $eol) |
285 | 285 | { |
286 | - return preg_replace_callback('/(['. preg_quote($quo, '/') . '])(.*)\1/imsU', function($matches) use ($delim, $eol) { |
|
286 | + return preg_replace_callback('/(['.preg_quote($quo, '/').'])(.*)\1/imsU', function($matches) use ($delim, $eol) { |
|
287 | 287 | $ret = str_replace($eol, self::PLACEHOLDER_NEWLINE, $matches[0]); |
288 | 288 | $ret = str_replace($delim, self::PLACEHOLDER_DELIM, $ret); |
289 | 289 | return $ret; |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | */ |
336 | 336 | protected function unEscape($str, $esc, $quo) |
337 | 337 | { |
338 | - return str_replace($esc . $quo, $quo, $str); |
|
338 | + return str_replace($esc.$quo, $quo, $str); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | */ |
477 | 477 | public function toArray() |
478 | 478 | { |
479 | - return array_map(function($row){ |
|
479 | + return array_map(function($row) { |
|
480 | 480 | return $row->toArray(); |
481 | 481 | }, iterator_to_array($this)); |
482 | 482 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | { |
124 | 124 | self::assertFileExists($filename); |
125 | 125 | if (!is_readable($filename)) { |
126 | - throw new IOException('Permission denied for: ' . $filename, IOException::ERR_FILE_PERMISSION_DENIED); |
|
126 | + throw new IOException('Permission denied for: '.$filename, IOException::ERR_FILE_PERMISSION_DENIED); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | protected static function assertFileExists($filename) |
138 | 138 | { |
139 | 139 | if (!file_exists($filename)) { |
140 | - throw new IOException('File does not exist: ' . $filename, IOException::ERR_FILE_NOT_FOUND); |
|
140 | + throw new IOException('File does not exist: '.$filename, IOException::ERR_FILE_NOT_FOUND); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | } |
@@ -62,10 +62,10 @@ discard block |
||
62 | 62 | $paths = $this->getPaths(); |
63 | 63 | if ($rp = realpath($path)) { |
64 | 64 | if (in_array($rp, $paths)) return true; |
65 | - $this->paths []= $rp; |
|
65 | + $this->paths [] = $rp; |
|
66 | 66 | return true; |
67 | 67 | } |
68 | - $this->paths []= $path; |
|
68 | + $this->paths [] = $path; |
|
69 | 69 | return false; |
70 | 70 | } |
71 | 71 | |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function load($className) |
115 | 115 | { |
116 | - if(class_exists($className)) { |
|
116 | + if (class_exists($className)) { |
|
117 | 117 | return; |
118 | 118 | } |
119 | 119 | $fqcp = str_replace(self::NAMESPACE_SEPARATOR, DIRECTORY_SEPARATOR, $className); |
120 | 120 | $paths = $this->getPaths(); |
121 | 121 | foreach ($paths as $path) { |
122 | - $classPath = $path . DIRECTORY_SEPARATOR . $fqcp . '.php'; |
|
123 | - if(file_exists($classPath) && is_readable($classPath)) { |
|
122 | + $classPath = $path.DIRECTORY_SEPARATOR.$fqcp.'.php'; |
|
123 | + if (file_exists($classPath) && is_readable($classPath)) { |
|
124 | 124 | require_once($classPath); |
125 | 125 | return; |
126 | 126 | } |
@@ -61,7 +61,9 @@ |
||
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 | } |
@@ -19,7 +19,6 @@ |
||
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 | * |