@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | * also optionally throw an OutOfBoundsException if no value is found. |
| 281 | 281 | * |
| 282 | 282 | * @param mixed $index The index of the data you want to get |
| 283 | - * @param mixed $default The default value to return if none available |
|
| 283 | + * @param null|integer $default The default value to return if none available |
|
| 284 | 284 | * @param bool $throw True if you want an exception to be thrown if no data found at $index |
| 285 | 285 | * @throws OutOfBoundsException If $throw is true and $index isn't found |
| 286 | 286 | * @return mixed The data found at $index or failing that, the $default |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | * Returns a new collection with $items added. |
| 546 | 546 | * |
| 547 | 547 | * @param array $items Any number of arguments will be pushed onto the |
| 548 | - * @return mixed The first item in this collection |
|
| 548 | + * @return AbstractCollection The first item in this collection |
|
| 549 | 549 | */ |
| 550 | 550 | public function push(...$items) |
| 551 | 551 | { |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | * |
| 559 | 559 | * Returns a new collection with $items added. |
| 560 | 560 | * |
| 561 | - * @return mixed The first item in this collection |
|
| 561 | + * @return AbstractCollection The first item in this collection |
|
| 562 | 562 | */ |
| 563 | 563 | public function unshift(...$items) |
| 564 | 564 | { |
@@ -697,7 +697,7 @@ discard block |
||
| 697 | 697 | /** |
| 698 | 698 | * Returns collection in reverse order. |
| 699 | 699 | * |
| 700 | - * @param null $preserveKeys True if you want to preserve collection's keys |
|
| 700 | + * @param boolean $preserveKeys True if you want to preserve collection's keys |
|
| 701 | 701 | * @return AbstractCollection This collection in reverse order. |
| 702 | 702 | */ |
| 703 | 703 | public function reverse($preserveKeys = null) |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * |
| 166 | 166 | * @return mixed |
| 167 | 167 | */ |
| 168 | - public function current () |
|
| 168 | + public function current() |
|
| 169 | 169 | { |
| 170 | 170 | return current($this->data); |
| 171 | 171 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * |
| 178 | 178 | * @return mixed |
| 179 | 179 | */ |
| 180 | - public function key () |
|
| 180 | + public function key() |
|
| 181 | 181 | { |
| 182 | 182 | return key($this->data); |
| 183 | 183 | } |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * |
| 192 | 192 | * @return mixed |
| 193 | 193 | */ |
| 194 | - public function next () |
|
| 194 | + public function next() |
|
| 195 | 195 | { |
| 196 | 196 | $next = next($this->data); |
| 197 | 197 | $key = key($this->data); |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | * |
| 211 | 211 | * @return mixed |
| 212 | 212 | */ |
| 213 | - public function rewind () |
|
| 213 | + public function rewind() |
|
| 214 | 214 | { |
| 215 | 215 | $this->isValid = true; |
| 216 | 216 | return reset($this->data); |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * |
| 224 | 224 | * @return bool True if internal pointer isn't past the end |
| 225 | 225 | */ |
| 226 | - public function valid () |
|
| 226 | + public function valid() |
|
| 227 | 227 | { |
| 228 | 228 | return $this->isValid; |
| 229 | 229 | } |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | return $this->data[$index]; |
| 293 | 293 | } |
| 294 | 294 | if ($throw) { |
| 295 | - throw new OutOfBoundsException(__CLASS__ . " could not find value at index " . $index); |
|
| 295 | + throw new OutOfBoundsException(__CLASS__." could not find value at index ".$index); |
|
| 296 | 296 | } |
| 297 | 297 | return $default; |
| 298 | 298 | } |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | unset($this->data[$index]); |
| 333 | 333 | } else { |
| 334 | 334 | if ($throw) { |
| 335 | - throw new OutOfBoundsException('No value found at given index: ' . $index); |
|
| 335 | + throw new OutOfBoundsException('No value found at given index: '.$index); |
|
| 336 | 336 | } |
| 337 | 337 | } |
| 338 | 338 | |
@@ -621,7 +621,7 @@ discard block |
||
| 621 | 621 | public function pairs() |
| 622 | 622 | { |
| 623 | 623 | return static::factory(array_map( |
| 624 | - function ($key, $val) { |
|
| 624 | + function($key, $val) { |
|
| 625 | 625 | return [$key, $val]; |
| 626 | 626 | }, |
| 627 | 627 | array_keys($this->data), |
@@ -766,7 +766,7 @@ discard block |
||
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | if (method_exists($val, '__toString')) { |
| 769 | - $val = (string)$val; |
|
| 769 | + $val = (string) $val; |
|
| 770 | 770 | } else { |
| 771 | 771 | $val = spl_object_hash($val); |
| 772 | 772 | } |
@@ -815,7 +815,7 @@ discard block |
||
| 815 | 815 | protected function assertCorrectInputDataType($data) |
| 816 | 816 | { |
| 817 | 817 | if (!$this->isConsistentDataStructure($data)) { |
| 818 | - throw new InvalidArgumentException(__CLASS__ . ' expected traversable data, got: ' . gettype ($data)); |
|
| 818 | + throw new InvalidArgumentException(__CLASS__.' expected traversable data, got: '.gettype($data)); |
|
| 819 | 819 | } |
| 820 | 820 | } |
| 821 | 821 | |
@@ -859,7 +859,7 @@ discard block |
||
| 859 | 859 | } |
| 860 | 860 | } |
| 861 | 861 | // if row contains an array it isn't tabular |
| 862 | - if (array_reduce($row, function($carry, $item){ |
|
| 862 | + if (array_reduce($row, function($carry, $item) { |
|
| 863 | 863 | return is_array($item) && $carry; |
| 864 | 864 | }, true)) { |
| 865 | 865 | return false; |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | return static::factory($values); |
| 65 | 65 | } |
| 66 | 66 | if ($throw) { |
| 67 | - throw new OutOfBoundsException(__CLASS__ . " could not find column: " . $column); |
|
| 67 | + throw new OutOfBoundsException(__CLASS__." could not find column: ".$column); |
|
| 68 | 68 | } |
| 69 | 69 | return false; |
| 70 | 70 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | return static::factory($this->data[$index]); |
| 101 | 101 | } |
| 102 | 102 | if ($throw) { |
| 103 | - throw new OutOfBoundsException(__CLASS__ . " could not find row: " . $offset); |
|
| 103 | + throw new OutOfBoundsException(__CLASS__." could not find row: ".$offset); |
|
| 104 | 104 | } |
| 105 | 105 | return false; |
| 106 | 106 | } |
@@ -176,6 +176,6 @@ discard block |
||
| 176 | 176 | return call_user_func_array([$column, $method], $args); |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | - throw new BadMethodCallException("Method does not exist: " . __CLASS__ . "::{$method}()"); |
|
| 179 | + throw new BadMethodCallException("Method does not exist: ".__CLASS__."::{$method}()"); |
|
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | \ No newline at end of file |
@@ -232,11 +232,11 @@ discard block |
||
| 232 | 232 | $types = new TabularCollection(); |
| 233 | 233 | |
| 234 | 234 | // callback to build the aforementioned collection |
| 235 | - $buildTypes = function ($line, $line_no) use ($types, $delim, $eol) { |
|
| 235 | + $buildTypes = function($line, $line_no) use ($types, $delim, $eol) { |
|
| 236 | 236 | |
| 237 | 237 | if ($line_no > 2) return; |
| 238 | 238 | $line = str_replace(self::PLACEHOLDER_NEWLINE, $eol, $line); |
| 239 | - $getType = function ($field, $colpos) use ($types, $line, $line_no, $delim) { |
|
| 239 | + $getType = function($field, $colpos) use ($types, $line, $line_no, $delim) { |
|
| 240 | 240 | $field = str_replace(self::PLACEHOLDER_DELIM, $delim, $field); |
| 241 | 241 | $fieldMeta = [ |
| 242 | 242 | "value" => $field, |
@@ -264,8 +264,8 @@ discard block |
||
| 264 | 264 | |
| 265 | 265 | $hasHeader = new NumericCollection(); |
| 266 | 266 | $possibleHeader = collect($types->shift()); |
| 267 | - $types->walk(function (AbstractCollection $row) use ($hasHeader, $possibleHeader) { |
|
| 268 | - $row->walk(function (AbstractCollection $fieldMeta, $col_no) use ($hasHeader, $possibleHeader) { |
|
| 267 | + $types->walk(function(AbstractCollection $row) use ($hasHeader, $possibleHeader) { |
|
| 268 | + $row->walk(function(AbstractCollection $fieldMeta, $col_no) use ($hasHeader, $possibleHeader) { |
|
| 269 | 269 | try { |
| 270 | 270 | $col = collect($possibleHeader->get($col_no, null, true)); |
| 271 | 271 | if ($fieldMeta->get('type') == self::TYPE_STRING) { |
@@ -329,9 +329,9 @@ discard block |
||
| 329 | 329 | { |
| 330 | 330 | $str = $this->removeQuotedStrings($this->sample); |
| 331 | 331 | $eols = [ |
| 332 | - self::EOL_WINDOWS => "\r\n", // 0x0D - 0x0A - Windows, DOS OS/2 |
|
| 333 | - self::EOL_UNIX => "\n", // 0x0A - - Unix, OSX |
|
| 334 | - self::EOL_TRS80 => "\r", // 0x0D - - Apple ][, TRS80 |
|
| 332 | + self::EOL_WINDOWS => "\r\n", // 0x0D - 0x0A - Windows, DOS OS/2 |
|
| 333 | + self::EOL_UNIX => "\n", // 0x0A - - Unix, OSX |
|
| 334 | + self::EOL_TRS80 => "\r", // 0x0D - - Apple ][, TRS80 |
|
| 335 | 335 | ]; |
| 336 | 336 | |
| 337 | 337 | $curCount = 0; |
@@ -374,12 +374,12 @@ discard block |
||
| 374 | 374 | $patterns = []; |
| 375 | 375 | // delim can be anything but line breaks, quotes, alphanumeric, underscore, backslash, or any type of spaces |
| 376 | 376 | $antidelims = implode(["\r", "\n", "\w", preg_quote('"', '/'), preg_quote("'", '/'), preg_quote(chr(self::SPACE), '/')]); |
| 377 | - $delim = '(?P<delim>[^' . $antidelims . '])'; |
|
| 377 | + $delim = '(?P<delim>[^'.$antidelims.'])'; |
|
| 378 | 378 | $quote = '(?P<quoteChar>"|\'|`)'; // @todo I think MS Excel uses some strange encoding for fancy open/close quotes |
| 379 | - $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 |
|
| 380 | - $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 |
|
| 381 | - $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 |
|
| 382 | - $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 |
|
| 379 | + $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 |
|
| 380 | + $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 |
|
| 381 | + $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 |
|
| 382 | + $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 |
|
| 383 | 383 | foreach ($patterns as $pattern) { |
| 384 | 384 | // @todo I had to add the error suppression char here because it was |
| 385 | 385 | // causing undefined offset errors with certain data sets. strange... |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | 390 | if ($matches) { |
| 391 | - $qcad = array_intersect_key($matches, array_flip(['quoteChar','delim'])); |
|
| 391 | + $qcad = array_intersect_key($matches, array_flip(['quoteChar', 'delim'])); |
|
| 392 | 392 | if (!empty($matches['quoteChar']) && !empty($matches['delim'])) { |
| 393 | 393 | try { |
| 394 | 394 | return [ |
@@ -430,15 +430,15 @@ discard block |
||
| 430 | 430 | // each frequency (in 10 lines, "tab" occurred 5 times on 7 of those |
| 431 | 431 | // lines, 6 times on 2 lines, and 7 times on 1 line) |
| 432 | 432 | collect(explode($eol, $this->removeQuotedStrings($this->sample))) |
| 433 | - ->walk(function ($line, $line_no) use ($frequencies) { |
|
| 433 | + ->walk(function($line, $line_no) use ($frequencies) { |
|
| 434 | 434 | collect(str_split($line)) |
| 435 | - ->filter(function ($c) { |
|
| 435 | + ->filter(function($c) { |
|
| 436 | 436 | return collect($this->delims)->contains($c); |
| 437 | 437 | }) |
| 438 | 438 | ->frequency() |
| 439 | 439 | ->sort() |
| 440 | 440 | ->reverse() |
| 441 | - ->walk(function ($count, $char) use ($frequencies, $line_no) { |
|
| 441 | + ->walk(function($count, $char) use ($frequencies, $line_no) { |
|
| 442 | 442 | try { |
| 443 | 443 | $char_counts = $frequencies->get($char, null, true); |
| 444 | 444 | } catch (OutOfBoundsException $e) { |
@@ -451,8 +451,8 @@ discard block |
||
| 451 | 451 | // the above only finds frequencies for characters if they exist in |
| 452 | 452 | // a given line. This will go back and fill in zeroes where a char |
| 453 | 453 | // didn't occur at all in a given line (needed to determine mode) |
| 454 | - ->walk(function ($line, $line_no) use ($frequencies) { |
|
| 455 | - $frequencies->walk(function ($counts, $char) use ($line_no, $frequencies) { |
|
| 454 | + ->walk(function($line, $line_no) use ($frequencies) { |
|
| 455 | + $frequencies->walk(function($counts, $char) use ($line_no, $frequencies) { |
|
| 456 | 456 | try { |
| 457 | 457 | $char_counts = $frequencies->get($char, null, true); |
| 458 | 458 | } catch (OutOfBoundsException $e) { |
@@ -472,8 +472,8 @@ discard block |
||
| 472 | 472 | foreach ($freqs as $char => $freq) { |
| 473 | 473 | $modes->set($char, collect($freq)->mode()); |
| 474 | 474 | } |
| 475 | - $freqs->walk(function ($f, $chr) use ($modes, $consistencies) { |
|
| 476 | - collect($f)->walk(function ($num) use ($modes, $chr, $consistencies) { |
|
| 475 | + $freqs->walk(function($f, $chr) use ($modes, $consistencies) { |
|
| 476 | + collect($f)->walk(function($num) use ($modes, $chr, $consistencies) { |
|
| 477 | 477 | if ($expected = $modes->get($chr)) { |
| 478 | 478 | if ($num == $expected) { |
| 479 | 479 | // met the goal, yay! |
@@ -565,19 +565,19 @@ discard block |
||
| 565 | 565 | // @todo Write a method that does this... |
| 566 | 566 | $lines = collect(explode($eol, $this->removeQuotedStrings($this->sample))); |
| 567 | 567 | |
| 568 | - return $delims[collect($delims)->map(function ($delim) use (&$distrib, $lines) { |
|
| 568 | + return $delims[collect($delims)->map(function($delim) use (&$distrib, $lines) { |
|
| 569 | 569 | $linedist = collect(); |
| 570 | - $lines->walk(function ($line, $line_no) use (&$linedist, $delim) { |
|
| 570 | + $lines->walk(function($line, $line_no) use (&$linedist, $delim) { |
|
| 571 | 571 | if (!strlen($line)) { |
| 572 | 572 | return; |
| 573 | 573 | } |
| 574 | 574 | $sectstot = 10; |
| 575 | 575 | $sectlen = (int) (strlen($line) / $sectstot); |
| 576 | 576 | $sections = collect(str_split($line, $sectlen)) |
| 577 | - ->map(function ($section) use ($delim) { |
|
| 577 | + ->map(function($section) use ($delim) { |
|
| 578 | 578 | return substr_count($section, $delim); |
| 579 | 579 | }) |
| 580 | - ->filter(function ($count) { |
|
| 580 | + ->filter(function($count) { |
|
| 581 | 581 | return (bool) $count; |
| 582 | 582 | }); |
| 583 | 583 | if (is_numeric($count = $sections->count())) { |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | }); |
| 587 | 587 | |
| 588 | 588 | return $linedist; |
| 589 | - })->map(function ($dists) { |
|
| 589 | + })->map(function($dists) { |
|
| 590 | 590 | return $dists->average(); |
| 591 | 591 | })->sort() |
| 592 | 592 | ->reverse() |
@@ -636,9 +636,9 @@ discard block |
||
| 636 | 636 | |
| 637 | 637 | // walk through each line from the data sample to determine which fields |
| 638 | 638 | // are quoted and which aren't |
| 639 | - $qsFunc = function ($line) use (&$quoting_styles, &$freq, $eol, $delim) { |
|
| 639 | + $qsFunc = function($line) use (&$quoting_styles, &$freq, $eol, $delim) { |
|
| 640 | 640 | $line = str_replace(self::PLACEHOLDER_NEWLINE, $eol, $line); |
| 641 | - $qnqaFunc = function ($field) use (&$quoting_styles, &$freq, $delim) { |
|
| 641 | + $qnqaFunc = function($field) use (&$quoting_styles, &$freq, $delim) { |
|
| 642 | 642 | $field = str_replace(self::PLACEHOLDER_DELIM, $delim, $field); |
| 643 | 643 | if ($this->isQuoted($field)) { |
| 644 | 644 | $field = $this->unQuote($field); |
@@ -659,7 +659,7 @@ discard block |
||
| 659 | 659 | $lines->walk($qsFunc->bindTo($this)); |
| 660 | 660 | |
| 661 | 661 | $types = $freq->get('quoted')->unique(); |
| 662 | - $quoting_styles = $quoting_styles->filter(function ($val) { |
|
| 662 | + $quoting_styles = $quoting_styles->filter(function($val) { |
|
| 663 | 663 | return (bool) $val; |
| 664 | 664 | }); |
| 665 | 665 | // if quoting_styles still has QUOTE_ALL or QUOTE_NONE, then return |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | if ($types->contains(self::DATA_NONNUMERIC)) { |
| 680 | 680 | // allow for a SMALL amount of error here |
| 681 | 681 | $counts = collect([self::DATA_SPECIAL => 0, self::DATA_NONNUMERIC => 0]); |
| 682 | - $freq->get('quoted')->walk(function ($type) use (&$counts) { |
|
| 682 | + $freq->get('quoted')->walk(function($type) use (&$counts) { |
|
| 683 | 683 | $counts->increment($type); |
| 684 | 684 | }); |
| 685 | 685 | // @todo is all this even necessary? seems unnecessary to me... |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | */ |
| 773 | 773 | protected function replaceQuotedSpecialChars($data, $delim) |
| 774 | 774 | { |
| 775 | - return preg_replace_callback('/([\'"])(.*)\1/imsU', function ($matches) use ($delim) { |
|
| 775 | + return preg_replace_callback('/([\'"])(.*)\1/imsU', function($matches) use ($delim) { |
|
| 776 | 776 | $ret = preg_replace("/([\r\n])/", self::PLACEHOLDER_NEWLINE, $matches[0]); |
| 777 | 777 | $ret = str_replace($delim, self::PLACEHOLDER_DELIM, $ret); |
| 778 | 778 | |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | $day = '[0-3]?[0-9]'; |
| 813 | 813 | $sep = '[\/\.\-]?'; |
| 814 | 814 | $time = '([0-2]?[0-9](:[0-5][0-9]){1,2}(am|pm)?|[01]?[0-9](am|pm))'; |
| 815 | - $date = '(' . $month . $sep . $day . $sep . $year . '|' . $day . $sep . $month . $sep . $year . '|' . $year . $sep . $month . $sep . $day . ')'; |
|
| 815 | + $date = '('.$month.$sep.$day.$sep.$year.'|'.$day.$sep.$month.$sep.$year.'|'.$year.$sep.$month.$sep.$day.')'; |
|
| 816 | 816 | $dt = new DateTime($data); |
| 817 | 817 | $dt->setTime(0, 0, 0); |
| 818 | 818 | $now = new DateTime(); |