Renamed protected functions: no end user should be tempted to call them

This commit is contained in:
Fonata
2019-03-10 11:56:32 +01:00
parent 5874b768b9
commit e3105d4003
3 changed files with 14 additions and 12 deletions

View File

@@ -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;

View File

@@ -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.');

View File

@@ -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([