summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorignace nyamagana butera <nyamsprod@gmail.com>2015-09-25 12:14:30 +0200
committerignace nyamagana butera <nyamsprod@gmail.com>2015-09-25 12:14:30 +0200
commit9e50df4fbed858b4b633f7d203c5be31b3f089fe (patch)
tree8b2477a73be3c3b3cb888c1df12bdcafef53837d /src
parent640f57af7abb41d51673cd860041979623cee423 (diff)
parente81de221d38490459439d105bd4367ac024a1ee2 (diff)
downloadcsv-9e50df4fbed858b4b633f7d203c5be31b3f089fe.zip
csv-9e50df4fbed858b4b633f7d203c5be31b3f089fe.tar.gz
csv-9e50df4fbed858b4b633f7d203c5be31b3f089fe.tar.bz2
Merge pull request #118 from thephpleague/features/improve-package-settings
Improve Package Testing tools
Diffstat (limited to 'src')
-rw-r--r--src/AbstractCsv.php40
-rw-r--r--src/Config/Controls.php12
-rw-r--r--src/Config/Output.php20
-rw-r--r--src/Exception/InvalidRowException.php4
-rw-r--r--src/Modifier/MapIterator.php2
-rw-r--r--src/Modifier/QueryFilter.php6
-rw-r--r--src/Modifier/RowFilter.php5
-rw-r--r--src/Modifier/StreamFilter.php6
-rw-r--r--src/Plugin/ColumnConsistencyValidator.php4
-rw-r--r--src/Reader.php26
-rw-r--r--src/Writer.php19
11 files changed, 62 insertions, 82 deletions
diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php
index f03e149..db3ab6c 100644
--- a/src/AbstractCsv.php
+++ b/src/AbstractCsv.php
@@ -16,8 +16,10 @@ use CallbackFilterIterator;
use InvalidArgumentException;
use IteratorAggregate;
use JsonSerializable;
-use League\Csv\Config;
-use League\Csv\Modifier;
+use League\Csv\Config\Controls;
+use League\Csv\Config\Output;
+use League\Csv\Modifier\QueryFilter;
+use League\Csv\Modifier\StreamFilter;
use SplFileInfo;
use SplFileObject;
use SplTempFileObject;
@@ -31,6 +33,14 @@ use SplTempFileObject;
*/
abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
{
+ use Controls;
+
+ use Output;
+
+ use QueryFilter;
+
+ use StreamFilter;
+
/**
* UTF-8 BOM sequence
*/
@@ -73,26 +83,6 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
protected $open_mode;
/**
- * Csv Controls Trait
- */
- use Config\Controls;
-
- /**
- * Csv Outputting Trait
- */
- use Config\Output;
-
- /**
- * Query Filter Trait
- */
- use Modifier\QueryFilter;
-
- /**
- * Stream Filter API Trait
- */
- use Modifier\StreamFilter;
-
- /**
* Creates a new instance
*
* The path must be an SplFileInfo object
@@ -104,7 +94,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
*/
protected function __construct($path, $open_mode = 'r+')
{
- $this->flags = SplFileObject::READ_CSV|SplFileObject::DROP_NEW_LINE;
+ $this->flags = SplFileObject::READ_CSV | SplFileObject::DROP_NEW_LINE;
$this->open_mode = strtolower($open_mode);
$this->path = $this->normalizePath($path);
$this->initStreamFilter($this->path);
@@ -160,7 +150,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
protected function getConversionIterator()
{
$iterator = $this->getIterator();
- $iterator->setFlags($this->flags|SplFileObject::READ_AHEAD|SplFileObject::SKIP_EMPTY);
+ $iterator->setFlags($this->flags | SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY);
$iterator = $this->applyBomStripping($iterator);
$iterator = new CallbackFilterIterator($iterator, function ($row) {
return is_array($row) && [null] != $row;
@@ -239,7 +229,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
* The string must be an object that implements the `__toString` method,
* or a string
*
- * @param string|object $str the string
+ * @param string|object $str the string
* @param string $newline the newline character
*
* @return static
diff --git a/src/Config/Controls.php b/src/Config/Controls.php
index 92194a5..88d390b 100644
--- a/src/Config/Controls.php
+++ b/src/Config/Controls.php
@@ -73,7 +73,7 @@ trait Controls
*
* @param string $delimiter
*
- * @throws \InvalidArgumentException If $delimeter is not a single character
+ * @throws InvalidArgumentException If $delimeter is not a single character
*
* @return $this
*/
@@ -123,7 +123,7 @@ trait Controls
* @param int $nb_rows
* @param string[] $delimiters additional delimiters
*
- * @throws \InvalidArgumentException If $nb_rows value is invalid
+ * @throws InvalidArgumentException If $nb_rows value is invalid
*
* @return string[]
*/
@@ -153,7 +153,7 @@ trait Controls
*
* @param string $enclosure
*
- * @throws \InvalidArgumentException If $enclosure is not a single character
+ * @throws InvalidArgumentException If $enclosure is not a single character
*
* @return $this
*/
@@ -182,7 +182,7 @@ trait Controls
*
* @param string $escape
*
- * @throws \InvalidArgumentException If $escape is not a single character
+ * @throws InvalidArgumentException If $escape is not a single character
*
* @return $this
*/
@@ -211,7 +211,7 @@ trait Controls
*
* @param int $flags
*
- * @throws \InvalidArgumentException If the argument is not a valid integer
+ * @throws InvalidArgumentException If the argument is not a valid integer
*
* @return $this
*/
@@ -221,7 +221,7 @@ trait Controls
throw new InvalidArgumentException('you should use a `SplFileObject` Constant');
}
- $this->flags = $flags|SplFileObject::READ_CSV;
+ $this->flags = $flags | SplFileObject::READ_CSV;
return $this;
}
diff --git a/src/Config/Output.php b/src/Config/Output.php
index 6a43dbc..035f444 100644
--- a/src/Config/Output.php
+++ b/src/Config/Output.php
@@ -15,7 +15,7 @@ namespace League\Csv\Config;
use DomDocument;
use InvalidArgumentException;
use Iterator;
-use League\Csv\Modifier;
+use League\Csv\Modifier\MapIterator;
use SplFileObject;
/**
@@ -49,14 +49,14 @@ trait Output
/**
* Returns the CSV Iterator
*
- * @return \Iterator
+ * @return Iterator
*/
abstract protected function getConversionIterator();
/**
* Returns the CSV Iterator
*
- * @return \Iterator
+ * @return Iterator
*/
abstract public function getIterator();
@@ -70,7 +70,7 @@ trait Output
public function setEncodingFrom($str)
{
$str = str_replace('_', '-', $str);
- $str = filter_var($str, FILTER_SANITIZE_STRING, ['flags' => FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH]);
+ $str = filter_var($str, FILTER_SANITIZE_STRING, ['flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH]);
if (empty($str)) {
throw new InvalidArgumentException('you should use a valid charset');
}
@@ -92,7 +92,7 @@ trait Output
/**
* Sets the BOM sequence to prepend the CSV on output
*
- * @param string $str The BOM sequence
+ * @param string $str The BOM sequence
*
* @return static
*/
@@ -159,8 +159,8 @@ trait Output
if (! is_null($filename)) {
$filename = trim($filename);
$filename = filter_var($filename, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
- header("Content-Type: application/octet-stream");
- header("Content-Transfer-Encoding: binary");
+ header('Content-Type: application/octet-stream');
+ header('Content-Transfer-Encoding: binary');
header("Content-Disposition: attachment; filename=\"$filename\"");
}
@@ -218,7 +218,7 @@ trait Output
/**
* Convert Csv file into UTF-8
*
- * @return \Iterator
+ * @return Iterator
*/
protected function convertToUtf8(Iterator $iterator)
{
@@ -226,7 +226,7 @@ trait Output
return $iterator;
}
- return new Modifier\MapIterator($iterator, function ($row) {
+ return new MapIterator($iterator, function ($row) {
foreach ($row as &$value) {
$value = mb_convert_encoding($value, 'UTF-8', $this->encodingFrom);
}
@@ -258,7 +258,7 @@ trait Output
* @param string $row_name XML row node name
* @param string $cell_name XML cell node name
*
- * @return \DomDocument
+ * @return DomDocument
*/
public function toXML($root_name = 'csv', $row_name = 'row', $cell_name = 'cell')
{
diff --git a/src/Exception/InvalidRowException.php b/src/Exception/InvalidRowException.php
index 0fb0227..559fcc2 100644
--- a/src/Exception/InvalidRowException.php
+++ b/src/Exception/InvalidRowException.php
@@ -12,8 +12,6 @@
*/
namespace League\Csv\Exception;
-use InvalidArgumentException;
-
/**
* Thrown when a data is not validated prior to insertion
*
@@ -42,7 +40,7 @@ class InvalidRowException extends \InvalidArgumentException
* @param array $data invalid data
* @param string $message exception message
*/
- public function __construct($name, array $data = [], $message = "")
+ public function __construct($name, array $data = [], $message = '')
{
parent::__construct($message);
$this->name = $name;
diff --git a/src/Modifier/MapIterator.php b/src/Modifier/MapIterator.php
index 2306f1c..436cb99 100644
--- a/src/Modifier/MapIterator.php
+++ b/src/Modifier/MapIterator.php
@@ -36,7 +36,7 @@ class MapIterator extends IteratorIterator
* The Constructor
*
* @param Iterator $iterator
- * @param callable $callable
+ * @param callable $callable
*/
public function __construct(Iterator $iterator, callable $callable)
{
diff --git a/src/Modifier/QueryFilter.php b/src/Modifier/QueryFilter.php
index a2727a7..d6eef72 100644
--- a/src/Modifier/QueryFilter.php
+++ b/src/Modifier/QueryFilter.php
@@ -65,7 +65,7 @@ trait QueryFilter
/**
* Stripping BOM setter
*
- * @param bool $status
+ * @param bool $status
*
* @return $this
*/
@@ -240,7 +240,7 @@ trait QueryFilter
/**
* Remove the BOM sequence from the CSV
*
- * @param Iterator $iterator
+ * @param Iterator $iterator
*
* @return \Iterator
*/
@@ -264,7 +264,7 @@ trait QueryFilter
/**
* Return the Iterator without the BOM sequence
*
- * @param Iterator $iterator
+ * @param Iterator $iterator
*
* @return Iterator
*/
diff --git a/src/Modifier/RowFilter.php b/src/Modifier/RowFilter.php
index b340a68..06137ff 100644
--- a/src/Modifier/RowFilter.php
+++ b/src/Modifier/RowFilter.php
@@ -96,7 +96,7 @@ trait RowFilter
* add a Validator to the collection
*
* @param callable $callable
- * @param string $name the rule name
+ * @param string $name the rule name
*
* @return $this
*/
@@ -174,7 +174,6 @@ trait RowFilter
*
* @throws \League\Csv\Exception\InvalidRowException If the validation failed
*
- * @return void
*/
protected function validateRow(array $row)
{
@@ -184,6 +183,4 @@ trait RowFilter
}
}
}
-
-
}
diff --git a/src/Modifier/StreamFilter.php b/src/Modifier/StreamFilter.php
index ebea922..38ddcd6 100644
--- a/src/Modifier/StreamFilter.php
+++ b/src/Modifier/StreamFilter.php
@@ -85,7 +85,7 @@ trait StreamFilter
/**
* Get the stream mode
*
- * @param string $mode
+ * @param string $mode
*
* @return int
*/
@@ -107,7 +107,7 @@ trait StreamFilter
/**
* Check if the trait methods can be used
*
- * @throws \LogicException If the API can not be use
+ * @throws LogicException If the API can not be use
*/
protected function assertStreamable()
{
@@ -134,7 +134,7 @@ trait StreamFilter
*
* @param int $mode
*
- * @throws \OutOfBoundsException If the mode is invalid
+ * @throws OutOfBoundsException If the mode is invalid
*
* @return $this
*/
diff --git a/src/Plugin/ColumnConsistencyValidator.php b/src/Plugin/ColumnConsistencyValidator.php
index aa013b3..b2942d1 100644
--- a/src/Plugin/ColumnConsistencyValidator.php
+++ b/src/Plugin/ColumnConsistencyValidator.php
@@ -42,9 +42,8 @@ class ColumnConsistencyValidator
*
* @param int $value
*
- * @throws \InvalidArgumentException If $value is lesser than -1
+ * @throws InvalidArgumentException If $value is lesser than -1
*
- * @return void
*/
public function setColumnsCount($value)
{
@@ -70,7 +69,6 @@ class ColumnConsistencyValidator
* and therefore will also validate the next line whatever length it has no matter
* the current $columns_count property value.
*
- * @return void
*/
public function autodetectColumnsCount()
{
diff --git a/src/Reader.php b/src/Reader.php
index 2d5e213..9160074 100644
--- a/src/Reader.php
+++ b/src/Reader.php
@@ -15,7 +15,7 @@ namespace League\Csv;
use CallbackFilterIterator;
use InvalidArgumentException;
use Iterator;
-use League\Csv\Modifier;
+use League\Csv\Modifier\MapIterator;
use LimitIterator;
use SplFileObject;
@@ -29,7 +29,7 @@ use SplFileObject;
class Reader extends AbstractCsv
{
/**
- * {@ihneritdoc}
+ * @ihneritdoc
*/
protected $stream_filter_mode = STREAM_FILTER_READ;
@@ -38,7 +38,7 @@ class Reader extends AbstractCsv
*
* @param callable $callable a callable function to be applied to each Iterator item
*
- * @return \Iterator
+ * @return Iterator
*/
public function query(callable $callable = null)
{
@@ -52,7 +52,7 @@ class Reader extends AbstractCsv
$iterator = $this->applyIteratorSortBy($iterator);
$iterator = $this->applyIteratorInterval($iterator);
if (! is_null($callable)) {
- return new Modifier\MapIterator($iterator, $callable);
+ return new MapIterator($iterator, $callable);
}
return $iterator;
@@ -86,7 +86,7 @@ class Reader extends AbstractCsv
*
* @param int $offset
*
- * @throws \InvalidArgumentException If the $offset is not a valid Integer
+ * @throws InvalidArgumentException If the $offset is not a valid Integer
*
* @return array
*/
@@ -134,7 +134,7 @@ class Reader extends AbstractCsv
* @param int $column_index field Index
* @param callable $callable a callable function
*
- * @throws \InvalidArgumentException If the column index is not a positive integer or 0
+ * @throws InvalidArgumentException If the column index is not a positive integer or 0
*
* @return array
*/
@@ -150,7 +150,7 @@ class Reader extends AbstractCsv
$iterator = new CallbackFilterIterator($iterator, function ($row) use ($column_index) {
return array_key_exists($column_index, $row);
});
- $iterator = new Modifier\MapIterator($iterator, function ($row) use ($column_index) {
+ $iterator = new MapIterator($iterator, function ($row) use ($column_index) {
return $row[$column_index];
});
@@ -166,9 +166,9 @@ class Reader extends AbstractCsv
* @param array|int $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 function
+ * @param callable $callable a callable function
*
- * @throws \InvalidArgumentException If the submitted keys are invalid
+ * @throws InvalidArgumentException If the submitted keys are invalid
*
* @return array
*/
@@ -183,7 +183,7 @@ class Reader extends AbstractCsv
}
$keys_count = count($keys);
$iterator = $this->query($callable);
- $iterator = new Modifier\MapIterator($iterator, function (array $row) use ($keys, $keys_count) {
+ $iterator = new MapIterator($iterator, function (array $row) use ($keys, $keys_count) {
if ($keys_count != count($row)) {
$row = array_slice(array_pad($row, $keys_count, null), 0, $keys_count);
}
@@ -200,7 +200,7 @@ class Reader extends AbstractCsv
* @param array|int $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
+ * @throws InvalidArgumentException If the row index and/or the resulting array is invalid
*
* @return array
*/
@@ -224,7 +224,7 @@ class Reader extends AbstractCsv
*
* @param int $offset
*
- * @throws \InvalidArgumentException If the $offset is not valid or the row does not exist
+ * @throws InvalidArgumentException If the $offset is not valid or the row does not exist
*
* @return array
*/
@@ -252,7 +252,7 @@ class Reader extends AbstractCsv
*
* @param array $keys
*
- * @throws \InvalidArgumentException If the submitted array fails the assertion
+ * @throws InvalidArgumentException If the submitted array fails the assertion
*/
protected function assertValidAssocKeys(array $keys)
{
diff --git a/src/Writer.php b/src/Writer.php
index 824203a..c25143d 100644
--- a/src/Writer.php
+++ b/src/Writer.php
@@ -13,7 +13,7 @@
namespace League\Csv;
use InvalidArgumentException;
-use League\Csv\Modifier;
+use League\Csv\Modifier\RowFilter;
use ReflectionMethod;
use Traversable;
@@ -26,8 +26,10 @@ use Traversable;
*/
class Writer extends AbstractCsv
{
+ use RowFilter;
+
/**
- * {@ihneritdoc}
+ * @ihneritdoc
*/
protected $stream_filter_mode = STREAM_FILTER_WRITE;
@@ -53,12 +55,7 @@ class Writer extends AbstractCsv
protected static $fputcsv_param_count;
/**
- * Row Formatter and Validator trait
- */
- use Modifier\RowFilter;
-
- /**
- * {@ihneritdoc}
+ * @ihneritdoc
*/
protected function __construct($path, $open_mode = 'r+')
{
@@ -82,9 +79,9 @@ class Writer extends AbstractCsv
*
* a simple wrapper method around insertOne
*
- * @param \Traversable|array $rows a multidimentional array or a Traversable object
+ * @param Traversable|array $rows a multidimentional array or a Traversable object
*
- * @throws \InvalidArgumentException If the given rows format is invalid
+ * @throws InvalidArgumentException If the given rows format is invalid
*
* @return static
*/
@@ -134,7 +131,7 @@ class Writer extends AbstractCsv
/**
* returns the parameters for SplFileObject::fputcsv
*
- * @param array $fields The fields to be add
+ * @param array $fields The fields to be add
*
* @return array
*/