Completed
Push — master ( 748f90...5c1aea )
by Luke
08:07
created
src/CSVelte/Taster.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -193,16 +193,16 @@  discard block
 block discarded – undo
193 193
     {
194 194
         $str = $this->removeQuotedStrings($this->sample);
195 195
         $eols = [
196
-            self::EOL_WINDOWS => "\r\n",  // 0x0D - 0x0A - Windows, DOS OS/2
197
-            self::EOL_UNIX    => "\n",    // 0x0A -      - Unix, OSX
198
-            self::EOL_TRS80   => "\r",    // 0x0D -      - Apple ][, TRS80
196
+            self::EOL_WINDOWS => "\r\n", // 0x0D - 0x0A - Windows, DOS OS/2
197
+            self::EOL_UNIX    => "\n", // 0x0A -      - Unix, OSX
198
+            self::EOL_TRS80   => "\r", // 0x0D -      - Apple ][, TRS80
199 199
         ];
200 200
 
201 201
         $curCount = 0;
202 202
         // @todo This should return a default maybe?
203 203
         $curEol = PHP_EOL;
204
-        foreach($eols as $k => $eol) {
205
-            if( ($count = substr_count($str, $eol)) > $curCount) {
204
+        foreach ($eols as $k => $eol) {
205
+            if (($count = substr_count($str, $eol)) > $curCount) {
206 206
                 $curCount = $count;
207 207
                 $curEol = $eol;
208 208
             }
@@ -235,12 +235,12 @@  discard block
 block discarded – undo
235 235
         $patterns = [];
236 236
         // delim can be anything but line breaks, quotes, alphanumeric, underscore, backslash, or any type of spaces
237 237
         $antidelims = implode(array("\r", "\n", "\w", preg_quote('"', '/'), preg_quote("'", '/')/*, preg_quote('\\', '/')*/, preg_quote(chr(self::SPACE), '/')));
238
-        $delim = '(?P<delim>[^' . $antidelims . '])';
238
+        $delim = '(?P<delim>[^'.$antidelims.'])';
239 239
         $quote = '(?P<quoteChar>"|\'|`)'; // @todo I think MS Excel uses some strange encoding for fancy open/close quotes
240
-        $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
241
-        $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
242
-        $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
243
-        $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
240
+        $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
241
+        $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
242
+        $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
243
+        $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
244 244
         foreach ($patterns as $pattern) {
245 245
             // @todo I had to add the error suppression char here because it was
246 246
             //     causing undefined offset errors with certain data sets. strange...
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
             if (array_key_exists(self::DATA_NONNUMERIC, array_flip($types))) {
386 386
                 // allow for a SMALL amount of error here
387 387
                 $counts = array(self::DATA_SPECIAL => 0, self::DATA_NONNUMERIC => 0);
388
-                array_walk($freq['quoted'], function ($val) use (&$counts) {
388
+                array_walk($freq['quoted'], function($val) use (&$counts) {
389 389
                     $counts[$val]++;
390 390
                 });
391 391
                 arsort($counts);
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
                 $day = '[0-3]?[0-9]';
512 512
                 $sep = '[\/\.\-]?';
513 513
                 $time = '([0-2]?[0-9](:[0-5][0-9]){1,2}(am|pm)?|[01]?[0-9](am|pm))';
514
-                $date = '(' . $month . $sep . $day . $sep . $year . '|' . $day . $sep . $month . $sep . $year . '|' . $year . $sep . $month . $sep . $day . ')';
514
+                $date = '('.$month.$sep.$day.$sep.$year.'|'.$day.$sep.$month.$sep.$year.'|'.$year.$sep.$month.$sep.$day.')';
515 515
                 $dt = Carbon::parse($data);
516 516
                 if ($dt->today()) {
517 517
                     // then this is most likely a time string...
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
                 }
522 522
                 if (preg_match("/^{$date}$/i", $data)) {
523 523
                     return self::TYPE_DATE;
524
-                } elseif(preg_match("/^{$date} {$time}$/i")) {
524
+                } elseif (preg_match("/^{$date} {$time}$/i")) {
525 525
                     return self::TYPE_DATETIME;
526 526
                 }
527 527
             } catch (\Exception $e) {
Please login to merge, or discard this patch.
src/CSVelte/IO/Stream.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
             return self::streamize((string) $resource);
145 145
         }
146 146
 
147
-        throw new InvalidArgumentException('Invalid resource type: ' . $type);
147
+        throw new InvalidArgumentException('Invalid resource type: '.$type);
148 148
     }
149 149
 
150 150
     /**
@@ -231,17 +231,17 @@  discard block
 block discarded – undo
231 231
                 $stream = @fopen($uri, $mode);
232 232
             } else {
233 233
                 if (!is_array($context)) {
234
-                    throw new InvalidArgumentException("Invalid argument for context. Expected array, got: " . gettype($context));
234
+                    throw new InvalidArgumentException("Invalid argument for context. Expected array, got: ".gettype($context));
235 235
                 }
236 236
                 $context = stream_context_create($context);
237 237
                 $stream = @fopen($uri, $mode, false, $context);
238 238
             }
239 239
             if (false === $stream) {
240
-                throw new IOException("Invalid stream URI: " . $uri, IOException::ERR_INVALID_STREAM_URI);
240
+                throw new IOException("Invalid stream URI: ".$uri, IOException::ERR_INVALID_STREAM_URI);
241 241
             }
242 242
         }
243 243
         if (!is_resource($stream) || get_resource_type($stream) != 'stream') {
244
-            throw new IOException("Expected stream resource, got: " . gettype($stream), IOException::ERR_INVALID_STREAM_RESOURCE);
244
+            throw new IOException("Expected stream resource, got: ".gettype($stream), IOException::ERR_INVALID_STREAM_RESOURCE);
245 245
         }
246 246
         return $stream;
247 247
     }
Please login to merge, or discard this patch.
src/CSVelte/Writer.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.