@@ -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() |
@@ -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 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | { |
| 142 | 142 | if (is_array($rows)) $rows = new ArrayIterator($rows); |
| 143 | 143 | if (!($rows instanceof Iterator)) { |
| 144 | - throw new InvalidArgumentException('First argument for ' . __METHOD__ . ' must be iterable'); |
|
| 144 | + throw new InvalidArgumentException('First argument for '.__METHOD__.' must be iterable'); |
|
| 145 | 145 | } |
| 146 | 146 | $written = 0; |
| 147 | 147 | if ($rows instanceof Reader) { |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | { |
| 166 | 166 | $items = array(); |
| 167 | 167 | foreach ($row as $data) { |
| 168 | - $items []= $this->prepareData($data); |
|
| 168 | + $items [] = $this->prepareData($data); |
|
| 169 | 169 | } |
| 170 | 170 | $row = new Row($items); |
| 171 | 171 | return $row; |
@@ -193,11 +193,11 @@ discard block |
||
| 193 | 193 | // to use it for very long, in fact, once I finish writing the Data class |
| 194 | 194 | // it is gonezo! |
| 195 | 195 | $hasSpecialChars = function($s) use ($flvr) { |
| 196 | - $specialChars = preg_quote($flvr->lineTerminator . $flvr->quoteChar . $flvr->delimiter); |
|
| 196 | + $specialChars = preg_quote($flvr->lineTerminator.$flvr->quoteChar.$flvr->delimiter); |
|
| 197 | 197 | $pattern = "/[{$specialChars}]/m"; |
| 198 | 198 | return preg_match($pattern, $s); |
| 199 | 199 | }; |
| 200 | - switch($flvr->quoteStyle) { |
|
| 200 | + switch ($flvr->quoteStyle) { |
|
| 201 | 201 | case Flavor::QUOTE_ALL: |
| 202 | 202 | $doQuote = true; |
| 203 | 203 | break; |
@@ -227,6 +227,6 @@ discard block |
||
| 227 | 227 | $escapeQuote = ""; |
| 228 | 228 | if ($isQuoted) $escapeQuote = ($flvr->doubleQuote) ? $flvr->quoteChar : $flvr->escapeChar; |
| 229 | 229 | // @todo Not sure what else, if anything, I'm supposed to be escaping here.. |
| 230 | - return str_replace($flvr->quoteChar, $escapeQuote . $flvr->quoteChar, $str); |
|
| 230 | + return str_replace($flvr->quoteChar, $escapeQuote.$flvr->quoteChar, $str); |
|
| 231 | 231 | } |
| 232 | 232 | } |
@@ -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) { |
@@ -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)); |