@@ -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 | /** |
@@ -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 | } |
@@ -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) { |
@@ -292,20 +292,20 @@ discard block |
||
| 292 | 292 | throw new TasterException("quoteChar and delimiter cannot be determined", TasterException::ERR_QUOTE_AND_DELIM); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - /** |
|
| 296 | - * Take a list of likely delimiter characters and find the one that occurs |
|
| 297 | - * the most consistent amount of times within the provided data. |
|
| 298 | - * |
|
| 299 | - * @param string $eol The character(s) used for newlines |
|
| 300 | - * @return string One of four Flavor::QUOTING_* constants |
|
| 301 | - * @see Flavor for possible quote style constants |
|
| 302 | - * @todo Refactor this method--It needs more thorough testing against a wider |
|
| 303 | - * variety of CSV data to be sure it works reliably. And I'm sure there |
|
| 304 | - * are many performance and logic improvements that could be made. This |
|
| 305 | - * is essentially a first draft. |
|
| 306 | - * @todo Can't use replaceQuotedSpecialChars rather than removeQuotedStrings |
|
| 307 | - * because the former requires u to know the delimiter |
|
| 308 | - */ |
|
| 295 | + /** |
|
| 296 | + * Take a list of likely delimiter characters and find the one that occurs |
|
| 297 | + * the most consistent amount of times within the provided data. |
|
| 298 | + * |
|
| 299 | + * @param string $eol The character(s) used for newlines |
|
| 300 | + * @return string One of four Flavor::QUOTING_* constants |
|
| 301 | + * @see Flavor for possible quote style constants |
|
| 302 | + * @todo Refactor this method--It needs more thorough testing against a wider |
|
| 303 | + * variety of CSV data to be sure it works reliably. And I'm sure there |
|
| 304 | + * are many performance and logic improvements that could be made. This |
|
| 305 | + * is essentially a first draft. |
|
| 306 | + * @todo Can't use replaceQuotedSpecialChars rather than removeQuotedStrings |
|
| 307 | + * because the former requires u to know the delimiter |
|
| 308 | + */ |
|
| 309 | 309 | protected function lickDelimiter($eol = "\n") |
| 310 | 310 | { |
| 311 | 311 | $frequencies = []; |
@@ -382,16 +382,16 @@ discard block |
||
| 382 | 382 | * which one has the best distribution, return that one. |
| 383 | 383 | */ |
| 384 | 384 | |
| 385 | - $decision = $dups->get($max); |
|
| 386 | - try { |
|
| 387 | - return $this->guessDelimByDistribution($decision, $eol); |
|
| 388 | - } catch (TasterException $e) { |
|
| 389 | - // if somehow we STILL can't come to a consensus, then fall back to a |
|
| 390 | - // "preferred delimiters" list... |
|
| 391 | - foreach ($this->delims as $key => $val) { |
|
| 385 | + $decision = $dups->get($max); |
|
| 386 | + try { |
|
| 387 | + return $this->guessDelimByDistribution($decision, $eol); |
|
| 388 | + } catch (TasterException $e) { |
|
| 389 | + // if somehow we STILL can't come to a consensus, then fall back to a |
|
| 390 | + // "preferred delimiters" list... |
|
| 391 | + foreach ($this->delims as $key => $val) { |
|
| 392 | 392 | if ($delim = array_search($val, $decision)) return $delim; |
| 393 | - } |
|
| 394 | - } |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | 395 | } |
| 396 | 396 | return $delims |
| 397 | 397 | ->sort() |
@@ -450,8 +450,8 @@ discard block |
||
| 450 | 450 | })->map(function($dists) { |
| 451 | 451 | return $dists->average(); |
| 452 | 452 | })->sort() |
| 453 | - ->reverse() |
|
| 454 | - ->getKeyAtPosition(0)]; |
|
| 453 | + ->reverse() |
|
| 454 | + ->getKeyAtPosition(0)]; |
|
| 455 | 455 | } catch (Exception $e) { |
| 456 | 456 | throw new TasterException("delimiter cannot be determined by distribution", TasterException::ERR_DELIMITER); |
| 457 | 457 | } |
@@ -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)); |
@@ -267,16 +267,16 @@ |
||
| 267 | 267 | return strlen($data); |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * Seekability accessor. |
|
| 272 | - * |
|
| 273 | - * Despite the fact that any class that implements this interface must also |
|
| 274 | - * define methods such as seek, that is no guarantee that an |
|
| 275 | - * object will necessarily be seekable. This method should tell the user |
|
| 276 | - * whether a stream is, in fact, seekable. |
|
| 277 | - * |
|
| 278 | - * @return boolean True if seekable, false otherwise |
|
| 279 | - */ |
|
| 270 | + /** |
|
| 271 | + * Seekability accessor. |
|
| 272 | + * |
|
| 273 | + * Despite the fact that any class that implements this interface must also |
|
| 274 | + * define methods such as seek, that is no guarantee that an |
|
| 275 | + * object will necessarily be seekable. This method should tell the user |
|
| 276 | + * whether a stream is, in fact, seekable. |
|
| 277 | + * |
|
| 278 | + * @return boolean True if seekable, false otherwise |
|
| 279 | + */ |
|
| 280 | 280 | public function isSeekable() |
| 281 | 281 | { |
| 282 | 282 | return $this->seekable; |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | public function toArray() |
| 195 | 195 | { |
| 196 | 196 | $data = []; |
| 197 | - foreach($this->data as $key => $val) { |
|
| 197 | + foreach ($this->data as $key => $val) { |
|
| 198 | 198 | $data[$key] = (is_object($val) && method_exists($val, 'toArray')) ? $val->toArray() : $val; |
| 199 | 199 | } |
| 200 | 200 | return $data; |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | if ($i === $pos) return $key; |
| 370 | 370 | $i++; |
| 371 | 371 | } |
| 372 | - throw new OutOfBoundsException("Collection data does not contain a key at given position: " . $pos); |
|
| 372 | + throw new OutOfBoundsException("Collection data does not contain a key at given position: ".$pos); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | return $this->data[$key]; |
| 555 | 555 | } else { |
| 556 | 556 | if ($throwExc) { |
| 557 | - throw new OutOfBoundsException("Collection data does not contain value for given key: " . $key); |
|
| 557 | + throw new OutOfBoundsException("Collection data does not contain value for given key: ".$key); |
|
| 558 | 558 | } |
| 559 | 559 | } |
| 560 | 560 | return $default; |
@@ -899,7 +899,7 @@ discard block |
||
| 899 | 899 | public function pairs($alt = false) |
| 900 | 900 | { |
| 901 | 901 | return new self(array_map( |
| 902 | - function ($key, $val) use ($alt) { |
|
| 902 | + function($key, $val) use ($alt) { |
|
| 903 | 903 | if ($alt) { |
| 904 | 904 | return [$key => $val]; |
| 905 | 905 | } else { |
@@ -981,7 +981,7 @@ discard block |
||
| 981 | 981 | if (false !== ($condRet = $this->if2DMapInternalMethod(__METHOD__))) { |
| 982 | 982 | return $condRet; |
| 983 | 983 | } |
| 984 | - $strvals = $this->map(function($val){ |
|
| 984 | + $strvals = $this->map(function($val) { |
|
| 985 | 985 | return (string) $val; |
| 986 | 986 | }); |
| 987 | 987 | $this->assertNumericValues(); |
@@ -1095,7 +1095,7 @@ discard block |
||
| 1095 | 1095 | $this->assertIsTabular(); |
| 1096 | 1096 | return $this->sort(function($a, $b) use ($key, $cmp) { |
| 1097 | 1097 | if (!isset($a[$key]) || !isset($b[$key])) { |
| 1098 | - throw new RuntimeException('Cannot order collection by non-existant key: ' . $key); |
|
| 1098 | + throw new RuntimeException('Cannot order collection by non-existant key: '.$key); |
|
| 1099 | 1099 | } |
| 1100 | 1100 | if (is_null($cmp)) { |
| 1101 | 1101 | return strcasecmp($a[$key], $b[$key]); |
@@ -1142,7 +1142,7 @@ discard block |
||
| 1142 | 1142 | */ |
| 1143 | 1143 | public function is2D() |
| 1144 | 1144 | { |
| 1145 | - return !$this->contains(function($val){ |
|
| 1145 | + return !$this->contains(function($val) { |
|
| 1146 | 1146 | return !is_array($val); |
| 1147 | 1147 | }); |
| 1148 | 1148 | return false; |
@@ -1212,7 +1212,7 @@ discard block |
||
| 1212 | 1212 | |
| 1213 | 1213 | protected function assertNumericValues() |
| 1214 | 1214 | { |
| 1215 | - if ($this->contains(function($val){ |
|
| 1215 | + if ($this->contains(function($val) { |
|
| 1216 | 1216 | return !is_numeric($val); |
| 1217 | 1217 | })) { |
| 1218 | 1218 | // can't average non-numeric data |
@@ -1228,6 +1228,6 @@ discard block |
||
| 1228 | 1228 | if (is_null($data) || is_array($data) || $data instanceof Iterator) { |
| 1229 | 1229 | return; |
| 1230 | 1230 | } |
| 1231 | - throw new InvalidArgumentException("Invalid type for collection data: " . gettype($data)); |
|
| 1231 | + throw new InvalidArgumentException("Invalid type for collection data: ".gettype($data)); |
|
| 1232 | 1232 | } |
| 1233 | 1233 | } |
@@ -267,16 +267,16 @@ |
||
| 267 | 267 | return strlen($data); |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * Seekability accessor. |
|
| 272 | - * |
|
| 273 | - * Despite the fact that any class that implements this interface must also |
|
| 274 | - * define methods such as seek, that is no guarantee that an |
|
| 275 | - * object will necessarily be seekable. This method should tell the user |
|
| 276 | - * whether a stream is, in fact, seekable. |
|
| 277 | - * |
|
| 278 | - * @return boolean True if seekable, false otherwise |
|
| 279 | - */ |
|
| 270 | + /** |
|
| 271 | + * Seekability accessor. |
|
| 272 | + * |
|
| 273 | + * Despite the fact that any class that implements this interface must also |
|
| 274 | + * define methods such as seek, that is no guarantee that an |
|
| 275 | + * object will necessarily be seekable. This method should tell the user |
|
| 276 | + * whether a stream is, in fact, seekable. |
|
| 277 | + * |
|
| 278 | + * @return boolean True if seekable, false otherwise |
|
| 279 | + */ |
|
| 280 | 280 | public function isSeekable() |
| 281 | 281 | { |
| 282 | 282 | return $this->seekable; |
@@ -267,16 +267,16 @@ |
||
| 267 | 267 | return strlen($data); |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * Seekability accessor. |
|
| 272 | - * |
|
| 273 | - * Despite the fact that any class that implements this interface must also |
|
| 274 | - * define methods such as seek, that is no guarantee that an |
|
| 275 | - * object will necessarily be seekable. This method should tell the user |
|
| 276 | - * whether a stream is, in fact, seekable. |
|
| 277 | - * |
|
| 278 | - * @return boolean True if seekable, false otherwise |
|
| 279 | - */ |
|
| 270 | + /** |
|
| 271 | + * Seekability accessor. |
|
| 272 | + * |
|
| 273 | + * Despite the fact that any class that implements this interface must also |
|
| 274 | + * define methods such as seek, that is no guarantee that an |
|
| 275 | + * object will necessarily be seekable. This method should tell the user |
|
| 276 | + * whether a stream is, in fact, seekable. |
|
| 277 | + * |
|
| 278 | + * @return boolean True if seekable, false otherwise |
|
| 279 | + */ |
|
| 280 | 280 | public function isSeekable() |
| 281 | 281 | { |
| 282 | 282 | return $this->seekable; |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | { |
| 240 | 240 | if (!$this->isConnected()) { |
| 241 | 241 | $e = null; |
| 242 | - $errhandler = function () use (&$e) { |
|
| 242 | + $errhandler = function() use (&$e) { |
|
| 243 | 243 | $e = new IOException(sprintf( |
| 244 | 244 | "Could not open connection for %s using mode %s", |
| 245 | 245 | $this->getUri(), |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | $this->updateContext(); |
| 556 | 556 | return $this; |
| 557 | 557 | } |
| 558 | - throw new InvalidArgumentException("Context options must be an array, got: " . gettype($options)); |
|
| 558 | + throw new InvalidArgumentException("Context options must be an array, got: ".gettype($options)); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | /** |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | $this->updateContext(); |
| 576 | 576 | return $this; |
| 577 | 577 | } |
| 578 | - throw new InvalidArgumentException("Context parameters must be an array, got: " . gettype($params)); |
|
| 578 | + throw new InvalidArgumentException("Context parameters must be an array, got: ".gettype($params)); |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | /** |
@@ -185,10 +185,10 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | // ok we're opening a new stream resource handle |
| 187 | 187 | $this->setUri($uri) |
| 188 | - ->setMode($mode) |
|
| 189 | - ->setLazy($lazy) |
|
| 190 | - ->setUseIncludePath($use_include_path) |
|
| 191 | - ->setContext($context_options, $context_params); |
|
| 188 | + ->setMode($mode) |
|
| 189 | + ->setLazy($lazy) |
|
| 190 | + ->setUseIncludePath($use_include_path) |
|
| 191 | + ->setContext($context_options, $context_params); |
|
| 192 | 192 | if (!$this->isLazy()) { |
| 193 | 193 | $this->connect(); |
| 194 | 194 | } |
@@ -351,9 +351,9 @@ discard block |
||
| 351 | 351 | |
| 352 | 352 | $this->flag = ''; |
| 353 | 353 | $this->setBaseMode($base) |
| 354 | - ->setIsPlus($plus == '+') |
|
| 355 | - ->setIsText($flag == 't') |
|
| 356 | - ->setIsBinary($flag == 'b'); |
|
| 354 | + ->setIsPlus($plus == '+') |
|
| 355 | + ->setIsText($flag == 't') |
|
| 356 | + ->setIsBinary($flag == 'b'); |
|
| 357 | 357 | |
| 358 | 358 | return $this; |
| 359 | 359 | } |