From e3105d400322aadc9805d8c513a370499a961ff4 Mon Sep 17 00:00:00 2001 From: Fonata Date: Sun, 10 Mar 2019 11:56:32 +0100 Subject: [PATCH] Renamed protected functions: no end user should be tempted to call them --- src/Csv.php | 22 ++++++++++++---------- src/extensions/DatatypeTrait.php | 2 +- tests/methods/ParseTest.php | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Csv.php b/src/Csv.php index cf9a208..f73d1e9 100644 --- a/src/Csv.php +++ b/src/Csv.php @@ -378,11 +378,11 @@ class Csv { if (strlen($input) <= PHP_MAXPATHLEN && is_readable($input)) { $this->file = $input; - $this->data = $this->parse_file(); + $this->data = $this->_parse_file(); } else { $this->file = null; $this->file_data = &$input; - $this->data = $this->parse_string(); + $this->data = $this->_parse_string(); } return $this->data !== false; @@ -523,7 +523,7 @@ class Csv { // parse data if ($parse) { - $this->data = $this->parse_string(); + $this->data = $this->_parse_string(); } return $this->delimiter; @@ -573,13 +573,13 @@ class Csv { /** * Parse File - * Read file to string and call parse_string() + * Read file to string and call _parse_string() * * @param string|null $file Local CSV file * * @return array|bool */ - protected function parse_file($file = null) { + protected function _parse_file($file = null) { if (is_null($file)) { $file = $this->file; } @@ -588,13 +588,15 @@ class Csv { $this->load_data($file); } - return !empty($this->file_data) ? $this->parse_string() : false; + return !empty($this->file_data) ? $this->_parse_string() : false; } /** - * Parse CSV strings to arrays. If you need BOM detection or character - * encoding conversion, please call load_data() first, followed by a call to - * parse_string() with no parameters. + * Internal function to parse CSV strings to arrays. + * + * If you need BOM detection or character encoding conversion, please call + * $csv->load_data($your_data_string) first, followed by a call to + * $csv->parse($csv->file_data). * * To detect field separators, please use auto() instead. * @@ -602,7 +604,7 @@ class Csv { * * @return array|false - 2D array with CSV data, or false on failure */ - protected function parse_string($data = null) { + protected function _parse_string($data = null) { if (empty($data)) { if ($this->_check_data()) { $data = &$this->file_data; diff --git a/src/extensions/DatatypeTrait.php b/src/extensions/DatatypeTrait.php index a939006..5b22935 100644 --- a/src/extensions/DatatypeTrait.php +++ b/src/extensions/DatatypeTrait.php @@ -51,7 +51,7 @@ trait DatatypeTrait { */ public function getDatatypes() { if (empty($this->data)) { - $this->data = $this->parse_string(); + $this->data = $this->_parse_string(); } if (!is_array($this->data)) { throw new \UnexpectedValueException('No data set yet.'); diff --git a/tests/methods/ParseTest.php b/tests/methods/ParseTest.php index 4aa4bcd..db3b3ae 100644 --- a/tests/methods/ParseTest.php +++ b/tests/methods/ParseTest.php @@ -88,7 +88,7 @@ class ParseTest extends TestCase { $sInput = "86545235689,a\r\n34365587654,b\r\n13469874576,\"c\r\nd\""; $expected_data = [86545235689, 34365587654, 13469874576]; - $actual_data = $this->invokeMethod($this->csv, 'parse_string', array($sInput)); + $actual_data = $this->invokeMethod($this->csv, '_parse_string', array($sInput)); $actual_column = array_map('reset', $actual_data); $this->assertEquals($expected_data, $actual_column); $this->assertEquals([