@@ -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) |
@@ -242,7 +242,7 @@ |
||
| 242 | 242 | } elseif ($fields instanceof Iterator) { |
| 243 | 243 | $fields = iterator_to_array($fields); |
| 244 | 244 | } else { |
| 245 | - throw new InvalidArgumentException(__CLASS__ . ' requires an array, got: ' . gettype($fields)); |
|
| 245 | + throw new InvalidArgumentException(__CLASS__.' requires an array, got: '.gettype($fields)); |
|
| 246 | 246 | } |
| 247 | 247 | } |
| 248 | 248 | $this->fields = collect(array_values($fields)); |
@@ -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 | /** |
@@ -329,7 +329,7 @@ |
||
| 329 | 329 | * @param string $str The string to unescape |
| 330 | 330 | * @param string $esc The escape character used |
| 331 | 331 | * @param string $quo The quote character used |
| 332 | - * @return mixed The string with characters unescaped |
|
| 332 | + * @return string The string with characters unescaped |
|
| 333 | 333 | * @todo This actually shouldn't even be necessary. Characters should be read |
| 334 | 334 | * in one at a time and a quote that follows another should just be ignored |
| 335 | 335 | * deeming this unnecessary. |
@@ -14,11 +14,9 @@ |
||
| 14 | 14 | namespace CSVelte; |
| 15 | 15 | |
| 16 | 16 | use CSVelte\Contract\Streamable; |
| 17 | - |
|
| 18 | 17 | use CSVelte\Table\Row; |
| 19 | 18 | use CSVelte\Table\HeaderRow; |
| 20 | 19 | use CSVelte\Reader\FilteredIterator as FilteredReader; |
| 21 | - |
|
| 22 | 20 | use CSVelte\Exception\EndOfFileException; |
| 23 | 21 | |
| 24 | 22 | use function |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 255 | public function toArray() |
| 256 | 256 | { |
| 257 | - return array_map(function ($row) { |
|
| 257 | + return array_map(function($row) { |
|
| 258 | 258 | return $row->toArray(); |
| 259 | 259 | }, iterator_to_array($this)); |
| 260 | 260 | } |
@@ -387,12 +387,12 @@ discard block |
||
| 387 | 387 | if (!isset($i)) { |
| 388 | 388 | $i = 0; |
| 389 | 389 | } |
| 390 | - $c = $line[$i++]; |
|
| 390 | + $c = $line[$i++]; |
|
| 391 | 391 | if ($this->escape) { |
| 392 | 392 | $this->escape = false; |
| 393 | 393 | continue; |
| 394 | 394 | } |
| 395 | - $this->escape = ($c == $escapeChar); |
|
| 395 | + $this->escape = ($c == $escapeChar); |
|
| 396 | 396 | if ($c == $quoteChar) { |
| 397 | 397 | $this->open = !$this->open; |
| 398 | 398 | } |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | */ |
| 429 | 429 | protected function replaceQuotedSpecialChars($data, $delim, $quo, $eol) |
| 430 | 430 | { |
| 431 | - return preg_replace_callback('/([' . preg_quote($quo, '/') . '])(.*)\1/imsU', function ($matches) use ($delim, $eol) { |
|
| 431 | + return preg_replace_callback('/(['.preg_quote($quo, '/').'])(.*)\1/imsU', function($matches) use ($delim, $eol) { |
|
| 432 | 432 | $ret = str_replace($eol, self::PLACEHOLDER_NEWLINE, $matches[0]); |
| 433 | 433 | $ret = str_replace($delim, self::PLACEHOLDER_DELIM, $ret); |
| 434 | 434 | |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | protected function undoReplaceQuotedSpecialChars($data, $delim, $eol) |
| 454 | 454 | { |
| 455 | 455 | $replacements = [self::PLACEHOLDER_DELIM => $delim, self::PLACEHOLDER_NEWLINE => $eol]; |
| 456 | - if (array_walk($replacements, function ($replacement, $placeholder) use (&$data) { |
|
| 456 | + if (array_walk($replacements, function($replacement, $placeholder) use (&$data) { |
|
| 457 | 457 | $data = str_replace($placeholder, $replacement, $data); |
| 458 | 458 | })) { |
| 459 | 459 | return $data; |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | */ |
| 498 | 498 | protected function unEscape($str, $esc, $quo) |
| 499 | 499 | { |
| 500 | - return str_replace($esc . $quo, $quo, $str); |
|
| 500 | + return str_replace($esc.$quo, $quo, $str); |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | /** |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | $columns = explode($f->delimiter, $replaced); |
| 517 | 517 | $that = $this; |
| 518 | 518 | |
| 519 | - return array_map(function ($val) use ($that, $f) { |
|
| 519 | + return array_map(function($val) use ($that, $f) { |
|
| 520 | 520 | $undone = $that->undoReplaceQuotedSpecialChars($val, $f->delimiter, $f->lineTerminator); |
| 521 | 521 | |
| 522 | 522 | return $this->unQuote($undone); |
@@ -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 | } |
@@ -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 | * |
@@ -40,7 +40,7 @@ |
||
| 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 | /** |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | * Returns a new collection with $items added. |
| 441 | 441 | * |
| 442 | 442 | * @param array $items Any number of arguments will be pushed onto the |
| 443 | - * @return mixed The first item in this collection |
|
| 443 | + * @return Collection The first item in this collection |
|
| 444 | 444 | */ |
| 445 | 445 | public function push(...$items) |
| 446 | 446 | { |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | * |
| 454 | 454 | * Returns a new collection with $items added. |
| 455 | 455 | * |
| 456 | - * @return mixed The first item in this collection |
|
| 456 | + * @return Collection The first item in this collection |
|
| 457 | 457 | */ |
| 458 | 458 | public function unshift(...$items) |
| 459 | 459 | { |
@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | /** |
| 593 | 593 | * Returns collection in reverse order. |
| 594 | 594 | * |
| 595 | - * @param null $preserveKeys True if you want to preserve collection's keys |
|
| 595 | + * @param boolean $preserveKeys True if you want to preserve collection's keys |
|
| 596 | 596 | * @return Collection This collection in reverse order. |
| 597 | 597 | */ |
| 598 | 598 | public function reverse($preserveKeys = null) |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | * |
| 164 | 164 | * @return mixed |
| 165 | 165 | */ |
| 166 | - public function current () |
|
| 166 | + public function current() |
|
| 167 | 167 | { |
| 168 | 168 | return current($this->data); |
| 169 | 169 | } |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @return mixed |
| 177 | 177 | */ |
| 178 | - public function key () |
|
| 178 | + public function key() |
|
| 179 | 179 | { |
| 180 | 180 | return key($this->data); |
| 181 | 181 | } |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * |
| 190 | 190 | * @return mixed |
| 191 | 191 | */ |
| 192 | - public function next () |
|
| 192 | + public function next() |
|
| 193 | 193 | { |
| 194 | 194 | $next = next($this->data); |
| 195 | 195 | $key = key($this->data); |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * |
| 209 | 209 | * @return mixed |
| 210 | 210 | */ |
| 211 | - public function rewind () |
|
| 211 | + public function rewind() |
|
| 212 | 212 | { |
| 213 | 213 | $this->isValid = true; |
| 214 | 214 | return reset($this->data); |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * @return bool True if internal pointer isn't past the end |
| 223 | 223 | */ |
| 224 | - public function valid () |
|
| 224 | + public function valid() |
|
| 225 | 225 | { |
| 226 | 226 | return $this->isValid; |
| 227 | 227 | } |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | return $this->data[$index]; |
| 281 | 281 | } |
| 282 | 282 | if ($throw) { |
| 283 | - throw new OutOfBoundsException(__CLASS__ . " could not find value at index " . $index); |
|
| 283 | + throw new OutOfBoundsException(__CLASS__." could not find value at index ".$index); |
|
| 284 | 284 | } |
| 285 | 285 | return $default; |
| 286 | 286 | } |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | unset($this->data[$index]); |
| 318 | 318 | } else { |
| 319 | 319 | if ($throw) { |
| 320 | - throw new OutOfBoundsException('No value found at given index: ' . $index); |
|
| 320 | + throw new OutOfBoundsException('No value found at given index: '.$index); |
|
| 321 | 321 | } |
| 322 | 322 | } |
| 323 | 323 | |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | public function pairs() |
| 517 | 517 | { |
| 518 | 518 | return static::factory(array_map( |
| 519 | - function ($key, $val) { |
|
| 519 | + function($key, $val) { |
|
| 520 | 520 | return [$key, $val]; |
| 521 | 521 | }, |
| 522 | 522 | array_keys($this->data), |
@@ -661,7 +661,7 @@ discard block |
||
| 661 | 661 | protected function assertCorrectInputDataType($data) |
| 662 | 662 | { |
| 663 | 663 | if (!$this->isConsistentDataStructure($data)) { |
| 664 | - throw new InvalidArgumentException(__CLASS__ . ' expected traversable data, got: ' . gettype ($data)); |
|
| 664 | + throw new InvalidArgumentException(__CLASS__.' expected traversable data, got: '.gettype($data)); |
|
| 665 | 665 | } |
| 666 | 666 | } |
| 667 | 667 | |
@@ -705,7 +705,7 @@ discard block |
||
| 705 | 705 | } |
| 706 | 706 | } |
| 707 | 707 | // if row contains an array it isn't tabular |
| 708 | - if (array_reduce($row, function($carry, $item){ |
|
| 708 | + if (array_reduce($row, function($carry, $item) { |
|
| 709 | 709 | return is_array($item) && $carry; |
| 710 | 710 | }, true)) { |
| 711 | 711 | return false; |
@@ -25,9 +25,7 @@ |
||
| 25 | 25 | use CSVelte\IO\IteratorStream; |
| 26 | 26 | use CSVelte\IO\Stream; |
| 27 | 27 | use CSVelte\IO\StreamResource; |
| 28 | -use CSVelte\Collection\AbstractCollection; |
|
| 29 | 28 | use InvalidArgumentException; |
| 30 | - |
|
| 31 | 29 | use Iterator; |
| 32 | 30 | |
| 33 | 31 | /** |
@@ -692,7 +692,7 @@ |
||
| 692 | 692 | * |
| 693 | 693 | * @param string $data The data to check |
| 694 | 694 | * |
| 695 | - * @return bool Whether the data is quoted or not |
|
| 695 | + * @return integer Whether the data is quoted or not |
|
| 696 | 696 | */ |
| 697 | 697 | protected function isQuoted($data) |
| 698 | 698 | { |
@@ -19,7 +19,6 @@ |
||
| 19 | 19 | use CSVelte\Contract\Readable; |
| 20 | 20 | use CSVelte\Contract\Writable; |
| 21 | 21 | use CSVelte\Contract\Seekable; |
| 22 | - |
|
| 23 | 22 | use CSVelte\Exception\NotYetImplementedException; |
| 24 | 23 | |
| 25 | 24 | /** |
@@ -484,22 +484,22 @@ discard block |
||
| 484 | 484 | // at least the same general area. Use the delimiter that is the most |
| 485 | 485 | // consistent in that way... |
| 486 | 486 | |
| 487 | - /** |
|
| 488 | - * @todo Add a method here to figure out where duplicate best-match |
|
| 489 | - * delimiter(s) fall within each line and then, depending on |
|
| 490 | - * which one has the best distribution, return that one. |
|
| 491 | - */ |
|
| 492 | - $decision = $dups->get($max); |
|
| 487 | + /** |
|
| 488 | + * @todo Add a method here to figure out where duplicate best-match |
|
| 489 | + * delimiter(s) fall within each line and then, depending on |
|
| 490 | + * which one has the best distribution, return that one. |
|
| 491 | + */ |
|
| 492 | + $decision = $dups->get($max); |
|
| 493 | 493 | try { |
| 494 | 494 | return $this->guessDelimByDistribution($decision, $eol); |
| 495 | 495 | } catch (TasterException $e) { |
| 496 | 496 | // if somehow we STILL can't come to a consensus, then fall back to a |
| 497 | - // "preferred delimiters" list... |
|
| 498 | - foreach ($this->delims as $key => $val) { |
|
| 499 | - if ($delim = array_search($val, $decision)) { |
|
| 500 | - return $delim; |
|
| 501 | - } |
|
| 502 | - } |
|
| 497 | + // "preferred delimiters" list... |
|
| 498 | + foreach ($this->delims as $key => $val) { |
|
| 499 | + if ($delim = array_search($val, $decision)) { |
|
| 500 | + return $delim; |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | 503 | } |
| 504 | 504 | } |
| 505 | 505 | |
@@ -568,8 +568,8 @@ discard block |
||
| 568 | 568 | })->map(function ($dists) { |
| 569 | 569 | return $dists->average(); |
| 570 | 570 | })->sort() |
| 571 | - ->reverse() |
|
| 572 | - ->getKeyAtPosition(0)]; |
|
| 571 | + ->reverse() |
|
| 572 | + ->getKeyAtPosition(0)]; |
|
| 573 | 573 | } catch (Exception $e) { |
| 574 | 574 | throw new TasterException('delimiter cannot be determined by distribution', TasterException::ERR_DELIMITER); |
| 575 | 575 | } |
@@ -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(); |
@@ -70,11 +70,11 @@ discard block |
||
| 70 | 70 | if (in_array($rp, $paths)) { |
| 71 | 71 | return true; |
| 72 | 72 | } |
| 73 | - $this->paths []= $rp; |
|
| 73 | + $this->paths [] = $rp; |
|
| 74 | 74 | |
| 75 | 75 | return true; |
| 76 | 76 | } |
| 77 | - $this->paths []= $path; |
|
| 77 | + $this->paths [] = $path; |
|
| 78 | 78 | |
| 79 | 79 | return false; |
| 80 | 80 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | $fqcp = str_replace(self::NAMESPACE_SEPARATOR, DIRECTORY_SEPARATOR, $className); |
| 133 | 133 | $paths = $this->getPaths(); |
| 134 | 134 | foreach ($paths as $path) { |
| 135 | - $classPath = $path . DIRECTORY_SEPARATOR . $fqcp . '.php'; |
|
| 135 | + $classPath = $path.DIRECTORY_SEPARATOR.$fqcp.'.php'; |
|
| 136 | 136 | if (file_exists($classPath) && is_readable($classPath)) { |
| 137 | 137 | require_once($classPath); |
| 138 | 138 | |