From 5af539197a2d8bb7840bb59fa6f3054fac9ea8b9 Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Sat, 22 Feb 2014 11:32:41 +0100 Subject: [PATCH] remove validation resolves #14 --- README.md | 2 +- src/AbstractCsv.php | 14 -------------- src/Reader.php | 5 ----- src/Writer.php | 5 ----- test/WriterTest.php | 8 -------- test/foo.csv | 1 - 6 files changed, 1 insertion(+), 34 deletions(-) diff --git a/README.md b/README.md index 70ac274d..8b28e75c 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ $writer = Writer::createFromString('john,doe,john.doe@example.com'); Both classes constructors take one optional parameter `$open_mode` representing the file open mode used by the PHP [fopen](http://php.net/manual/en/function.fopen.php) function. * The `Bakame\Csv\Writer` `$open_mode` default value is `w`. -* The `Bakame\Csv\Reader` `$open_mode` default value is `r`, and **no other value is possible**. So you don't need to explicitly set it. +* The `Bakame\Csv\Reader` `$open_mode` default value is `r`. The static method `createFromString` is to be use if your data is a string. This method takes no optional `$open_mode` parameter. diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php index 614f5c5e..6c1b258b 100644 --- a/src/AbstractCsv.php +++ b/src/AbstractCsv.php @@ -96,13 +96,6 @@ class AbstractCsv implements JsonSerializable, IteratorAggregate */ protected $encoding = 'UTF-8'; - /** - * Open mode available flag - * - * @var array - */ - protected $available_open_mode = ['r', 'r+', 'w', 'w+', 'x', 'x+', 'a', 'a+', 'c', 'c+']; - /** * The constructor * @@ -177,13 +170,6 @@ protected function fetchFile($path, $open_mode) return $path; } $open_mode = strtolower($open_mode); - if (! in_array($open_mode, $this->available_open_mode)) { - throw new InvalidArgumentException( - 'Invalid `$open_mode` value. Available values are : "' - .implode('", "', $this->available_open_mode).'"' - ); - } - if ($path instanceof SplFileInfo) { return $path->openFile($open_mode); } elseif (is_string($path)) { diff --git a/src/Reader.php b/src/Reader.php index f837598c..8d82c031 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -51,11 +51,6 @@ class Reader extends AbstractCsv */ use IteratorQuery; - /** - * {@inheritdoc} - */ - protected $available_open_mode = ['r']; - /** * Intelligent Array Combine * diff --git a/src/Writer.php b/src/Writer.php index d3e9ed05..c047953b 100644 --- a/src/Writer.php +++ b/src/Writer.php @@ -44,11 +44,6 @@ */ class Writer extends AbstractCsv { - /** - * {@inheritdoc} - */ - protected $available_open_mode = ['r+', 'w', 'w+', 'x', 'x+', 'a', 'a+', 'c', 'c+']; - /** * {@inheritdoc} */ diff --git a/test/WriterTest.php b/test/WriterTest.php index ccd45cda..3b4a39db 100644 --- a/test/WriterTest.php +++ b/test/WriterTest.php @@ -22,14 +22,6 @@ public function setUp() $this->csv = new Writer(new SplTempFileObject); } - /** - * @expectedException InvalidArgumentException - */ - public function testConstructorWithWrongOpenMode() - { - new Writer('foo.csv', 'r'); - } - public function testInsert() { $expected = [ diff --git a/test/foo.csv b/test/foo.csv index 4307de42..0c85eae9 100644 --- a/test/foo.csv +++ b/test/foo.csv @@ -1,2 +1 @@ -1,2,3 "john","doe","john.doe@example.com" \ No newline at end of file