@@ -82,7 +82,7 @@ |
||
82 | 82 | */ |
83 | 83 | public function toArray() |
84 | 84 | { |
85 | - return array_map(function ($row) { |
|
85 | + return array_map(function($row) { |
|
86 | 86 | return $row->toArray(); |
87 | 87 | }, iterator_to_array($this)); |
88 | 88 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | { |
245 | 245 | if (!$this->isConnected()) { |
246 | 246 | $e = null; |
247 | - $errhandler = function () use (&$e) { |
|
247 | + $errhandler = function() use (&$e) { |
|
248 | 248 | $e = new IOException(sprintf( |
249 | 249 | 'Could not open connection for %s using mode %s', |
250 | 250 | $this->getUri(), |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | |
544 | 544 | return $this; |
545 | 545 | } |
546 | - throw new InvalidArgumentException('Context options must be an array, got: ' . gettype($options)); |
|
546 | + throw new InvalidArgumentException('Context options must be an array, got: '.gettype($options)); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | |
568 | 568 | return $this; |
569 | 569 | } |
570 | - throw new InvalidArgumentException('Context parameters must be an array, got: ' . gettype($params)); |
|
570 | + throw new InvalidArgumentException('Context parameters must be an array, got: '.gettype($params)); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | /** |
@@ -896,7 +896,7 @@ discard block |
||
896 | 896 | if (is_null($lazy)) { |
897 | 897 | $lazy = true; |
898 | 898 | } |
899 | - $this->lazy = (bool) $lazy; |
|
899 | + $this->lazy = (bool) $lazy; |
|
900 | 900 | |
901 | 901 | return $this; |
902 | 902 | } |
@@ -165,7 +165,7 @@ |
||
165 | 165 | $top = substr($this->buffer, 0, $start); |
166 | 166 | $data = substr($this->buffer, $start, $length); |
167 | 167 | $bottom = substr($this->buffer, $start + $length); |
168 | - $this->buffer = $top . $bottom; |
|
168 | + $this->buffer = $top.$bottom; |
|
169 | 169 | |
170 | 170 | return $data; |
171 | 171 | } |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | } |
371 | 371 | $i++; |
372 | 372 | } |
373 | - throw new OutOfBoundsException('Collection data does not contain a key at given position: ' . $pos); |
|
373 | + throw new OutOfBoundsException('Collection data does not contain a key at given position: '.$pos); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | return $this->data[$key]; |
576 | 576 | } |
577 | 577 | if ($throwExc) { |
578 | - throw new OutOfBoundsException('Collection data does not contain value for given key: ' . $key); |
|
578 | + throw new OutOfBoundsException('Collection data does not contain value for given key: '.$key); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | return $default; |
@@ -928,11 +928,11 @@ discard block |
||
928 | 928 | public function duplicates() |
929 | 929 | { |
930 | 930 | $dups = []; |
931 | - $this->walk(function ($val, $key) use (&$dups) { |
|
931 | + $this->walk(function($val, $key) use (&$dups) { |
|
932 | 932 | $dups[$val][] = $key; |
933 | 933 | }); |
934 | 934 | |
935 | - return (new self($dups))->filter(function ($val) { |
|
935 | + return (new self($dups))->filter(function($val) { |
|
936 | 936 | return count($val) > 1; |
937 | 937 | }); |
938 | 938 | } |
@@ -962,7 +962,7 @@ discard block |
||
962 | 962 | public function pairs($alt = false) |
963 | 963 | { |
964 | 964 | return new self(array_map( |
965 | - function ($key, $val) use ($alt) { |
|
965 | + function($key, $val) use ($alt) { |
|
966 | 966 | if ($alt) { |
967 | 967 | return [$key => $val]; |
968 | 968 | } |
@@ -1048,7 +1048,7 @@ discard block |
||
1048 | 1048 | if (false !== ($condRet = $this->if2DMapInternalMethod(__METHOD__))) { |
1049 | 1049 | return $condRet; |
1050 | 1050 | } |
1051 | - $strvals = $this->map(function ($val) { |
|
1051 | + $strvals = $this->map(function($val) { |
|
1052 | 1052 | return (string) $val; |
1053 | 1053 | }); |
1054 | 1054 | $this->assertNumericValues(); |
@@ -1171,9 +1171,9 @@ discard block |
||
1171 | 1171 | { |
1172 | 1172 | $this->assertIsTabular(); |
1173 | 1173 | |
1174 | - return $this->sort(function ($a, $b) use ($key, $cmp) { |
|
1174 | + return $this->sort(function($a, $b) use ($key, $cmp) { |
|
1175 | 1175 | if (!isset($a[$key]) || !isset($b[$key])) { |
1176 | - throw new RuntimeException('Cannot order collection by non-existant key: ' . $key); |
|
1176 | + throw new RuntimeException('Cannot order collection by non-existant key: '.$key); |
|
1177 | 1177 | } |
1178 | 1178 | if (is_null($cmp)) { |
1179 | 1179 | return strcasecmp($a[$key], $b[$key]); |
@@ -1207,7 +1207,7 @@ discard block |
||
1207 | 1207 | */ |
1208 | 1208 | public function is2D() |
1209 | 1209 | { |
1210 | - return !$this->contains(function ($val) { |
|
1210 | + return !$this->contains(function($val) { |
|
1211 | 1211 | return !is_array($val); |
1212 | 1212 | }); |
1213 | 1213 | } |
@@ -1226,7 +1226,7 @@ discard block |
||
1226 | 1226 | // look through each item in the collection and if an array, grab its keys |
1227 | 1227 | // and throw them in an array to be analyzed later... |
1228 | 1228 | $test = []; |
1229 | - $this->walk(function ($val, $key) use (&$test) { |
|
1229 | + $this->walk(function($val, $key) use (&$test) { |
|
1230 | 1230 | if (is_array($val)) { |
1231 | 1231 | $test[$key] = array_keys($val); |
1232 | 1232 | |
@@ -1298,7 +1298,7 @@ discard block |
||
1298 | 1298 | if (count($method) == 2) { |
1299 | 1299 | $method = $method[1]; |
1300 | 1300 | |
1301 | - return $this->map(function ($val) use ($method) { |
|
1301 | + return $this->map(function($val) use ($method) { |
|
1302 | 1302 | return (new self($val))->$method(); |
1303 | 1303 | }); |
1304 | 1304 | } |
@@ -1332,7 +1332,7 @@ discard block |
||
1332 | 1332 | |
1333 | 1333 | protected function assertNumericValues() |
1334 | 1334 | { |
1335 | - if ($this->contains(function ($val) { |
|
1335 | + if ($this->contains(function($val) { |
|
1336 | 1336 | return !is_numeric($val); |
1337 | 1337 | })) { |
1338 | 1338 | // can't average non-numeric data |
@@ -1348,6 +1348,6 @@ discard block |
||
1348 | 1348 | if (is_null($data) || is_array($data) || $data instanceof Iterator) { |
1349 | 1349 | return; |
1350 | 1350 | } |
1351 | - throw new InvalidArgumentException('Invalid type for collection data: ' . gettype($data)); |
|
1351 | + throw new InvalidArgumentException('Invalid type for collection data: '.gettype($data)); |
|
1352 | 1352 | } |
1353 | 1353 | } |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | public function lickHeader($delim, $eol) |
224 | 224 | { |
225 | 225 | $types = collect(); |
226 | - $buildTypes = function ($line, $line_no) use (&$types, $delim, $eol) { |
|
226 | + $buildTypes = function($line, $line_no) use (&$types, $delim, $eol) { |
|
227 | 227 | $line = str_replace(self::PLACEHOLDER_NEWLINE, $eol, $line); |
228 | - $getType = function ($field, $colpos) use (&$types, $line, $line_no, $delim) { |
|
228 | + $getType = function($field, $colpos) use (&$types, $line, $line_no, $delim) { |
|
229 | 229 | $field = str_replace(self::PLACEHOLDER_DELIM, $delim, $field); |
230 | 230 | // @todo Need a Collection::setTableField($x, $y) method |
231 | 231 | // See notes in green binder about refactoring Collection |
@@ -247,8 +247,8 @@ discard block |
||
247 | 247 | |
248 | 248 | $hasHeader = 0; |
249 | 249 | $possibleHeader = $types->shift(); |
250 | - $types->walk(function ($row) use (&$hasHeader, $possibleHeader) { |
|
251 | - $row->walk(function ($field_info, $col_no) use (&$hasHeader, $possibleHeader) { |
|
250 | + $types->walk(function($row) use (&$hasHeader, $possibleHeader) { |
|
251 | + $row->walk(function($field_info, $col_no) use (&$hasHeader, $possibleHeader) { |
|
252 | 252 | extract($field_info); |
253 | 253 | try { |
254 | 254 | $col = $possibleHeader->get($col_no, null, true); |
@@ -314,9 +314,9 @@ discard block |
||
314 | 314 | { |
315 | 315 | $str = $this->removeQuotedStrings($this->sample); |
316 | 316 | $eols = [ |
317 | - self::EOL_WINDOWS => "\r\n", // 0x0D - 0x0A - Windows, DOS OS/2 |
|
318 | - self::EOL_UNIX => "\n", // 0x0A - - Unix, OSX |
|
319 | - self::EOL_TRS80 => "\r", // 0x0D - - Apple ][, TRS80 |
|
317 | + self::EOL_WINDOWS => "\r\n", // 0x0D - 0x0A - Windows, DOS OS/2 |
|
318 | + self::EOL_UNIX => "\n", // 0x0A - - Unix, OSX |
|
319 | + self::EOL_TRS80 => "\r", // 0x0D - - Apple ][, TRS80 |
|
320 | 320 | ]; |
321 | 321 | |
322 | 322 | $curCount = 0; |
@@ -359,12 +359,12 @@ discard block |
||
359 | 359 | $patterns = []; |
360 | 360 | // delim can be anything but line breaks, quotes, alphanumeric, underscore, backslash, or any type of spaces |
361 | 361 | $antidelims = implode(["\r", "\n", "\w", preg_quote('"', '/'), preg_quote("'", '/'), preg_quote(chr(self::SPACE), '/')]); |
362 | - $delim = '(?P<delim>[^' . $antidelims . '])'; |
|
362 | + $delim = '(?P<delim>[^'.$antidelims.'])'; |
|
363 | 363 | $quote = '(?P<quoteChar>"|\'|`)'; // @todo I think MS Excel uses some strange encoding for fancy open/close quotes |
364 | - $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 |
|
365 | - $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 |
|
366 | - $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 |
|
367 | - $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 |
|
364 | + $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 |
|
365 | + $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 |
|
366 | + $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 |
|
367 | + $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 |
|
368 | 368 | foreach ($patterns as $pattern) { |
369 | 369 | // @todo I had to add the error suppression char here because it was |
370 | 370 | // causing undefined offset errors with certain data sets. strange... |
@@ -422,24 +422,24 @@ discard block |
||
422 | 422 | // each frequency (in 10 lines, "tab" occurred 5 times on 7 of those |
423 | 423 | // lines, 6 times on 2 lines, and 7 times on 1 line) |
424 | 424 | collect(explode($eol, $this->removeQuotedStrings($this->sample))) |
425 | - ->walk(function ($line, $line_no) use (&$frequencies) { |
|
425 | + ->walk(function($line, $line_no) use (&$frequencies) { |
|
426 | 426 | collect(str_split($line)) |
427 | - ->filter(function ($c) { |
|
427 | + ->filter(function($c) { |
|
428 | 428 | return collect($this->delims)->contains($c); |
429 | 429 | }) |
430 | 430 | ->frequency() |
431 | 431 | ->sort() |
432 | 432 | ->reverse() |
433 | - ->walk(function ($count, $char) use (&$frequencies, $line_no) { |
|
433 | + ->walk(function($count, $char) use (&$frequencies, $line_no) { |
|
434 | 434 | $frequencies[$char][$line_no] = $count; |
435 | 435 | }); |
436 | 436 | }) |
437 | 437 | // the above only finds frequencies for characters if they exist in |
438 | 438 | // a given line. This will go back and fill in zeroes where a char |
439 | 439 | // didn't occur at all in a given line (needed to determine mode) |
440 | - ->walk(function ($line, $line_no) use (&$frequencies) { |
|
440 | + ->walk(function($line, $line_no) use (&$frequencies) { |
|
441 | 441 | collect($frequencies) |
442 | - ->walk(function ($counts, $char) use ($line_no, &$frequencies) { |
|
442 | + ->walk(function($counts, $char) use ($line_no, &$frequencies) { |
|
443 | 443 | if (!isset($frequencies[$char][$line_no])) { |
444 | 444 | $frequencies[$char][$line_no] = 0; |
445 | 445 | } |
@@ -450,8 +450,8 @@ discard block |
||
450 | 450 | // of times a char (possible delim) will occur on each line... |
451 | 451 | $freqs = collect($frequencies); |
452 | 452 | $modes = $freqs->mode(); |
453 | - $freqs->walk(function ($f, $chr) use ($modes, &$consistencies) { |
|
454 | - collect($f)->walk(function ($num) use ($modes, $chr, &$consistencies) { |
|
453 | + $freqs->walk(function($f, $chr) use ($modes, &$consistencies) { |
|
454 | + collect($f)->walk(function($num) use ($modes, $chr, &$consistencies) { |
|
455 | 455 | if ($expected = $modes->get($chr)) { |
456 | 456 | if ($num == $expected) { |
457 | 457 | // met the goal, yay! |
@@ -544,19 +544,19 @@ discard block |
||
544 | 544 | // @todo Write a method that does this... |
545 | 545 | $lines = collect(explode($eol, $this->removeQuotedStrings($this->sample))); |
546 | 546 | |
547 | - return $delims[collect($delims)->map(function ($delim) use (&$distrib, $lines) { |
|
547 | + return $delims[collect($delims)->map(function($delim) use (&$distrib, $lines) { |
|
548 | 548 | $linedist = collect(); |
549 | - $lines->walk(function ($line, $line_no) use (&$linedist, $delim) { |
|
549 | + $lines->walk(function($line, $line_no) use (&$linedist, $delim) { |
|
550 | 550 | if (!strlen($line)) { |
551 | 551 | return; |
552 | 552 | } |
553 | 553 | $sectstot = 10; |
554 | 554 | $sectlen = (int) (strlen($line) / $sectstot); |
555 | 555 | $sections = collect(str_split($line, $sectlen)) |
556 | - ->map(function ($section) use ($delim) { |
|
556 | + ->map(function($section) use ($delim) { |
|
557 | 557 | return substr_count($section, $delim); |
558 | 558 | }) |
559 | - ->filter(function ($count) { |
|
559 | + ->filter(function($count) { |
|
560 | 560 | return (bool) $count; |
561 | 561 | }); |
562 | 562 | if (is_numeric($count = $sections->count())) { |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | }); |
566 | 566 | |
567 | 567 | return $linedist; |
568 | - })->map(function ($dists) { |
|
568 | + })->map(function($dists) { |
|
569 | 569 | return $dists->average(); |
570 | 570 | })->sort() |
571 | 571 | ->reverse() |
@@ -615,9 +615,9 @@ discard block |
||
615 | 615 | |
616 | 616 | // walk through each line from the data sample to determine which fields |
617 | 617 | // are quoted and which aren't |
618 | - $qsFunc = function ($line) use (&$quoting_styles, &$freq, $eol, $delim) { |
|
618 | + $qsFunc = function($line) use (&$quoting_styles, &$freq, $eol, $delim) { |
|
619 | 619 | $line = str_replace(self::PLACEHOLDER_NEWLINE, $eol, $line); |
620 | - $qnqaFunc = function ($field) use (&$quoting_styles, &$freq, $delim) { |
|
620 | + $qnqaFunc = function($field) use (&$quoting_styles, &$freq, $delim) { |
|
621 | 621 | $field = str_replace(self::PLACEHOLDER_DELIM, $delim, $field); |
622 | 622 | if ($this->isQuoted($field)) { |
623 | 623 | $field = $this->unQuote($field); |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | $lines->walk($qsFunc->bindTo($this)); |
639 | 639 | |
640 | 640 | $types = $freq->get('quoted')->unique(); |
641 | - $quoting_styles = $quoting_styles->filter(function ($val) { |
|
641 | + $quoting_styles = $quoting_styles->filter(function($val) { |
|
642 | 642 | return (bool) $val; |
643 | 643 | }); |
644 | 644 | // if quoting_styles still has QUOTE_ALL or QUOTE_NONE, then return |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | if ($types->contains(self::DATA_NONNUMERIC)) { |
659 | 659 | // allow for a SMALL amount of error here |
660 | 660 | $counts = collect([self::DATA_SPECIAL => 0, self::DATA_NONNUMERIC => 0]); |
661 | - $freq->get('quoted')->walk(function ($type) use (&$counts) { |
|
661 | + $freq->get('quoted')->walk(function($type) use (&$counts) { |
|
662 | 662 | $counts->increment($type); |
663 | 663 | }); |
664 | 664 | // @todo is all this even necessary? seems unnecessary to me... |
@@ -751,7 +751,7 @@ discard block |
||
751 | 751 | */ |
752 | 752 | protected function replaceQuotedSpecialChars($data, $delim) |
753 | 753 | { |
754 | - return preg_replace_callback('/([\'"])(.*)\1/imsU', function ($matches) use ($delim) { |
|
754 | + return preg_replace_callback('/([\'"])(.*)\1/imsU', function($matches) use ($delim) { |
|
755 | 755 | $ret = preg_replace("/([\r\n])/", self::PLACEHOLDER_NEWLINE, $matches[0]); |
756 | 756 | $ret = str_replace($delim, self::PLACEHOLDER_DELIM, $ret); |
757 | 757 | |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | $day = '[0-3]?[0-9]'; |
792 | 792 | $sep = '[\/\.\-]?'; |
793 | 793 | $time = '([0-2]?[0-9](:[0-5][0-9]){1,2}(am|pm)?|[01]?[0-9](am|pm))'; |
794 | - $date = '(' . $month . $sep . $day . $sep . $year . '|' . $day . $sep . $month . $sep . $year . '|' . $year . $sep . $month . $sep . $day . ')'; |
|
794 | + $date = '('.$month.$sep.$day.$sep.$year.'|'.$day.$sep.$month.$sep.$year.'|'.$year.$sep.$month.$sep.$day.')'; |
|
795 | 795 | $dt = new DateTime($data); |
796 | 796 | $dt->setTime(0, 0, 0); |
797 | 797 | $now = new DateTime(); |