Completed
Push — releases/v0.2.1 ( ff9fbc...bb9532 )
by Luke
03:05
created
src/CSVelte/IO/Stream.php 3 patches
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -16,14 +16,11 @@
 block discarded – undo
16 16
 use CSVelte\Traits\IsReadable;
17 17
 use CSVelte\Traits\IsWritable;
18 18
 use CSVelte\Traits\IsSeekable;
19
-
20 19
 use CSVelte\Contract\Readable;
21 20
 use CSVelte\Contract\Writable;
22 21
 use CSVelte\Contract\Seekable;
23 22
 
24 23
 use \InvalidArgumentException;
25
-use CSVelte\Exception\NotYetImplementedException;
26
-use CSVelte\Exception\EndOfFileException;
27 24
 use CSVelte\Exception\IOException;
28 25
 
29 26
 /**
Please login to merge, or discard this patch.
Doc Comments   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -131,6 +131,7 @@  discard block
 block discarded – undo
131 131
      *
132 132
      * @see http://php.net/manual/en/function.fopen.php
133 133
      * @see http://php.net/manual/en/function.stream-context-create.php
134
+     * @param string $mode
134 135
      */
135 136
     public static function open($uri, $mode = null, $context = null, $lazy = false)
136 137
     {
@@ -143,7 +144,7 @@  discard block
 block discarded – undo
143 144
     /**
144 145
      * Close stream resource.
145 146
      *
146
-     * @return boolean True on success or false on failure
147
+     * @return boolean|null True on success or false on failure
147 148
      */
148 149
     public function close()
149 150
     {
@@ -224,7 +225,7 @@  discard block
 block discarded – undo
224 225
      *
225 226
      * Returns the internal stream resource pointer
226 227
      *
227
-     * @return resource The open stream resource pointer
228
+     * @return Resource The open stream resource pointer
228 229
      */
229 230
     public function getResource()
230 231
     {
@@ -262,7 +263,7 @@  discard block
 block discarded – undo
262 263
      *
263 264
      * After the stream has been detached, the stream is in an unusable state.
264 265
      *
265
-     * @return resource|null Underlying PHP stream, if any
266
+     * @return Resource Underlying PHP stream, if any
266 267
      */
267 268
     public function detach()
268 269
     {
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -136,7 +136,9 @@  discard block
 block discarded – undo
136 136
     {
137 137
         $resource = (new Resource($uri, $mode))
138 138
             ->setContextResource($context);
139
-        if (!$lazy) $resource->connect();
139
+        if (!$lazy) {
140
+            $resource->connect();
141
+        }
140 142
         return new self($resource);
141 143
     }
142 144
 
@@ -169,7 +171,9 @@  discard block
 block discarded – undo
169 171
             }
170 172
             // if a certain value was requested, return it
171 173
             // otherwise, return entire array
172
-            if (is_null($key)) return $this->meta;
174
+            if (is_null($key)) {
175
+                return $this->meta;
176
+            }
173 177
             return (array_key_exists($key, $this->meta)) ? $this->meta[$key] : null;
174 178
         }
175 179
     }
@@ -315,7 +319,9 @@  discard block
 block discarded – undo
315 319
     public function read($length)
316 320
     {
317 321
         $this->assertIsReadable();
318
-        if ($this->eof()) return false;
322
+        if ($this->eof()) {
323
+            return false;
324
+        }
319 325
         return fread($this->resource->getHandle(), $length);
320 326
     }
321 327
 
Please login to merge, or discard this patch.
src/CSVelte/IO/IteratorStream.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
     /**
177 177
      * Return the current position within the stream/readable
178 178
      *
179
-     * @return int The current position within readable
179
+     * @return boolean The current position within readable
180 180
      */
181 181
     public function tell()
182 182
     {
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
     /**
229 229
      * Closes the stream and any underlying resources.
230 230
      *
231
-     * @return void
231
+     * @return boolean
232 232
      */
233 233
     public function close()
234 234
     {
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      * Write data to the output.
279 279
      *
280 280
      * @param string The data to write
281
-     * @return int The number of bytes written
281
+     * @return boolean The number of bytes written
282 282
      */
283 283
     public function write($data)
284 284
     {
Please login to merge, or discard this patch.
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -267,16 +267,16 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
src/CSVelte/IO/Resource.php 4 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      *
220 220
      * Creates and returns a Stream object for this resource
221 221
      *
222
-     * @return resource The underlying stream resource
222
+     * @return Stream The underlying stream resource
223 223
      */
224 224
     public function __invoke()
225 225
     {
@@ -432,6 +432,7 @@  discard block
 block discarded – undo
432 432
      * until the user specifically requests it.
433 433
      *
434 434
      * @param boolean|null Whether or not to "lazily" open the stream
435
+     * @param boolean|null $lazy
435 436
      * @return $this
436 437
      */
437 438
     protected function setLazy($lazy)
@@ -841,6 +842,7 @@  discard block
 block discarded – undo
841 842
      * only be called on unopened stream resources.
842 843
      *
843 844
      * @param  string The method that is asserting
845
+     * @param string $method
844 846
      * @return void
845 847
      * @throws \CSVelte\Exception\IOException if stream is open
846 848
      */
@@ -857,6 +859,7 @@  discard block
 block discarded – undo
857 859
      * Used internally to ensure that a given stream wrapper is valid and available
858 860
      *
859 861
      * @param  string The name of the stream wrapper
862
+     * @param string $name
860 863
      * @return void
861 864
      * @throws \InvalidArgumentException if wrapper doesn't exist
862 865
      */
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -190,17 +190,17 @@  discard block
 block discarded – undo
190 190
             // set all this manually
191 191
             $meta = stream_get_meta_data($handle);
192 192
             $this->setUri($meta['uri'])
193
-                 ->setMode($meta['mode']);
193
+                    ->setMode($meta['mode']);
194 194
             $this->conn = $handle;
195 195
             return;
196 196
         }
197 197
 
198 198
         // ok we're opening a new stream resource handle
199 199
         $this->setUri($uri)
200
-             ->setMode($mode)
201
-             ->setLazy($lazy)
202
-             ->setUseIncludePath($use_include_path)
203
-             ->setContext($context_options, $context_params);
200
+                ->setMode($mode)
201
+                ->setLazy($lazy)
202
+                ->setUseIncludePath($use_include_path)
203
+                ->setContext($context_options, $context_params);
204 204
         if (!$this->isLazy()) {
205 205
             $this->connect();
206 206
         }
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
 
340 340
         $this->flag = '';
341 341
         $this->setBaseMode($base)
342
-             ->setIsPlus($plus == '+')
343
-             ->setIsText($flag == 't')
344
-             ->setIsBinary($flag == 'b');
342
+                ->setIsPlus($plus == '+')
343
+                ->setIsText($flag == 't')
344
+                ->setIsBinary($flag == 'b');
345 345
 
346 346
         return $this;
347 347
     }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
     {
240 240
         if (!$this->isConnected()) {
241 241
             $e = null;
242
-            $errhandler = function ($errno, $errstr, $errfile, $errline) use (&$e) {
242
+            $errhandler = function($errno, $errstr, $errfile, $errline) 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
 block discarded – undo
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
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -254,7 +254,9 @@  discard block
 block discarded – undo
254 254
                 $this->getContext()
255 255
             );
256 256
             restore_error_handler();
257
-            if ($e) throw $e;
257
+            if ($e) {
258
+                throw $e;
259
+            }
258 260
         }
259 261
         return $this->isConnected();
260 262
     }
@@ -328,7 +330,9 @@  discard block
 block discarded – undo
328 330
     public function setMode($mode = null)
329 331
     {
330 332
         $this->assertNotConnected(__METHOD__);
331
-        if (is_null($mode)) $mode = "r+b";
333
+        if (is_null($mode)) {
334
+            $mode = "r+b";
335
+        }
332 336
 
333 337
         $mode = substr($mode, 0, 3);
334 338
         $rest = substr($mode, 1);
@@ -436,7 +440,9 @@  discard block
 block discarded – undo
436 440
      */
437 441
     protected function setLazy($lazy)
438 442
     {
439
-        if (is_null($lazy)) $lazy = true;
443
+        if (is_null($lazy)) {
444
+            $lazy = true;
445
+        }
440 446
         $this->lazy = (boolean) $lazy;
441 447
         return $this;
442 448
     }
Please login to merge, or discard this patch.
src/CSVelte/Table/AbstractRow.php 5 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,6 @@
 block discarded – undo
15 15
 use \Iterator;
16 16
 use \Countable;
17 17
 use \ArrayAccess;
18
-use CSVelte\Flavor;
19 18
 
20 19
 use \OutOfBoundsException;
21 20
 use \InvalidArgumentException;
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@
 block discarded – undo
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)
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
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));
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     /**
133 133
      * Get the current key (column number or header, if available)
134 134
      *
135
-     * @return string The "current" key
135
+     * @return integer The "current" key
136 136
      * @access public
137 137
      * @todo Figure out if this can return a CSVelte\Table\HeaderData object so long as it
138 138
      *     has a __toString() method that generated the right key...
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      * Advance the internal pointer to the next column's data object
147 147
      * Also returns the next column's data object if there is one
148 148
      *
149
-     * @return CSVelte\Table\Data The "next" column's data
149
+     * @return string|null The "next" column's data
150 150
      * @access public
151 151
      */
152 152
     public function next()
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
     /**
159 159
      * Return the internal pointer to the first column and return that object
160 160
      *
161
-     * @return null|AbstractRow
161
+     * @return string|null
162 162
      */
163 163
     public function rewind()
164 164
     {
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -152,7 +152,9 @@
 block discarded – undo
152 152
     public function next()
153 153
     {
154 154
         $this->position++;
155
-        if ($this->valid()) return $this->current();
155
+        if ($this->valid()) {
156
+            return $this->current();
157
+        }
156 158
     }
157 159
 
158 160
     /**
Please login to merge, or discard this patch.
src/CSVelte/Taster.php 4 patches
Doc Comments   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -189,6 +189,7 @@  discard block
 block discarded – undo
189 189
      * replaceQuotedSpecialChars method which (at least to me) makes more sense.
190 190
      *
191 191
      * @param string The string to replace quoted strings within
192
+     * @param string $data
192 193
      * @return string The input string with quoted strings removed
193 194
      * @todo Replace code that uses this method with the replaceQuotedSpecialChars
194 195
      *     method instead. I think it's cleaner.
@@ -559,7 +560,7 @@  discard block
 block discarded – undo
559 560
      * Determine whether a particular string of data has quotes around it.
560 561
      *
561 562
      * @param string The data to check
562
-     * @return boolean Whether the data is quoted or not
563
+     * @return integer Whether the data is quoted or not
563 564
      */
564 565
     protected function isQuoted($data)
565 566
     {
@@ -607,6 +608,8 @@  discard block
 block discarded – undo
607 608
      *
608 609
      * @param string The string to do the replacements on
609 610
      * @param string The delimiter character to replace
611
+     * @param string $data
612
+     * @param string $delim
610 613
      * @return string The data with replacements performed
611 614
      * @todo I could probably pass in (maybe optionally) the newline character I
612 615
      *     want to replace as well. I'll do that if I need to.
@@ -632,6 +635,7 @@  discard block
 block discarded – undo
632 635
      * to be practical.
633 636
      *
634 637
      * @param string The string of data to check the type of
638
+     * @param string $data
635 639
      * @return string One of the TYPE_ string constants above
636 640
      */
637 641
     protected function lickType($data)
Please login to merge, or discard this patch.
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -290,20 +290,20 @@  discard block
 block discarded – undo
290 290
         throw new TasterException("quoteChar and delimiter cannot be determined", TasterException::ERR_QUOTE_AND_DELIM);
291 291
     }
292 292
 
293
-     /**
294
-      * Take a list of likely delimiter characters and find the one that occurs
295
-      * the most consistent amount of times within the provided data.
296
-      *
297
-      * @param string The character(s) used for newlines
298
-      * @return string One of four Flavor::QUOTING_* constants
299
-      * @see \CSVelte\Flavor for possible quote style constants
300
-      * @todo Refactor this method--It needs more thorough testing against a wider
301
-      *     variety of CSV data to be sure it works reliably. And I'm sure there
302
-      *     are many performance and logic improvements that could be made. This
303
-      *     is essentially a first draft.
304
-      * @todo Can't use replaceQuotedSpecialChars rather than removeQuotedStrings
305
-      *     because the former requires u to know the delimiter
306
-      */
293
+        /**
294
+         * Take a list of likely delimiter characters and find the one that occurs
295
+         * the most consistent amount of times within the provided data.
296
+         *
297
+         * @param string The character(s) used for newlines
298
+         * @return string One of four Flavor::QUOTING_* constants
299
+         * @see \CSVelte\Flavor for possible quote style constants
300
+         * @todo Refactor this method--It needs more thorough testing against a wider
301
+         *     variety of CSV data to be sure it works reliably. And I'm sure there
302
+         *     are many performance and logic improvements that could be made. This
303
+         *     is essentially a first draft.
304
+         * @todo Can't use replaceQuotedSpecialChars rather than removeQuotedStrings
305
+         *     because the former requires u to know the delimiter
306
+         */
307 307
     protected function lickDelimiter($eol = "\n")
308 308
     {
309 309
         $frequencies = [];
@@ -381,16 +381,16 @@  discard block
 block discarded – undo
381 381
              *     which one has the best distribution, return that one.
382 382
              */
383 383
 
384
-             $decision = $dups->get($max);
385
-             try {
386
-                 $delim = $this->guessDelimByDistribution($decision, $eol);
387
-             } catch (TasterException $e) {
388
-                 // if somehow we STILL can't come to a consensus, then fall back to a
389
-                 // "preferred delimiters" list...
390
-                 foreach ($this->delims as $key => $val) {
384
+                $decision = $dups->get($max);
385
+                try {
386
+                    $delim = $this->guessDelimByDistribution($decision, $eol);
387
+                } catch (TasterException $e) {
388
+                    // if somehow we STILL can't come to a consensus, then fall back to a
389
+                    // "preferred delimiters" list...
390
+                    foreach ($this->delims as $key => $val) {
391 391
                     if ($delim = array_search($val, $decision)) return $delim;
392
-                 }
393
-             }
392
+                    }
393
+                }
394 394
         }
395 395
         return $delims
396 396
             ->sort()
@@ -447,8 +447,8 @@  discard block
 block discarded – undo
447 447
             })->map(function($dists) {
448 448
                 return $dists->average();
449 449
             })->sort()
450
-              ->reverse()
451
-              ->getKeyAtPosition(0)];
450
+                ->reverse()
451
+                ->getKeyAtPosition(0)];
452 452
         } catch (Exception $e) {
453 453
             throw new TasterException("delimiter cannot be determined by distribution", TasterException::ERR_DELIMITER);
454 454
         }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -215,16 +215,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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) {
Please login to merge, or discard this patch.
Braces   +34 added lines, -12 removed lines patch added patch discarded remove patch
@@ -169,7 +169,9 @@  discard block
 block discarded – undo
169 169
         try {
170 170
             list($quoteChar, $delimiter) = $this->lickQuoteAndDelim();
171 171
         } catch (TasterException $e) {
172
-            if ($e->getCode() !== TasterException::ERR_QUOTE_AND_DELIM) throw $e;
172
+            if ($e->getCode() !== TasterException::ERR_QUOTE_AND_DELIM) {
173
+                throw $e;
174
+            }
173 175
             $quoteChar = '"';
174 176
             $delimiter = $this->lickDelimiter($lineTerminator);
175 177
         }
@@ -265,7 +267,9 @@  discard block
 block discarded – undo
265 267
         foreach ($patterns as $pattern) {
266 268
             // @todo I had to add the error suppression char here because it was
267 269
             //     causing undefined offset errors with certain data sets. strange...
268
-            if (@preg_match_all($pattern, $this->sample, $matches) && $matches) break;
270
+            if (@preg_match_all($pattern, $this->sample, $matches) && $matches) {
271
+                break;
272
+            }
269 273
         }
270 274
         if ($matches) {
271 275
             try {
@@ -388,7 +392,9 @@  discard block
 block discarded – undo
388 392
                  // if somehow we STILL can't come to a consensus, then fall back to a
389 393
                  // "preferred delimiters" list...
390 394
                  foreach ($this->delims as $key => $val) {
391
-                    if ($delim = array_search($val, $decision)) return $delim;
395
+                    if ($delim = array_search($val, $decision)) {
396
+                        return $delim;
397
+                    }
392 398
                  }
393 399
              }
394 400
         }
@@ -431,7 +437,9 @@  discard block
 block discarded – undo
431 437
             return $delims[collect($delims)->map(function($delim) use (&$distrib, $lines) {
432 438
                 $linedist = collect();
433 439
                 $lines->walk(function($line, $line_no) use (&$linedist, $delim) {
434
-                    if (!strlen($line)) return;
440
+                    if (!strlen($line)) {
441
+                        return;
442
+                    }
435 443
                     $sectstot = 10;
436 444
                     $sectlen = (int) (strlen($line) / $sectstot);
437 445
                     $sections = collect(str_split($line, $sectlen))
@@ -519,8 +527,12 @@  discard block
 block discarded – undo
519 527
         $quoting_styles = $quoting_styles->filter(function($val) { return (bool) $val; });
520 528
         // if quoting_styles still has QUOTE_ALL or QUOTE_NONE, then return
521 529
         // whichever of them it is, we don't need to do anything else
522
-        if ($quoting_styles->has(Flavor::QUOTE_ALL)) return Flavor::QUOTE_ALL;
523
-        if ($quoting_styles->has(Flavor::QUOTE_NONE)) return Flavor::QUOTE_NONE;
530
+        if ($quoting_styles->has(Flavor::QUOTE_ALL)) {
531
+            return Flavor::QUOTE_ALL;
532
+        }
533
+        if ($quoting_styles->has(Flavor::QUOTE_NONE)) {
534
+            return Flavor::QUOTE_NONE;
535
+        }
524 536
         if (count($types) == 1) {
525 537
             $style = $types->getValueAtPosition(0);
526 538
             if ($quoting_styles->has($style)) {
@@ -537,7 +549,9 @@  discard block
 block discarded – undo
537 549
                 if ($most = $counts->max()) {
538 550
                     $least = $counts->min();
539 551
                     $err_margin = $least / $most;
540
-                    if ($err_margin < 1) return Flavor::QUOTE_NONNUMERIC;
552
+                    if ($err_margin < 1) {
553
+                        return Flavor::QUOTE_NONNUMERIC;
554
+                    }
541 555
                 }
542 556
             }
543 557
         }
@@ -712,7 +726,9 @@  discard block
 block discarded – undo
712 726
                 $field = str_replace(self::PLACEHOLDER_DELIM, $delim, $field);
713 727
                 // @todo Need a Collection::setTableField($x, $y) method
714 728
                 //       See notes in green binder about refactoring Collection
715
-                if (!$types->has($line_no)) $types->set($line_no, collect());
729
+                if (!$types->has($line_no)) {
730
+                    $types->set($line_no, collect());
731
+                }
716 732
                 $types->get($line_no)->set($colpos, [
717 733
                     'type' => $this->lickType($this->unQuote($field)),
718 734
                     'length' => strlen($field)
@@ -735,12 +751,18 @@  discard block
 block discarded – undo
735 751
                     extract($possibleHeader->get($col_no, null, true), EXTR_PREFIX_ALL, "header");
736 752
                     if ($header_type == self::TYPE_STRING) {
737 753
                         // use length
738
-                        if ($length != $header_length) $hasHeader++;
739
-                        else $hasHeader--;
754
+                        if ($length != $header_length) {
755
+                            $hasHeader++;
756
+                        } else {
757
+                            $hasHeader--;
758
+                        }
740 759
                     } else {
741 760
                         // use data type
742
-                        if ($type != $header_type) $hasHeader++;
743
-                        else $hasHeader--;
761
+                        if ($type != $header_type) {
762
+                            $hasHeader++;
763
+                        } else {
764
+                            $hasHeader--;
765
+                        }
744 766
                     }
745 767
                 } catch (OutOfBoundsException $e) {
746 768
                     // failure...
Please login to merge, or discard this patch.
src/CSVelte/Writer.php 3 patches
Doc Comments   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
     /**
61 61
      * Class Constructor
62 62
      *
63
-     * @param \CSVelte\Contract\Writable $output An output source to write to
63
+     * @param Streamable $output An output source to write to
64 64
      * @param \CSVelte\Flavor|array $flavor A flavor or set of formatting params
65 65
      */
66 66
     public function __construct(Streamable $output, $flavor = null)
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      * likely buffer the output so that this may be called after writeRows()
90 90
      *
91 91
      * @param \Iterator|array A list of header values
92
-     * @return boolean
92
+     * @return boolean|null
93 93
      * @throws \CSVelte\Exception\WriterException
94 94
      */
95 95
     public function setHeaderRow($headers)
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      * This means taking an array of data, and converting it to a Row object
160 160
      *
161 161
      * @param \Iterator|array of data items
162
-     * @return CSVelte\Table\AbstractRow
162
+     * @return Row
163 163
      * @access protected
164 164
      */
165 165
     protected function prepareRow(Iterator $row)
@@ -187,6 +187,9 @@  discard block
 block discarded – undo
187 187
         return $this->quoteString($data);
188 188
     }
189 189
 
190
+    /**
191
+     * @param string $str
192
+     */
190 193
     protected function quoteString($str)
191 194
     {
192 195
         $flvr = $this->getFlavor();
Please login to merge, or discard this 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.
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -64,7 +64,9 @@  discard block
 block discarded – undo
64 64
      */
65 65
     public function __construct(Writable $output, $flavor = null)
66 66
     {
67
-        if (!($flavor instanceof Flavor)) $flavor = new Flavor($flavor);
67
+        if (!($flavor instanceof Flavor)) {
68
+            $flavor = new Flavor($flavor);
69
+        }
68 70
         $this->flavor = $flavor;
69 71
         $this->output = $output;
70 72
     }
@@ -96,7 +98,9 @@  discard block
 block discarded – undo
96 98
         if ($this->written) {
97 99
             throw new WriterException("Cannot set header row once data has already been written. ");
98 100
         }
99
-        if (is_array($headers)) $headers = new ArrayIterator($headers);
101
+        if (is_array($headers)) {
102
+            $headers = new ArrayIterator($headers);
103
+        }
100 104
         $this->headers = $headers;
101 105
     }
102 106
 
@@ -114,7 +118,9 @@  discard block
 block discarded – undo
114 118
             $headerRow = new HeaderRow((array) $this->headers);
115 119
             $this->writeHeaderRow($headerRow);
116 120
         }
117
-        if (is_array($row)) $row = new ArrayIterator($row);
121
+        if (is_array($row)) {
122
+            $row = new ArrayIterator($row);
123
+        }
118 124
         $row = $this->prepareRow($row);
119 125
         if ($count = $this->output->writeLine($row->join($delim), $eol)) {
120 126
             $this->written++;
@@ -139,7 +145,9 @@  discard block
 block discarded – undo
139 145
      */
140 146
     public function writeRows($rows)
141 147
     {
142
-        if (is_array($rows)) $rows = new ArrayIterator($rows);
148
+        if (is_array($rows)) {
149
+            $rows = new ArrayIterator($rows);
150
+        }
143 151
         if (!($rows instanceof Iterator)) {
144 152
             throw new InvalidArgumentException('First argument for ' . __METHOD__ . ' must be iterable');
145 153
         }
@@ -148,7 +156,9 @@  discard block
 block discarded – undo
148 156
             $this->writeHeaderRow($rows->header());
149 157
         }
150 158
         foreach ($rows as $row) {
151
-            if ($this->writeRow($row)) $written++;
159
+            if ($this->writeRow($row)) {
160
+                $written++;
161
+            }
152 162
         }
153 163
         return $written;
154 164
     }
@@ -225,7 +235,9 @@  discard block
 block discarded – undo
225 235
     {
226 236
         $flvr = $this->getFlavor();
227 237
         $escapeQuote = "";
228
-        if ($isQuoted) $escapeQuote = ($flvr->doubleQuote) ? $flvr->quoteChar : $flvr->escapeChar;
238
+        if ($isQuoted) {
239
+            $escapeQuote = ($flvr->doubleQuote) ? $flvr->quoteChar : $flvr->escapeChar;
240
+        }
229 241
         // @todo Not sure what else, if anything, I'm supposed to be escaping here..
230 242
         return str_replace($flvr->quoteChar, $escapeQuote . $flvr->quoteChar, $str);
231 243
     }
Please login to merge, or discard this patch.
src/CSVelte/Reader/FilteredIterator.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
src/CSVelte/Flavor.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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()
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -191,8 +191,9 @@
 block discarded – undo
191 191
      */
192 192
     protected function assertValidAttribute($attr)
193 193
     {
194
-        if (!property_exists(self::class, $attr))
195
-            throw new InvalidArgumentException("Unknown attribute: " . $attr);
194
+        if (!property_exists(self::class, $attr)) {
195
+                    throw new InvalidArgumentException("Unknown attribute: " . $attr);
196
+        }
196 197
     }
197 198
 
198 199
     /**
Please login to merge, or discard this patch.
src/CSVelte/Traits/IsReadable.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,9 @@
 block discarded – undo
45 45
     {
46 46
         $size = 0;
47 47
         $buffer = false;
48
-        if (!is_array($eol)) $eol = array($eol);
48
+        if (!is_array($eol)) {
49
+            $eol = array($eol);
50
+        }
49 51
         while (!$this->eof()) {
50 52
             // Using a loose equality here to match on '' and false.
51 53
             if (null == ($byte = $this->read(1))) {
Please login to merge, or discard this patch.