@@ -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 | * |
@@ -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 | } |
@@ -64,7 +64,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -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 | /** |
@@ -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; |
@@ -138,7 +138,9 @@ |
||
| 138 | 138 | public function readChunk($start = null, $length = null) |
| 139 | 139 | { |
| 140 | 140 | //dd($this->buffer, false); |
| 141 | - if ($this->buffer === false) return false; |
|
| 141 | + if ($this->buffer === false) { |
|
| 142 | + return false; |
|
| 143 | + } |
|
| 142 | 144 | $top = substr($this->buffer, 0, $start); |
| 143 | 145 | $data = substr($this->buffer, $start, $length); |
| 144 | 146 | $bottom = substr($this->buffer, $start + $length); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * Read in the specified amount of characters from the input source |
| 120 | 120 | * |
| 121 | 121 | * @param integer Amount of characters to read from input source |
| 122 | - * @return string|boolean The specified amount of characters read from input source |
|
| 122 | + * @return false|string The specified amount of characters read from input source |
|
| 123 | 123 | */ |
| 124 | 124 | public function read($chars) |
| 125 | 125 | { |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * |
| 247 | 247 | * After the stream has been detached, the stream is in an unusable state. |
| 248 | 248 | * |
| 249 | - * @return BufferStream|null Underlying PHP stream, if any |
|
| 249 | + * @return string Underlying PHP stream, if any |
|
| 250 | 250 | */ |
| 251 | 251 | public function detach() |
| 252 | 252 | { |
@@ -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 | } |
@@ -153,8 +153,9 @@ discard block |
||
| 153 | 153 | } |
| 154 | 154 | } else { |
| 155 | 155 | if (is_null($key)) { |
| 156 | - if (is_array($val)) return $this->merge($val); |
|
| 157 | - else { |
|
| 156 | + if (is_array($val)) { |
|
| 157 | + return $this->merge($val); |
|
| 158 | + } else { |
|
| 158 | 159 | if (is_callable($val)) { |
| 159 | 160 | return $this->map($val); |
| 160 | 161 | } /*else { |
@@ -248,7 +249,9 @@ discard block |
||
| 248 | 249 | { |
| 249 | 250 | if (is_callable($callback = $val)) { |
| 250 | 251 | foreach ($this->data as $key => $val) { |
| 251 | - if ($callback($val, $key)) return true; |
|
| 252 | + if ($callback($val, $key)) { |
|
| 253 | + return true; |
|
| 254 | + } |
|
| 252 | 255 | } |
| 253 | 256 | } elseif (in_array($val, $this->data)) { |
| 254 | 257 | return (is_null($key) || (isset($this->data[$key]) && $this->data[$key] == $val)); |
@@ -366,7 +369,9 @@ discard block |
||
| 366 | 369 | { |
| 367 | 370 | $i = 0; |
| 368 | 371 | foreach ($this->data as $key => $val) { |
| 369 | - if ($i === $pos) return $key; |
|
| 372 | + if ($i === $pos) { |
|
| 373 | + return $key; |
|
| 374 | + } |
|
| 370 | 375 | $i++; |
| 371 | 376 | } |
| 372 | 377 | throw new OutOfBoundsException("Collection data does not contain a key at given position: " . $pos); |
@@ -744,7 +749,9 @@ discard block |
||
| 744 | 749 | { |
| 745 | 750 | foreach ($this->data as $key => $val) { |
| 746 | 751 | if (!$ret = $callback($val, $key)) { |
| 747 | - if ($ret === false) break; |
|
| 752 | + if ($ret === false) { |
|
| 753 | + break; |
|
| 754 | + } |
|
| 748 | 755 | } |
| 749 | 756 | } |
| 750 | 757 | return $this; |
@@ -776,7 +783,9 @@ discard block |
||
| 776 | 783 | { |
| 777 | 784 | $keys = []; |
| 778 | 785 | foreach ($this->data as $key => $val) { |
| 779 | - if (false === $callback($val, $key)) $keys[$key] = true; |
|
| 786 | + if (false === $callback($val, $key)) { |
|
| 787 | + $keys[$key] = true; |
|
| 788 | + } |
|
| 780 | 789 | } |
| 781 | 790 | return new self(array_diff_key($this->data, $keys)); |
| 782 | 791 | } |
@@ -793,7 +802,9 @@ discard block |
||
| 793 | 802 | public function first(Callable $callback) |
| 794 | 803 | { |
| 795 | 804 | foreach ($this->data as $key => $val) { |
| 796 | - if ($callback($val, $key)) return $val; |
|
| 805 | + if ($callback($val, $key)) { |
|
| 806 | + return $val; |
|
| 807 | + } |
|
| 797 | 808 | } |
| 798 | 809 | return null; |
| 799 | 810 | } |
@@ -811,7 +822,9 @@ discard block |
||
| 811 | 822 | { |
| 812 | 823 | $elem = null; |
| 813 | 824 | foreach ($this->data as $key => $val) { |
| 814 | - if ($callback($val, $key)) $elem = $val; |
|
| 825 | + if ($callback($val, $key)) { |
|
| 826 | + $elem = $val; |
|
| 827 | + } |
|
| 815 | 828 | } |
| 816 | 829 | return $elem; |
| 817 | 830 | } |
@@ -1062,7 +1075,9 @@ discard block |
||
| 1062 | 1075 | */ |
| 1063 | 1076 | public function sort(Callable $callback = null, $preserve_keys = true) |
| 1064 | 1077 | { |
| 1065 | - if (is_null($callback)) $callback = 'strcasecmp'; |
|
| 1078 | + if (is_null($callback)) { |
|
| 1079 | + $callback = 'strcasecmp'; |
|
| 1080 | + } |
|
| 1066 | 1081 | if (!is_callable($callback)) { |
| 1067 | 1082 | throw new InvalidArgumentException(sprintf( |
| 1068 | 1083 | 'Invalid argument supplied for %s. Expected %s, got: "%s".', |
@@ -1172,7 +1187,9 @@ discard block |
||
| 1172 | 1187 | |
| 1173 | 1188 | // if the list of array keys is shorter than the total amount of items in |
| 1174 | 1189 | // the collection, than this is not tabular data |
| 1175 | - if (count($test) != count($this)) return false; |
|
| 1190 | + if (count($test) != count($this)) { |
|
| 1191 | + return false; |
|
| 1192 | + } |
|
| 1176 | 1193 | |
| 1177 | 1194 | // loop through the array of each item's array keys that we just created |
| 1178 | 1195 | // and compare it to the FIRST item. If any array contains different keys |
@@ -1180,7 +1197,9 @@ discard block |
||
| 1180 | 1197 | $first = array_shift($test); |
| 1181 | 1198 | foreach ($test as $key => $keys) { |
| 1182 | 1199 | $diff = array_diff($first, $keys); |
| 1183 | - if (!empty($diff)) return false; |
|
| 1200 | + if (!empty($diff)) { |
|
| 1201 | + return false; |
|
| 1202 | + } |
|
| 1184 | 1203 | } |
| 1185 | 1204 | return true; |
| 1186 | 1205 | } |
@@ -91,7 +91,9 @@ |
||
| 91 | 91 | { |
| 92 | 92 | $res = (new Resource($uri, $mode)) |
| 93 | 93 | ->setContextResource($context); |
| 94 | - if (!$lazy) $res->connect(); |
|
| 94 | + if (!$lazy) { |
|
| 95 | + $res->connect(); |
|
| 96 | + } |
|
| 95 | 97 | return $res; |
| 96 | 98 | } |
| 97 | 99 | |
@@ -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; |
@@ -259,7 +259,7 @@ |
||
| 259 | 259 | /** |
| 260 | 260 | * Closes the stream and any underlying resources. |
| 261 | 261 | * |
| 262 | - * @return void |
|
| 262 | + * @return boolean |
|
| 263 | 263 | */ |
| 264 | 264 | public function close() |
| 265 | 265 | { |