diff options
author | ignace nyamagana butera <nyamsprod@gmail.com> | 2016-02-15 09:06:28 +0100 |
---|---|---|
committer | ignace nyamagana butera <nyamsprod@gmail.com> | 2016-02-15 09:06:28 +0100 |
commit | 13c72e4fba8c12daf5d9b35115484a486a0bf16b (patch) | |
tree | 5ebf07e0bbd9e43940ee85ed262f2a485eaec64a /src | |
parent | 8f18ddedefff4d2ca5c09cc591cba4798d906c14 (diff) | |
download | csv-13c72e4fba8c12daf5d9b35115484a486a0bf16b.zip csv-13c72e4fba8c12daf5d9b35115484a486a0bf16b.tar.gz csv-13c72e4fba8c12daf5d9b35115484a486a0bf16b.tar.bz2 |
All properties are now camelCase
Diffstat (limited to 'src')
-rw-r--r-- | src/AbstractCsv.php | 46 | ||||
-rw-r--r-- | src/Config/Controls.php | 8 | ||||
-rw-r--r-- | src/Config/Output.php | 52 | ||||
-rw-r--r-- | src/Modifier/QueryFilter.php | 48 | ||||
-rw-r--r-- | src/Modifier/StreamFilter.php | 76 | ||||
-rw-r--r-- | src/Plugin/ColumnConsistencyValidator.php | 26 | ||||
-rw-r--r-- | src/Reader.php | 38 | ||||
-rw-r--r-- | src/Writer.php | 8 |
8 files changed, 150 insertions, 152 deletions
diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php index c9ac691..c1fc654 100644 --- a/src/AbstractCsv.php +++ b/src/AbstractCsv.php @@ -79,7 +79,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate * * @var string */ - protected $open_mode; + protected $openMode; /** * Creates a new instance @@ -88,12 +88,12 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate * an object that implements the `__toString` method * a path to a file * - * @param SplFileObject|string $path The file path - * @param string $open_mode The file open mode flag + * @param SplFileObject|string $path The file path + * @param string $openMode The file open mode flag */ - protected function __construct($path, $open_mode = 'r+') + protected function __construct($path, $openMode = 'r+') { - $this->open_mode = strtolower($open_mode); + $this->openMode = strtolower($openMode); $this->path = $path; $this->initStreamFilter($this->path); } @@ -156,14 +156,14 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate /** * Return a new {@link AbstractCsv} from a string * - * @param mixed $path file path - * @param string $open_mode the file open mode flag + * @param mixed $path file path + * @param string $openMode the file open mode flag * * @throws InvalidArgumentException If $path is a SplTempFileObject object * * @return static */ - public static function createFromPath($path, $open_mode = 'r+') + public static function createFromPath($path, $openMode = 'r+') { if ($path instanceof SplTempFileObject) { throw new InvalidArgumentException('an `SplTempFileObject` object does not contain a valid path'); @@ -173,26 +173,26 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate $path = $path->getPath().'/'.$path->getBasename(); } - return new static(static::validateString($path), $open_mode); + return new static(static::validateString($path), $openMode); } /** * Return a new {@link AbstractCsv} instance from another {@link AbstractCsv} object * - * @param string $class the class to be instantiated - * @param string $open_mode the file open mode flag + * @param string $class the class to be instantiated + * @param string $openMode the file open mode flag * * @return static */ - protected function newInstance($class, $open_mode) + protected function newInstance($class, $openMode) { - $csv = new $class($this->path, $open_mode); + $csv = new $class($this->path, $openMode); $csv->delimiter = $this->delimiter; $csv->enclosure = $this->enclosure; $csv->escape = $this->escape; - $csv->input_encoding = $this->input_encoding; - $csv->input_bom = $this->input_bom; - $csv->output_bom = $this->output_bom; + $csv->inputEncoding = $this->inputEncoding; + $csv->inputBom = $this->inputBom; + $csv->outputBom = $this->outputBom; $csv->newline = $this->newline; return $csv; @@ -201,25 +201,25 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate /** * Return a new {@link Writer} instance from a {@link AbstractCsv} object * - * @param string $open_mode the file open mode flag + * @param string $openMode the file open mode flag * * @return Writer */ - public function newWriter($open_mode = 'r+') + public function newWriter($openMode = 'r+') { - return $this->newInstance(Writer::class, $open_mode); + return $this->newInstance(Writer::class, $openMode); } /** * Return a new {@link Reader} instance from a {@link AbstractCsv} object * - * @param string $open_mode the file open mode flag + * @param string $openMode the file open mode flag * * @return Reader */ - public function newReader($open_mode = 'r+') + public function newReader($openMode = 'r+') { - return $this->newInstance(Reader::class, $open_mode); + return $this->newInstance(Reader::class, $openMode); } /** @@ -231,7 +231,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate { $iterator = $this->path; if (!$iterator instanceof SplFileObject) { - $iterator = new SplFileObject($this->getStreamFilterPath(), $this->open_mode); + $iterator = new SplFileObject($this->getStreamFilterPath(), $this->openMode); } $iterator->setCsvControl($this->delimiter, $this->enclosure, $this->escape); $iterator->setFlags(SplFileObject::READ_CSV | SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY); diff --git a/src/Config/Controls.php b/src/Config/Controls.php index bf1166e..454bcb0 100644 --- a/src/Config/Controls.php +++ b/src/Config/Controls.php @@ -102,13 +102,13 @@ trait Controls * a valid delimiter and each value the number of occurences * * @param string[] $delimiters the delimiters to consider - * @param int $nb_rows Detection is made using $nb_rows of the CSV + * @param int $nbRows Detection is made using $nbRows of the CSV * * @return array */ - public function fetchDelimitersOccurrence(array $delimiters, $nb_rows = 1) + public function fetchDelimitersOccurrence(array $delimiters, $nbRows = 1) { - $nb_rows = $this->validateInteger($nb_rows, 1, 'The number of rows to consider must be a valid positive integer'); + $nbRows = $this->validateInteger($nbRows, 1, 'The number of rows to consider must be a valid positive integer'); $filterRow = function ($row) { return is_array($row) && count($row) > 1; }; @@ -117,7 +117,7 @@ trait Controls $res = []; foreach ($delimiters as $delim) { $csv->setCsvControl($delim, $this->enclosure, $this->escape); - $iterator = new CallbackFilterIterator(new LimitIterator($csv, 0, $nb_rows), $filterRow); + $iterator = new CallbackFilterIterator(new LimitIterator($csv, 0, $nbRows), $filterRow); $res[$delim] = count(iterator_to_array($iterator, false), COUNT_RECURSIVE); } arsort($res, SORT_NUMERIC); diff --git a/src/Config/Output.php b/src/Config/Output.php index 6c0471f..29fd084 100644 --- a/src/Config/Output.php +++ b/src/Config/Output.php @@ -33,19 +33,19 @@ trait Output * * @var string */ - protected $input_encoding = 'UTF-8'; + protected $inputEncoding = 'UTF-8'; /** * The Input file BOM character * @var string */ - protected $input_bom; + protected $inputBom; /** * The Output file BOM character * @var string */ - protected $output_bom = ''; + protected $outputBom = ''; /** * Sets the CSV encoding charset @@ -61,7 +61,7 @@ trait Output if (empty($str)) { throw new InvalidArgumentException('you should use a valid charset'); } - $this->input_encoding = strtoupper($str); + $this->inputEncoding = strtoupper($str); return $this; } @@ -89,7 +89,7 @@ trait Output */ public function getInputEncoding() { - return $this->input_encoding; + return $this->inputEncoding; } /** @@ -103,7 +103,7 @@ trait Output */ public function getEncodingFrom() { - return $this->input_encoding; + return $this->inputEncoding; } /** @@ -116,12 +116,12 @@ trait Output public function setOutputBOM($str) { if (empty($str)) { - $this->output_bom = ''; + $this->outputBom = ''; return $this; } - $this->output_bom = (string) $str; + $this->outputBom = (string) $str; return $this; } @@ -133,7 +133,7 @@ trait Output */ public function getOutputBOM() { - return $this->output_bom; + return $this->outputBom; } /** @@ -143,7 +143,7 @@ trait Output */ public function getInputBOM() { - if (null === $this->input_bom) { + if (null === $this->inputBom) { $bom = [ AbstractCsv::BOM_UTF32_BE, AbstractCsv::BOM_UTF32_LE, AbstractCsv::BOM_UTF16_BE, AbstractCsv::BOM_UTF16_LE, AbstractCsv::BOM_UTF8, @@ -156,10 +156,10 @@ trait Output return strpos($line, $sequence) === 0; }); - $this->input_bom = (string) array_shift($res); + $this->inputBom = (string) array_shift($res); } - return $this->input_bom; + return $this->inputBom; } /** @@ -196,15 +196,15 @@ trait Output protected function fpassthru() { $bom = ''; - $input_bom = $this->getInputBOM(); - if ($this->output_bom && $input_bom != $this->output_bom) { - $bom = $this->output_bom; + $inputBom = $this->getInputBOM(); + if ($this->outputBom && $inputBom != $this->outputBom) { + $bom = $this->outputBom; } $csv = $this->getIterator(); $csv->setFlags(SplFileObject::READ_CSV); $csv->rewind(); if (!empty($bom)) { - $csv->fseek(mb_strlen($input_bom)); + $csv->fseek(mb_strlen($inputBom)); } echo $bom; $res = $csv->fpassthru(); @@ -249,12 +249,12 @@ trait Output */ protected function convertToUtf8(Iterator $iterator) { - if (stripos($this->input_encoding, 'UTF-8') !== false) { + if (stripos($this->inputEncoding, 'UTF-8') !== false) { return $iterator; } $convertCell = function ($value) { - return mb_convert_encoding($value, 'UTF-8', $this->input_encoding); + return mb_convert_encoding($value, 'UTF-8', $this->inputEncoding); }; $convertRow = function (array $row) use ($convertCell) { @@ -282,21 +282,21 @@ trait Output /** * Transforms a CSV into a XML * - * @param string $root_name XML root node name - * @param string $row_name XML row node name - * @param string $cell_name XML cell node name + * @param string $rootName XML root node name + * @param string $rowName XML row node name + * @param string $cellName XML cell node name * * @return DomDocument */ - public function toXML($root_name = 'csv', $row_name = 'row', $cell_name = 'cell') + public function toXML($rootName = 'csv', $rowName = 'row', $cellName = 'cell') { $doc = new DomDocument('1.0', 'UTF-8'); - $root = $doc->createElement($root_name); + $root = $doc->createElement($rootName); foreach ($this->convertToUtf8($this->getQueryIterator()) as $row) { - $rowElement = $doc->createElement($row_name); - array_walk($row, function ($value) use (&$rowElement, $doc, $cell_name) { + $rowElement = $doc->createElement($rowName); + array_walk($row, function ($value) use (&$rowElement, $doc, $cellName) { $content = $doc->createTextNode($value); - $cell = $doc->createElement($cell_name); + $cell = $doc->createElement($cellName); $cell->appendChild($content); $rowElement->appendChild($cell); }); diff --git a/src/Modifier/QueryFilter.php b/src/Modifier/QueryFilter.php index 72e9104..d28fd1f 100644 --- a/src/Modifier/QueryFilter.php +++ b/src/Modifier/QueryFilter.php @@ -31,35 +31,35 @@ trait QueryFilter * * @var callable[] */ - protected $iterator_filters = []; + protected $iteratorFilters = []; /** * Callables to sort the iterator * * @var callable[] */ - protected $iterator_sort_by = []; + protected $iteratorSortBy = []; /** * iterator Offset * * @var int */ - protected $iterator_offset = 0; + protected $iteratorOffset = 0; /** * iterator maximum length * * @var int */ - protected $iterator_limit = -1; + protected $iteratorLimit = -1; /** * Stripping BOM status * * @var boolean */ - protected $strip_bom = false; + protected $stripBom = false; /** * Stripping BOM setter @@ -70,7 +70,7 @@ trait QueryFilter */ public function stripBom($status) { - $this->strip_bom = (bool) $status; + $this->stripBom = (bool) $status; return $this; } @@ -89,7 +89,7 @@ trait QueryFilter */ public function setOffset($offset = 0) { - $this->iterator_offset = $this->validateInteger($offset, 0, 'the offset must be a positive integer or 0'); + $this->iteratorOffset = $this->validateInteger($offset, 0, 'the offset must be a positive integer or 0'); return $this; } @@ -108,7 +108,7 @@ trait QueryFilter */ public function setLimit($limit = -1) { - $this->iterator_limit = $this->validateInteger($limit, -1, 'the limit must an integer greater or equals to -1'); + $this->iteratorLimit = $this->validateInteger($limit, -1, 'the limit must an integer greater or equals to -1'); return $this; } @@ -122,7 +122,7 @@ trait QueryFilter */ public function addSortBy(callable $callable) { - $this->iterator_sort_by[] = $callable; + $this->iteratorSortBy[] = $callable; return $this; } @@ -136,7 +136,7 @@ trait QueryFilter */ public function addFilter(callable $callable) { - $this->iterator_filters[] = $callable; + $this->iteratorFilters[] = $callable; return $this; } @@ -156,7 +156,7 @@ trait QueryFilter $normalizedCsv = function ($row) { return is_array($row) && $row != [null]; }; - array_unshift($this->iterator_filters, $normalizedCsv); + array_unshift($this->iteratorFilters, $normalizedCsv); $iterator = $this->getIterator(); $iterator = $this->applyBomStripping($iterator); $iterator = $this->applyIteratorFilter($iterator); @@ -180,17 +180,17 @@ trait QueryFilter */ protected function applyBomStripping(Iterator $iterator) { - if (!$this->strip_bom) { + if (!$this->stripBom) { return $iterator; } if (!$this->isBomStrippable()) { - $this->strip_bom = false; + $this->stripBom = false; return $iterator; } - $this->strip_bom = false; + $this->stripBom = false; return $this->getStripBomIterator($iterator); } @@ -202,7 +202,7 @@ trait QueryFilter */ protected function isBomStrippable() { - return !empty($this->getInputBom()) && $this->strip_bom; + return !empty($this->getInputBom()) && $this->stripBom; } /** @@ -244,8 +244,8 @@ trait QueryFilter $reducer = function ($iterator, $callable) { return new CallbackFilterIterator($iterator, $callable); }; - $iterator = array_reduce($this->iterator_filters, $reducer, $iterator); - $this->iterator_filters = []; + $iterator = array_reduce($this->iteratorFilters, $reducer, $iterator); + $this->iteratorFilters = []; return $iterator; } @@ -259,14 +259,14 @@ trait QueryFilter */ protected function applyIteratorSortBy(Iterator $iterator) { - if (!$this->iterator_sort_by) { + if (!$this->iteratorSortBy) { return $iterator; } $obj = new ArrayObject(iterator_to_array($iterator)); $obj->uasort(function ($rowA, $rowB) { $res = 0; - foreach ($this->iterator_sort_by as $compareRows) { + foreach ($this->iteratorSortBy as $compareRows) { if (0 !== ($res = call_user_func($compareRows, $rowA, $rowB))) { break; } @@ -274,7 +274,7 @@ trait QueryFilter return $res; }); - $this->iterator_sort_by = []; + $this->iteratorSortBy = []; return $obj->getIterator(); } @@ -288,10 +288,10 @@ trait QueryFilter */ protected function applyIteratorInterval(Iterator $iterator) { - $offset = $this->iterator_offset; - $limit = $this->iterator_limit; - $this->iterator_limit = -1; - $this->iterator_offset = 0; + $offset = $this->iteratorOffset; + $limit = $this->iteratorLimit; + $this->iteratorLimit = -1; + $this->iteratorOffset = 0; return new LimitIterator($iterator, $offset, $limit); } diff --git a/src/Modifier/StreamFilter.php b/src/Modifier/StreamFilter.php index e07d2bc..e3f0600 100644 --- a/src/Modifier/StreamFilter.php +++ b/src/Modifier/StreamFilter.php @@ -30,14 +30,14 @@ trait StreamFilter * * @var array */ - protected $stream_filters = []; + protected $streamFilters = []; /** * Stream filtering mode to apply on all filters * * @var int */ - protected $stream_filter_mode = STREAM_FILTER_ALL; + protected $streamFilterMode = STREAM_FILTER_ALL; /** *the real path @@ -45,7 +45,7 @@ trait StreamFilter * @var string the real path to the file * */ - protected $stream_uri; + protected $streamUri; /** * PHP Stream Filter Regex @@ -70,21 +70,21 @@ trait StreamFilter */ protected function initStreamFilter($path) { - $this->stream_filters = []; + $this->streamFilters = []; if (!is_string($path)) { - $this->stream_uri = null; + $this->streamUri = null; return; } if (!preg_match($this->stream_regex, $path, $matches)) { - $this->stream_uri = $path; + $this->streamUri = $path; return; } - $this->stream_uri = $matches['resource']; - $this->stream_filters = array_map('urldecode', explode('|', $matches['filters'])); - $this->stream_filter_mode = $this->fetchStreamModeAsInt($matches['mode']); + $this->streamUri = $matches['resource']; + $this->streamFilters = array_map('urldecode', explode('|', $matches['filters'])); + $this->streamFilterMode = $this->fetchStreamModeAsInt($matches['mode']); } /** @@ -116,7 +116,7 @@ trait StreamFilter */ protected function assertStreamable() { - if (!is_string($this->stream_uri)) { + if (!is_string($this->streamUri)) { throw new LogicException('The stream filter API can not be used'); } } @@ -128,7 +128,7 @@ trait StreamFilter */ public function isActiveStreamFilter() { - return is_string($this->stream_uri); + return is_string($this->streamUri); } /** @@ -150,8 +150,8 @@ trait StreamFilter throw new OutOfBoundsException('the $mode should be a valid `STREAM_FILTER_*` constant'); } - $this->stream_filter_mode = $mode; - $this->stream_filters = []; + $this->streamFilterMode = $mode; + $this->streamFilters = []; return $this; } @@ -165,20 +165,20 @@ trait StreamFilter { $this->assertStreamable(); - return $this->stream_filter_mode; + return $this->streamFilterMode; } /** * append a stream filter * - * @param string $filter_name a string or an object that implements the '__toString' method + * @param string $filterName a string or an object that implements the '__toString' method * * @return $this */ - public function appendStreamFilter($filter_name) + public function appendStreamFilter($filterName) { $this->assertStreamable(); - $this->stream_filters[] = $this->sanitizeStreamFilter($filter_name); + $this->streamFilters[] = $this->sanitizeStreamFilter($filterName); return $this; } @@ -186,14 +186,14 @@ trait StreamFilter /** * prepend a stream filter * - * @param string $filter_name a string or an object that implements the '__toString' method + * @param string $filterName a string or an object that implements the '__toString' method * * @return $this */ - public function prependStreamFilter($filter_name) + public function prependStreamFilter($filterName) { $this->assertStreamable(); - array_unshift($this->stream_filters, $this->sanitizeStreamFilter($filter_name)); + array_unshift($this->streamFilters, $this->sanitizeStreamFilter($filterName)); return $this; } @@ -201,15 +201,13 @@ trait StreamFilter /** * Sanitize the stream filter name * - * @param string $filter_name the stream filter name + * @param string $filterName the stream filter name * * @return string */ - protected function sanitizeStreamFilter($filter_name) + protected function sanitizeStreamFilter($filterName) { - $this->assertStreamable(); - - return urldecode($this->validateString($filter_name)); + return urldecode($this->validateString($filterName)); } /** @@ -220,30 +218,30 @@ trait StreamFilter /** * Detect if the stream filter is already present * - * @param string $filter_name + * @param string $filterName * * @return bool */ - public function hasStreamFilter($filter_name) + public function hasStreamFilter($filterName) { $this->assertStreamable(); - return false !== array_search(urldecode($filter_name), $this->stream_filters, true); + return false !== array_search(urldecode($filterName), $this->streamFilters, true); } /** * Remove a filter from the collection * - * @param string $filter_name + * @param string $filterName * * @return $this */ - public function removeStreamFilter($filter_name) + public function removeStreamFilter($filterName) { $this->assertStreamable(); - $res = array_search(urldecode($filter_name), $this->stream_filters, true); + $res = array_search(urldecode($filterName), $this->streamFilters, true); if (false !== $res) { - unset($this->stream_filters[$res]); + unset($this->streamFilters[$res]); } return $this; @@ -257,7 +255,7 @@ trait StreamFilter public function clearStreamFilter() { $this->assertStreamable(); - $this->stream_filters = []; + $this->streamFilters = []; return $this; } @@ -270,14 +268,14 @@ trait StreamFilter protected function getStreamFilterPath() { $this->assertStreamable(); - if (!$this->stream_filters) { - return $this->stream_uri; + if (!$this->streamFilters) { + return $this->streamUri; } return 'php://filter/' .$this->getStreamFilterPrefix() - .implode('|', array_map('urlencode', $this->stream_filters)) - .'/resource='.$this->stream_uri; + .implode('|', array_map('urlencode', $this->streamFilters)) + .'/resource='.$this->streamUri; } /** @@ -287,11 +285,11 @@ trait StreamFilter */ protected function getStreamFilterPrefix() { - if (STREAM_FILTER_READ == $this->stream_filter_mode) { + if (STREAM_FILTER_READ == $this->streamFilterMode) { return 'read='; } - if (STREAM_FILTER_WRITE == $this->stream_filter_mode) { + if (STREAM_FILTER_WRITE == $this->streamFilterMode) { return 'write='; } diff --git a/src/Plugin/ColumnConsistencyValidator.php b/src/Plugin/ColumnConsistencyValidator.php index c0bf74f..69dcced 100644 --- a/src/Plugin/ColumnConsistencyValidator.php +++ b/src/Plugin/ColumnConsistencyValidator.php @@ -28,14 +28,14 @@ class ColumnConsistencyValidator * * @var int */ - private $columns_count = -1; + private $columnsCount = -1; /** * should the class detect the column count based the inserted row * * @var bool */ - private $detect_columns_count = false; + private $detectColumnsCount = false; /** * Set Inserted row column count @@ -50,8 +50,8 @@ class ColumnConsistencyValidator if (false === filter_var($value, FILTER_VALIDATE_INT, ['options' => ['min_range' => -1]])) { throw new InvalidArgumentException('the column count must an integer greater or equals to -1'); } - $this->detect_columns_count = false; - $this->columns_count = $value; + $this->detectColumnsCount = false; + $this->columnsCount = $value; } /** @@ -61,18 +61,18 @@ class ColumnConsistencyValidator */ public function getColumnsCount() { - return $this->columns_count; + return $this->columnsCount; } /** - * The method will set the $columns_count property according to the next inserted row + * The method will set the $columnsCount property according to the next inserted row * and therefore will also validate the next line whatever length it has no matter - * the current $columns_count property value. + * the current $columnsCount property value. * */ public function autodetectColumnsCount() { - $this->detect_columns_count = true; + $this->detectColumnsCount = true; } /** @@ -84,17 +84,17 @@ class ColumnConsistencyValidator */ public function __invoke(array $row) { - if ($this->detect_columns_count) { - $this->columns_count = count($row); - $this->detect_columns_count = false; + if ($this->detectColumnsCount) { + $this->columnsCount = count($row); + $this->detectColumnsCount = false; return true; } - if (-1 == $this->columns_count) { + if (-1 == $this->columnsCount) { return true; } - return count($row) == $this->columns_count; + return count($row) == $this->columnsCount; } } diff --git a/src/Reader.php b/src/Reader.php index 6aee834..14b0cec 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -31,7 +31,7 @@ class Reader extends AbstractCsv /** * @inheritdoc */ - protected $stream_filter_mode = STREAM_FILTER_READ; + protected $streamFilterMode = STREAM_FILTER_READ; /** * Returns a sequential array of all CSV lines @@ -233,8 +233,8 @@ class Reader extends AbstractCsv * The rows are presented as associated arrays * The callable function will be applied to each row * - * @param int|array $offset_or_keys the name for each key member OR the row Index to be - * used as the associated named keys + * @param int|array $offsetOrKeys the name for each key member OR the row Index to be + * used as the associated named keys * * @param callable $callable A callable to be applied to each of the rows to be returned. * @@ -242,13 +242,13 @@ class Reader extends AbstractCsv * * @return Iterator */ - public function fetchAssoc($offset_or_keys = 0, callable $callable = null) + public function fetchAssoc($offsetOrKeys = 0, callable $callable = null) { - $keys = $this->getAssocKeys($offset_or_keys); - $keys_count = count($keys); - $combineArray = function (array $row) use ($keys, $keys_count) { - if ($keys_count != count($row)) { - $row = array_slice(array_pad($row, $keys_count, null), 0, $keys_count); + $keys = $this->getAssocKeys($offsetOrKeys); + $keysCount = count($keys); + $combineArray = function (array $row) use ($keys, $keysCount) { + if ($keysCount != count($row)) { + $row = array_slice(array_pad($row, $keysCount, null), 0, $keysCount); } return array_combine($keys, $row); @@ -263,27 +263,27 @@ class Reader extends AbstractCsv /** * Selects the array to be used as key for the fetchAssoc method * - * @param int|array $offset_or_keys the assoc key OR the row Index to be used - * as the key index + * @param int|array $offsetOrKeys the assoc key OR the row Index to be used + * as the key index * * @throws InvalidArgumentException If the row index and/or the resulting array is invalid * * @return array */ - protected function getAssocKeys($offset_or_keys) + protected function getAssocKeys($offsetOrKeys) { - if (is_array($offset_or_keys)) { - return $this->validateKeys($offset_or_keys); + if (is_array($offsetOrKeys)) { + return $this->validateKeys($offsetOrKeys); } - $offset_or_keys = $this->validateInteger( - $offset_or_keys, + $offsetOrKeys = $this->validateInteger( + $offsetOrKeys, 0, 'the row index must be a positive integer, 0 or a non empty array' ); - $keys = $this->validateKeys($this->getRow($offset_or_keys)); - $filterOutRow = function ($row, $rowIndex) use ($offset_or_keys) { - return $rowIndex != $offset_or_keys; + $keys = $this->validateKeys($this->getRow($offsetOrKeys)); + $filterOutRow = function ($row, $rowIndex) use ($offsetOrKeys) { + return $rowIndex != $offsetOrKeys; }; $this->addFilter($filterOutRow); diff --git a/src/Writer.php b/src/Writer.php index a35af37..19f20b1 100644 --- a/src/Writer.php +++ b/src/Writer.php @@ -32,7 +32,7 @@ class Writer extends AbstractCsv /** * @inheritdoc */ - protected $stream_filter_mode = STREAM_FILTER_WRITE; + protected $streamFilterMode = STREAM_FILTER_WRITE; /** * The CSV object holder @@ -53,7 +53,7 @@ class Writer extends AbstractCsv * * @var integer */ - protected static $fputcsv_param_count; + protected static $fputcsvParamsCount; /** * @inheritdoc @@ -71,7 +71,7 @@ class Writer extends AbstractCsv { if (null === static::$fputcsv) { static::$fputcsv = new ReflectionMethod('\SplFileObject', 'fputcsv'); - static::$fputcsv_param_count = static::$fputcsv->getNumberOfParameters(); + static::$fputcsvParamsCount = static::$fputcsv->getNumberOfParameters(); } } @@ -139,7 +139,7 @@ class Writer extends AbstractCsv protected function getFputcsvParameters(array $fields) { $parameters = [$fields, $this->delimiter, $this->enclosure]; - if (4 == static::$fputcsv_param_count) { + if (4 == static::$fputcsvParamsCount) { $parameters[] = $this->escape; } |