summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorignace nyamagana butera <nyamsprod@gmail.com>2016-05-23 10:06:05 +0200
committerignace nyamagana butera <nyamsprod@gmail.com>2016-05-23 10:22:11 +0200
commit86821ef8fb3d7b351983e6ed524b737e1afde6aa (patch)
tree00bb14dd3cd950a4d17c75b7034da8abc0290c46
parent6bc786825aa0d71c51ce3218ac265e01651b8603 (diff)
downloadcsv-86821ef8fb3d7b351983e6ed524b737e1afde6aa.zip
csv-86821ef8fb3d7b351983e6ed524b737e1afde6aa.tar.gz
csv-86821ef8fb3d7b351983e6ed524b737e1afde6aa.tar.bz2
Adding an autoloader script
-rw-r--r--CHANGELOG.md2
-rw-r--r--autoload.php21
-rw-r--r--src/AbstractCsv.php46
-rw-r--r--src/Config/Controls.php10
-rw-r--r--src/Config/Output.php60
-rw-r--r--src/Modifier/QueryFilter.php60
-rw-r--r--src/Modifier/StreamFilter.php74
-rw-r--r--src/Plugin/ColumnConsistencyValidator.php26
-rw-r--r--src/Reader.php96
-rw-r--r--src/Writer.php8
10 files changed, 213 insertions, 190 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0eee0b8..194ad34 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ All Notable changes to `Csv` will be documented in this file
### Added
+- The package now includes its own autoloader.
- `Ouput::getInputEncoding`
- `Ouput::setInputEncoding`
@@ -17,6 +18,7 @@ All Notable changes to `Csv` will be documented in this file
### Fixed
- Stream Filters are now url encoded before usage [issue #72](https://github.com/thephpleague/csv/issues/72)
+- All parameters are now using the snake case format
### Removed
diff --git a/autoload.php b/autoload.php
new file mode 100644
index 0000000..d9f9e3c
--- /dev/null
+++ b/autoload.php
@@ -0,0 +1,21 @@
+<?php
+
+spl_autoload_register(function ($class) {
+
+ $prefix = 'League\Csv\\';
+ if (0 !== strpos($class, $prefix)) {
+ return;
+ }
+
+ $file = __DIR__
+ .DIRECTORY_SEPARATOR
+ .'src'
+ .DIRECTORY_SEPARATOR
+ .str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen($prefix)))
+ .'.php';
+ if (!is_readable($file)) {
+ return;
+ }
+
+ require $file;
+});
diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php
index c1fc654..c9ac691 100644
--- a/src/AbstractCsv.php
+++ b/src/AbstractCsv.php
@@ -79,7 +79,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
*
* @var string
*/
- protected $openMode;
+ protected $open_mode;
/**
* 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 $openMode The file open mode flag
+ * @param SplFileObject|string $path The file path
+ * @param string $open_mode The file open mode flag
*/
- protected function __construct($path, $openMode = 'r+')
+ protected function __construct($path, $open_mode = 'r+')
{
- $this->openMode = strtolower($openMode);
+ $this->open_mode = strtolower($open_mode);
$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 $openMode the file open mode flag
+ * @param mixed $path file path
+ * @param string $open_mode the file open mode flag
*
* @throws InvalidArgumentException If $path is a SplTempFileObject object
*
* @return static
*/
- public static function createFromPath($path, $openMode = 'r+')
+ public static function createFromPath($path, $open_mode = '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), $openMode);
+ return new static(static::validateString($path), $open_mode);
}
/**
* Return a new {@link AbstractCsv} instance from another {@link AbstractCsv} object
*
- * @param string $class the class to be instantiated
- * @param string $openMode the file open mode flag
+ * @param string $class the class to be instantiated
+ * @param string $open_mode the file open mode flag
*
* @return static
*/
- protected function newInstance($class, $openMode)
+ protected function newInstance($class, $open_mode)
{
- $csv = new $class($this->path, $openMode);
+ $csv = new $class($this->path, $open_mode);
$csv->delimiter = $this->delimiter;
$csv->enclosure = $this->enclosure;
$csv->escape = $this->escape;
- $csv->inputEncoding = $this->inputEncoding;
- $csv->inputBom = $this->inputBom;
- $csv->outputBom = $this->outputBom;
+ $csv->input_encoding = $this->input_encoding;
+ $csv->input_bom = $this->input_bom;
+ $csv->output_bom = $this->output_bom;
$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 $openMode the file open mode flag
+ * @param string $open_mode the file open mode flag
*
* @return Writer
*/
- public function newWriter($openMode = 'r+')
+ public function newWriter($open_mode = 'r+')
{
- return $this->newInstance(Writer::class, $openMode);
+ return $this->newInstance(Writer::class, $open_mode);
}
/**
* Return a new {@link Reader} instance from a {@link AbstractCsv} object
*
- * @param string $openMode the file open mode flag
+ * @param string $open_mode the file open mode flag
*
* @return Reader
*/
- public function newReader($openMode = 'r+')
+ public function newReader($open_mode = 'r+')
{
- return $this->newInstance(Reader::class, $openMode);
+ return $this->newInstance(Reader::class, $open_mode);
}
/**
@@ -231,7 +231,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
{
$iterator = $this->path;
if (!$iterator instanceof SplFileObject) {
- $iterator = new SplFileObject($this->getStreamFilterPath(), $this->openMode);
+ $iterator = new SplFileObject($this->getStreamFilterPath(), $this->open_mode);
}
$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 454bcb0..c68429c 100644
--- a/src/Config/Controls.php
+++ b/src/Config/Controls.php
@@ -102,14 +102,14 @@ trait Controls
* a valid delimiter and each value the number of occurences
*
* @param string[] $delimiters the delimiters to consider
- * @param int $nbRows Detection is made using $nbRows of the CSV
+ * @param int $nb_rows Detection is made using $nb_rows of the CSV
*
* @return array
*/
- public function fetchDelimitersOccurrence(array $delimiters, $nbRows = 1)
+ public function fetchDelimitersOccurrence(array $delimiters, $nb_rows = 1)
{
- $nbRows = $this->validateInteger($nbRows, 1, 'The number of rows to consider must be a valid positive integer');
- $filterRow = function ($row) {
+ $nb_rows = $this->validateInteger($nb_rows, 1, 'The number of rows to consider must be a valid positive integer');
+ $filter_row = function ($row) {
return is_array($row) && count($row) > 1;
};
$delimiters = array_unique(array_filter($delimiters, [$this, 'isValidCsvControls']));
@@ -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, $nbRows), $filterRow);
+ $iterator = new CallbackFilterIterator(new LimitIterator($csv, 0, $nb_rows), $filter_row);
$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 abbaf84..8db93bb 100644
--- a/src/Config/Output.php
+++ b/src/Config/Output.php
@@ -33,19 +33,19 @@ trait Output
*
* @var string
*/
- protected $inputEncoding = 'UTF-8';
+ protected $input_encoding = 'UTF-8';
/**
* The Input file BOM character
* @var string
*/
- protected $inputBom;
+ protected $input_bom;
/**
* The Output file BOM character
* @var string
*/
- protected $outputBom = '';
+ protected $output_bom = '';
/**
* Sets the CSV encoding charset
@@ -61,7 +61,7 @@ trait Output
if (empty($str)) {
throw new InvalidArgumentException('you should use a valid charset');
}
- $this->inputEncoding = strtoupper($str);
+ $this->input_encoding = strtoupper($str);
return $this;
}
@@ -89,7 +89,7 @@ trait Output
*/
public function getInputEncoding()
{
- return $this->inputEncoding;
+ return $this->input_encoding;
}
/**
@@ -103,7 +103,7 @@ trait Output
*/
public function getEncodingFrom()
{
- return $this->inputEncoding;
+ return $this->input_encoding;
}
/**
@@ -116,12 +116,12 @@ trait Output
public function setOutputBOM($str)
{
if (empty($str)) {
- $this->outputBom = '';
+ $this->output_bom = '';
return $this;
}
- $this->outputBom = (string) $str;
+ $this->output_bom = (string) $str;
return $this;
}
@@ -133,7 +133,7 @@ trait Output
*/
public function getOutputBOM()
{
- return $this->outputBom;
+ return $this->output_bom;
}
/**
@@ -143,7 +143,7 @@ trait Output
*/
public function getInputBOM()
{
- if (null === $this->inputBom) {
+ if (null === $this->input_bom) {
$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->inputBom = (string) array_shift($res);
+ $this->input_bom = (string) array_shift($res);
}
- return $this->inputBom;
+ return $this->input_bom;
}
/**
@@ -196,15 +196,15 @@ trait Output
protected function fpassthru()
{
$bom = '';
- $inputBom = $this->getInputBOM();
- if ($this->outputBom && $inputBom != $this->outputBom) {
- $bom = $this->outputBom;
+ $input_bom = $this->getInputBOM();
+ if ($this->output_bom && $input_bom != $this->output_bom) {
+ $bom = $this->output_bom;
}
$csv = $this->getIterator();
$csv->setFlags(SplFileObject::READ_CSV);
$csv->rewind();
if (!empty($bom)) {
- $csv->fseek(mb_strlen($inputBom));
+ $csv->fseek(mb_strlen($input_bom));
}
echo $bom;
$res = $csv->fpassthru();
@@ -249,19 +249,19 @@ trait Output
*/
protected function convertToUtf8(Iterator $iterator)
{
- if (stripos($this->inputEncoding, 'UTF-8') !== false) {
+ if (stripos($this->input_encoding, 'UTF-8') !== false) {
return $iterator;
}
- $convertCell = function ($value) {
- return mb_convert_encoding($value, 'UTF-8', $this->inputEncoding);
+ $convert_cell = function ($value) {
+ return mb_convert_encoding($value, 'UTF-8', $this->input_encoding);
};
- $convertRow = function (array $row) use ($convertCell) {
- return array_map($convertCell, $row);
+ $convert_row = function (array $row) use ($convert_cell) {
+ return array_map($convert_cell, $row);
};
- return new MapIterator($iterator, $convertRow);
+ return new MapIterator($iterator, $convert_row);
}
/**
@@ -282,21 +282,21 @@ trait Output
/**
* Transforms a CSV into a XML
*
- * @param string $rootName XML root node name
- * @param string $rowName XML row node name
- * @param string $cellName XML cell node name
+ * @param string $root_name XML root node name
+ * @param string $row_name XML row node name
+ * @param string $cell_name XML cell node name
*
* @return DomDocument
*/
- public function toXML($rootName = 'csv', $rowName = 'row', $cellName = 'cell')
+ public function toXML($root_name = 'csv', $row_name = 'row', $cell_name = 'cell')
{
$doc = new DomDocument('1.0', 'UTF-8');
- $root = $doc->createElement($rootName);
+ $root = $doc->createElement($root_name);
foreach ($this->convertToUtf8($this->getQueryIterator()) as $row) {
- $rowElement = $doc->createElement($rowName);
- array_walk($row, function ($value) use (&$rowElement, $doc, $cellName) {
+ $rowElement = $doc->createElement($row_name);
+ array_walk($row, function ($value) use (&$rowElement, $doc, $cell_name) {
$content = $doc->createTextNode($value);
- $cell = $doc->createElement($cellName);
+ $cell = $doc->createElement($cell_name);
$cell->appendChild($content);
$rowElement->appendChild($cell);
});
diff --git a/src/Modifier/QueryFilter.php b/src/Modifier/QueryFilter.php
index d28fd1f..32ba957 100644
--- a/src/Modifier/QueryFilter.php
+++ b/src/Modifier/QueryFilter.php
@@ -31,35 +31,35 @@ trait QueryFilter
*
* @var callable[]
*/
- protected $iteratorFilters = [];
+ protected $iterator_filters = [];
/**
* Callables to sort the iterator
*
* @var callable[]
*/
- protected $iteratorSortBy = [];
+ protected $iterator_sort_by = [];
/**
* iterator Offset
*
* @var int
*/
- protected $iteratorOffset = 0;
+ protected $iterator_offset = 0;
/**
* iterator maximum length
*
* @var int
*/
- protected $iteratorLimit = -1;
+ protected $iterator_limit = -1;
/**
* Stripping BOM status
*
* @var boolean
*/
- protected $stripBom = false;
+ protected $strip_bom = false;
/**
* Stripping BOM setter
@@ -70,7 +70,7 @@ trait QueryFilter
*/
public function stripBom($status)
{
- $this->stripBom = (bool) $status;
+ $this->strip_bom = (bool) $status;
return $this;
}
@@ -89,7 +89,7 @@ trait QueryFilter
*/
public function setOffset($offset = 0)
{
- $this->iteratorOffset = $this->validateInteger($offset, 0, 'the offset must be a positive integer or 0');
+ $this->iterator_offset = $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->iteratorLimit = $this->validateInteger($limit, -1, 'the limit must an integer greater or equals to -1');
+ $this->iterator_limit = $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->iteratorSortBy[] = $callable;
+ $this->iterator_sort_by[] = $callable;
return $this;
}
@@ -136,7 +136,7 @@ trait QueryFilter
*/
public function addFilter(callable $callable)
{
- $this->iteratorFilters[] = $callable;
+ $this->iterator_filters[] = $callable;
return $this;
}
@@ -156,7 +156,7 @@ trait QueryFilter
$normalizedCsv = function ($row) {
return is_array($row) && $row != [null];
};
- array_unshift($this->iteratorFilters, $normalizedCsv);
+ array_unshift($this->iterator_filters, $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->stripBom) {
+ if (!$this->strip_bom) {
return $iterator;
}
if (!$this->isBomStrippable()) {
- $this->stripBom = false;
+ $this->strip_bom = false;
return $iterator;
}
- $this->stripBom = false;
+ $this->strip_bom = false;
return $this->getStripBomIterator($iterator);
}
@@ -202,7 +202,7 @@ trait QueryFilter
*/
protected function isBomStrippable()
{
- return !empty($this->getInputBom()) && $this->stripBom;
+ return !empty($this->getInputBom()) && $this->strip_bom;
}
/**
@@ -214,14 +214,14 @@ trait QueryFilter
*/
protected function getStripBomIterator(Iterator $iterator)
{
- $bomLength = mb_strlen($this->getInputBom());
+ $bom_length = mb_strlen($this->getInputBom());
$enclosure = $this->getEnclosure();
- $stripBom = function ($row, $index) use ($bomLength, $enclosure) {
+ $strip_bom = function ($row, $index) use ($bom_length, $enclosure) {
if (0 != $index) {
return $row;
}
- $row[0] = mb_substr($row[0], $bomLength);
+ $row[0] = mb_substr($row[0], $bom_length);
if ($row[0][0] === $enclosure && mb_substr($row[0], -1, 1) === $enclosure) {
$row[0] = mb_substr($row[0], 1, -1);
}
@@ -229,7 +229,7 @@ trait QueryFilter
return $row;
};
- return new MapIterator($iterator, $stripBom);
+ return new MapIterator($iterator, $strip_bom);
}
/**
@@ -244,8 +244,8 @@ trait QueryFilter
$reducer = function ($iterator, $callable) {
return new CallbackFilterIterator($iterator, $callable);
};
- $iterator = array_reduce($this->iteratorFilters, $reducer, $iterator);
- $this->iteratorFilters = [];
+ $iterator = array_reduce($this->iterator_filters, $reducer, $iterator);
+ $this->iterator_filters = [];
return $iterator;
}
@@ -259,22 +259,22 @@ trait QueryFilter
*/
protected function applyIteratorSortBy(Iterator $iterator)
{
- if (!$this->iteratorSortBy) {
+ if (!$this->iterator_sort_by) {
return $iterator;
}
$obj = new ArrayObject(iterator_to_array($iterator));
- $obj->uasort(function ($rowA, $rowB) {
+ $obj->uasort(function ($row_a, $row_b) {
$res = 0;
- foreach ($this->iteratorSortBy as $compareRows) {
- if (0 !== ($res = call_user_func($compareRows, $rowA, $rowB))) {
+ foreach ($this->iterator_sort_by as $compareRows) {
+ if (0 !== ($res = call_user_func($compareRows, $row_a, $row_b))) {
break;
}
}
return $res;
});
- $this->iteratorSortBy = [];
+ $this->iterator_sort_by = [];
return $obj->getIterator();
}
@@ -288,10 +288,10 @@ trait QueryFilter
*/
protected function applyIteratorInterval(Iterator $iterator)
{
- $offset = $this->iteratorOffset;
- $limit = $this->iteratorLimit;
- $this->iteratorLimit = -1;
- $this->iteratorOffset = 0;
+ $offset = $this->iterator_offset;
+ $limit = $this->iterator_limit;
+ $this->iterator_limit = -1;
+ $this->iterator_offset = 0;
return new LimitIterator($iterator, $offset, $limit);
}
diff --git a/src/Modifier/StreamFilter.php b/src/Modifier/StreamFilter.php
index e3f0600..f1b38b1 100644
--- a/src/Modifier/StreamFilter.php
+++ b/src/Modifier/StreamFilter.php
@@ -30,14 +30,14 @@ trait StreamFilter
*
* @var array
*/
- protected $streamFilters = [];
+ protected $stream_filters = [];
/**
* Stream filtering mode to apply on all filters
*
* @var int
*/
- protected $streamFilterMode = STREAM_FILTER_ALL;
+ protected $stream_filter_mode = STREAM_FILTER_ALL;
/**
*the real path
@@ -45,7 +45,7 @@ trait StreamFilter
* @var string the real path to the file
*
*/
- protected $streamUri;
+ protected $stream_uri;
/**
* PHP Stream Filter Regex
@@ -70,21 +70,21 @@ trait StreamFilter
*/
protected function initStreamFilter($path)
{
- $this->streamFilters = [];
+ $this->stream_filters = [];
if (!is_string($path)) {
- $this->streamUri = null;
+ $this->stream_uri = null;
return;
}
if (!preg_match($this->stream_regex, $path, $matches)) {
- $this->streamUri = $path;
+ $this->stream_uri = $path;
return;
}
- $this->streamUri = $matches['resource'];
- $this->streamFilters = array_map('urldecode', explode('|', $matches['filters']));
- $this->streamFilterMode = $this->fetchStreamModeAsInt($matches['mode']);
+ $this->stream_uri = $matches['resource'];
+ $this->stream_filters = array_map('urldecode', explode('|', $matches['filters']));
+ $this->stream_filter_mode = $this->fetchStreamModeAsInt($matches['mode']);
}
/**
@@ -116,7 +116,7 @@ trait StreamFilter
*/
protected function assertStreamable()
{
- if (!is_string($this->streamUri)) {
+ if (!is_string($this->stream_uri)) {
throw new LogicException('The stream filter API can not be used');
}
}
@@ -128,7 +128,7 @@ trait StreamFilter
*/
public function isActiveStreamFilter()
{
- return is_string($this->streamUri);
+ return is_string($this->stream_uri);
}
/**
@@ -150,8 +150,8 @@ trait StreamFilter
throw new OutOfBoundsException('the $mode should be a valid `STREAM_FILTER_*` constant');
}
- $this->streamFilterMode = $mode;
- $this->streamFilters = [];
+ $this->stream_filter_mode = $mode;
+ $this->stream_filters = [];
return $this;
}
@@ -165,20 +165,20 @@ trait StreamFilter
{
$this->assertStreamable();
- return $this->streamFilterMode;
+ return $this->stream_filter_mode;
}
/**
* append a stream filter
*
- * @param string $filterName a string or an object that implements the '__toString' method
+ * @param string $filter_name a string or an object that implements the '__toString' method
*
* @return $this
*/
- public function appendStreamFilter($filterName)
+ public function appendStreamFilter($filter_name)
{
$this->assertStreamable();
- $this->streamFilters[] = $this->sanitizeStreamFilter($filterName);
+ $this->stream_filters[] = $this->sanitizeStreamFilter($filter_name);
return $this;
}
@@ -186,14 +186,14 @@ trait StreamFilter
/**
* prepend a stream filter
*
- * @param string $filterName a string or an object that implements the '__toString' method
+ * @param string $filter_name a string or an object that implements the '__toString' method
*
* @return $this
*/
- public function prependStreamFilter($filterName)
+ public function prependStreamFilter($filter_name)
{
$this->assertStreamable();
- array_unshift($this->streamFilters, $this->sanitizeStreamFilter($filterName));
+ array_unshift($this->stream_filters, $this->sanitizeStreamFilter($filter_name));
return $this;
}
@@ -201,13 +201,13 @@ trait StreamFilter
/**
* Sanitize the stream filter name
*
- * @param string $filterName the stream filter name
+ * @param string $filter_name the stream filter name
*
* @return string
*/
- protected function sanitizeStreamFilter($filterName)
+ protected function sanitizeStreamFilter($filter_name)
{
- return urldecode($this->validateString($filterName));
+ return urldecode($this->validateString($filter_name));
}
/**
@@ -218,30 +218,30 @@ trait StreamFilter
/**
* Detect if the stream filter is already present
*
- * @param string $filterName
+ * @param string $filter_name
*
* @return bool
*/
- public function hasStreamFilter($filterName)
+ public function hasStreamFilter($filter_name)
{
$this->assertStreamable();
- return false !== array_search(urldecode($filterName), $this->streamFilters, true);
+ return false !== array_search(urldecode($filter_name), $this->stream_filters, true);
}
/**
* Remove a filter from the collection
*
- * @param string $filterName
+ * @param string $filter_name
*
* @return $this
*/
- public function removeStreamFilter($filterName)
+ public function removeStreamFilter($filter_name)
{
$this->assertStreamable();
- $res = array_search(urldecode($filterName), $this->streamFilters, true);
+ $res = array_search(urldecode($filter_name), $this->stream_filters, true);
if (false !== $res) {
- unset($this->streamFilters[$res]);
+ unset($this->stream_filters[$res]);
}
return $this;
@@ -255,7 +255,7 @@ trait StreamFilter
public function clearStreamFilter()
{
$this->assertStreamable();
- $this->streamFilters = [];
+ $this->stream_filters = [];
return $this;
}
@@ -268,14 +268,14 @@ trait StreamFilter
protected function getStreamFilterPath()
{
$this->assertStreamable();
- if (!$this->streamFilters) {
- return $this->streamUri;
+ if (!$this->stream_filters) {
+ return $this->stream_uri;
}
return 'php://filter/'
.$this->getStreamFilterPrefix()
- .implode('|', array_map('urlencode', $this->streamFilters))
- .'/resource='.$this->streamUri;
+ .implode('|', array_map('urlencode', $this->stream_filters))
+ .'/resource='.$this->stream_uri;
}
/**
@@ -285,11 +285,11 @@ trait StreamFilter
*/
protected function getStreamFilterPrefix()
{
- if (STREAM_FILTER_READ == $this->streamFilterMode) {
+ if (STREAM_FILTER_READ == $this->stream_filter_mode) {
return 'read=';
}
- if (STREAM_FILTER_WRITE == $this->streamFilterMode) {
+ if (STREAM_FILTER_WRITE == $this->stream_filter_mode) {
return 'write=';
}
diff --git a/src/Plugin/ColumnConsistencyValidator.php b/src/Plugin/ColumnConsistencyValidator.php
index 69dcced..5120b08 100644
--- a/src/Plugin/ColumnConsistencyValidator.php
+++ b/src/Plugin/ColumnConsistencyValidator.php
@@ -28,14 +28,14 @@ class ColumnConsistencyValidator
*
* @var int
*/
- private $columnsCount = -1;
+ private $columns_count = -1;
/**
* should the class detect the column count based the inserted row
*
* @var bool
*/
- private $detectColumnsCount = false;
+ private $detect_columns_count = 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->detectColumnsCount = false;
- $this->columnsCount = $value;
+ $this->detect_columns_count = false;
+ $this->columns_count = $value;
}
/**
@@ -61,18 +61,18 @@ class ColumnConsistencyValidator
*/
public function getColumnsCount()
{
- return $this->columnsCount;
+ return $this->columns_count;
}
/**
- * The method will set the $columnsCount property according to the next inserted row
+ * The method will set the $columns_count property according to the next inserted row
* and therefore will also validate the next line whatever length it has no matter
- * the current $columnsCount property value.
+ * the current $columns_count property value.
*
*/
public function autodetectColumnsCount()
{
- $this->detectColumnsCount = true;
+ $this->detect_columns_count = true;
}
/**
@@ -84,17 +84,17 @@ class ColumnConsistencyValidator
*/
public function __invoke(array $row)
{
- if ($this->detectColumnsCount) {
- $this->columnsCount = count($row);
- $this->detectColumnsCount = false;
+ if ($this->detect_columns_count) {
+ $this->columns_count = count($row);
+ $this->detect_columns_count = false;
return true;
}
- if (-1 == $this->columnsCount) {
+ if (-1 == $this->columns_count) {
return true;
}
- return count($row) == $this->columnsCount;
+ return count($row) === $this->columns_count;
}
}
diff --git a/src/Reader.php b/src/Reader.php
index 14b0cec..89a5d39 100644
--- a/src/Reader.php
+++ b/src/Reader.php
@@ -31,7 +31,7 @@ class Reader extends AbstractCsv
/**
* @inheritdoc
*/
- protected $streamFilterMode = STREAM_FILTER_READ;
+ protected $stream_filter_mode = STREAM_FILTER_READ;
/**
* Returns a sequential array of all CSV lines
@@ -130,25 +130,25 @@ class Reader extends AbstractCsv
*
* By default if no column index is provided the first column of the CSV is selected
*
- * @param int $columnIndex CSV column index
- * @param callable|null $callable A callable to be applied to each of the value to be returned.
+ * @param int $column_index CSV column index
+ * @param callable|null $callable A callable to be applied to each of the value to be returned.
*
* @return Iterator
*/
- public function fetchColumn($columnIndex = 0, callable $callable = null)
+ public function fetchColumn($column_index = 0, callable $callable = null)
{
- $columnIndex = $this->validateInteger($columnIndex, 0, 'the column index must be a positive integer or 0');
+ $column_index = $this->validateInteger($column_index, 0, 'the column index must be a positive integer or 0');
- $filterColumn = function ($row) use ($columnIndex) {
- return isset($row[$columnIndex]);
+ $filter_column = function ($row) use ($column_index) {
+ return isset($row[$column_index]);
};
- $selectColumn = function ($row) use ($columnIndex) {
- return $row[$columnIndex];
+ $select_column = function ($row) use ($column_index) {
+ return $row[$column_index];
};
- $this->addFilter($filterColumn);
- $iterator = $this->fetch($selectColumn);
+ $this->addFilter($filter_column);
+ $iterator = $this->fetch($select_column);
$iterator = $this->applyCallable($iterator, $callable);
return $iterator;
@@ -167,15 +167,15 @@ class Reader extends AbstractCsv
* If the value from the column key index is duplicated its corresponding value will
* be overwritten
*
- * @param int $offsetIndex The column index to serve as offset
- * @param int $valueIndex The column index to serve as value
- * @param callable|null $callable A callable to be applied to each of the rows to be returned.
+ * @param int $offset_index The column index to serve as offset
+ * @param int $value_index The column index to serve as value
+ * @param callable|null $callable A callable to be applied to each of the rows to be returned.
*
* @return array
*/
- public function fetchPairsWithoutDuplicates($offsetIndex = 0, $valueIndex = 1, callable $callable = null)
+ public function fetchPairsWithoutDuplicates($offset_index = 0, $value_index = 1, callable $callable = null)
{
- return iterator_to_array($this->fetchPairs($offsetIndex, $valueIndex, $callable), true);
+ return iterator_to_array($this->fetchPairs($offset_index, $value_index, $callable), true);
}
/**
@@ -186,28 +186,28 @@ class Reader extends AbstractCsv
* - the first CSV column is used to provide the keys
* - the second CSV column is used to provide the value
*
- * @param int $offsetIndex The column index to serve as offset
- * @param int $valueIndex The column index to serve as value
- * @param callable|null $callable A callable to be applied to each of the rows to be returned.
+ * @param int $offset_index The column index to serve as offset
+ * @param int $value_index The column index to serve as value
+ * @param callable|null $callable A callable to be applied to each of the rows to be returned.
*
* @return Generator
*/
- public function fetchPairs($offsetIndex = 0, $valueIndex = 1, callable $callable = null)
+ public function fetchPairs($offset_index = 0, $value_index = 1, callable $callable = null)
{
- $offsetIndex = $this->validateInteger($offsetIndex, 0, 'the offset column index must be a positive integer or 0');
- $valueIndex = $this->validateInteger($valueIndex, 0, 'the value column index must be a positive integer or 0');
- $filterPairs = function ($row) use ($offsetIndex) {
- return isset($row[$offsetIndex]);
+ $offset_index = $this->validateInteger($offset_index, 0, 'the offset column index must be a positive integer or 0');
+ $value_index = $this->validateInteger($value_index, 0, 'the value column index must be a positive integer or 0');
+ $filter_pairs = function ($row) use ($offset_index) {
+ return isset($row[$offset_index]);
};
- $selectPairs = function ($row) use ($offsetIndex, $valueIndex) {
+ $select_pairs = function ($row) use ($offset_index, $value_index) {
return [
- $row[$offsetIndex],
- isset($row[$valueIndex]) ? $row[$valueIndex] : null,
+ $row[$offset_index],
+ isset($row[$value_index]) ? $row[$value_index] : null,
];
};
- $this->addFilter($filterPairs);
- $iterator = $this->fetch($selectPairs);
+ $this->addFilter($filter_pairs);
+ $iterator = $this->fetch($select_pairs);
$iterator = $this->applyCallable($iterator, $callable);
return $this->generatePairs($iterator);
@@ -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 $offsetOrKeys the name for each key member OR the row Index to be
- * used as the associated named keys
+ * @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 callable $callable A callable to be applied to each of the rows to be returned.
*
@@ -242,19 +242,19 @@ class Reader extends AbstractCsv
*
* @return Iterator
*/
- public function fetchAssoc($offsetOrKeys = 0, callable $callable = null)
+ public function fetchAssoc($offset_or_keys = 0, callable $callable = null)
{
- $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);
+ $keys = $this->getAssocKeys($offset_or_keys);
+ $keys_count = count($keys);
+ $combine_array = function (array $row) use ($keys, $keys_count) {
+ if ($keys_count != count($row)) {
+ $row = array_slice(array_pad($row, $keys_count, null), 0, $keys_count);
}
return array_combine($keys, $row);
};
- $iterator = $this->fetch($combineArray);
+ $iterator = $this->fetch($combine_array);
$iterator = $this->applyCallable($iterator, $callable);
return $iterator;
@@ -263,27 +263,27 @@ class Reader extends AbstractCsv
/**
* Selects the array to be used as key for the fetchAssoc method
*
- * @param int|array $offsetOrKeys the assoc key OR the row Index to be used
- * as the key index
+ * @param int|array $offset_or_keys 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($offsetOrKeys)
+ protected function getAssocKeys($offset_or_keys)
{
- if (is_array($offsetOrKeys)) {
- return $this->validateKeys($offsetOrKeys);
+ if (is_array($offset_or_keys)) {
+ return $this->validateKeys($offset_or_keys);
}
- $offsetOrKeys = $this->validateInteger(
- $offsetOrKeys,
+ $offset_or_keys = $this->validateInteger(
+ $offset_or_keys,
0,
'the row index must be a positive integer, 0 or a non empty array'
);
- $keys = $this->validateKeys($this->getRow($offsetOrKeys));
- $filterOutRow = function ($row, $rowIndex) use ($offsetOrKeys) {
- return $rowIndex != $offsetOrKeys;
+ $keys = $this->validateKeys($this->getRow($offset_or_keys));
+ $filterOutRow = function ($row, $rowIndex) use ($offset_or_keys) {
+ return $rowIndex != $offset_or_keys;
};
$this->addFilter($filterOutRow);
diff --git a/src/Writer.php b/src/Writer.php
index 19f20b1..a35af37 100644
--- a/src/Writer.php
+++ b/src/Writer.php
@@ -32,7 +32,7 @@ class Writer extends AbstractCsv
/**
* @inheritdoc
*/
- protected $streamFilterMode = STREAM_FILTER_WRITE;
+ protected $stream_filter_mode = STREAM_FILTER_WRITE;
/**
* The CSV object holder
@@ -53,7 +53,7 @@ class Writer extends AbstractCsv
*
* @var integer
*/
- protected static $fputcsvParamsCount;
+ protected static $fputcsv_param_count;
/**
* @inheritdoc
@@ -71,7 +71,7 @@ class Writer extends AbstractCsv
{
if (null === static::$fputcsv) {
static::$fputcsv = new ReflectionMethod('\SplFileObject', 'fputcsv');
- static::$fputcsvParamsCount = static::$fputcsv->getNumberOfParameters();
+ static::$fputcsv_param_count = 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::$fputcsvParamsCount) {
+ if (4 == static::$fputcsv_param_count) {
$parameters[] = $this->escape;
}