mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 00:36:38 +00:00
PHPUnit 6 instead of 4, to get rid of wrapper
The TestCase wrapper caused PhpStorm to show warnings about multiple implementations Fixes #188 Improved some type hints in DocBlocks
This commit is contained in:
@@ -8,8 +8,6 @@ php:
|
|||||||
- '7.2'
|
- '7.2'
|
||||||
- '7.1'
|
- '7.1'
|
||||||
- '7.0'
|
- '7.0'
|
||||||
- '5.6'
|
|
||||||
- '5.5'
|
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- composer update
|
- composer update
|
||||||
|
|||||||
@@ -34,7 +34,8 @@
|
|||||||
"php": ">=5.5"
|
"php": ">=5.5"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "4.1.*"
|
"phpunit/phpunit": "^6",
|
||||||
|
"squizlabs/php_codesniffer": "^3.5"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"illuminate/support": "Fluent array interface for map functions"
|
"illuminate/support": "Fluent array interface for map functions"
|
||||||
|
|||||||
3
ruleset.xml
Normal file
3
ruleset.xml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="ParseCSV" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
|
||||||
|
</ruleset>
|
||||||
62
src/Csv.php
62
src/Csv.php
@@ -311,16 +311,16 @@ class Csv {
|
|||||||
* Constructor
|
* Constructor
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
* @param string|null $input The CSV string or a direct file path
|
* @param string|null $input The CSV string or a direct file path
|
||||||
* @param integer|null $offset Number of rows to ignore from the
|
* @param int|null $offset Number of rows to ignore from the
|
||||||
* beginning of the data
|
* beginning of the data
|
||||||
* @param integer|null $limit Limits the number of returned rows
|
* @param int|null $limit Limits the number of returned rows
|
||||||
* to specified amount
|
* to specified amount
|
||||||
* @param string|null $conditions Basic SQL-like conditions for row
|
* @param string|null $conditions Basic SQL-like conditions for row
|
||||||
* matching
|
* matching
|
||||||
* @param null|true $keep_file_data Keep raw file data in memory after
|
* @param null|true $keep_file_data Keep raw file data in memory after
|
||||||
* successful parsing
|
* successful parsing
|
||||||
* (useful for debugging)
|
* (useful for debugging)
|
||||||
*/
|
*/
|
||||||
public function __construct($input = null, $offset = null, $limit = null, $conditions = null, $keep_file_data = null) {
|
public function __construct($input = null, $offset = null, $limit = null, $conditions = null, $keep_file_data = null) {
|
||||||
$this->init($offset, $limit, $conditions, $keep_file_data);
|
$this->init($offset, $limit, $conditions, $keep_file_data);
|
||||||
@@ -331,13 +331,13 @@ class Csv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param integer|null $offset Number of rows to ignore from the
|
* @param int|null $offset Number of rows to ignore from the
|
||||||
* beginning of the data
|
* beginning of the data
|
||||||
* @param integer|null $limit Limits the number of returned rows
|
* @param int|null $limit Limits the number of returned rows
|
||||||
* to specified amount
|
* to specified amount
|
||||||
* @param string|null $conditions Basic SQL-like conditions for row
|
* @param string|null $conditions Basic SQL-like conditions for row
|
||||||
* matching
|
* matching
|
||||||
* @param null|true $keep_file_data Keep raw file data in memory after
|
* @param null|true $keep_file_data Keep raw file data in memory after
|
||||||
* successful parsing
|
* successful parsing
|
||||||
* (useful for debugging)
|
* (useful for debugging)
|
||||||
*/
|
*/
|
||||||
@@ -368,11 +368,11 @@ class Csv {
|
|||||||
* Parse a CSV file or string
|
* Parse a CSV file or string
|
||||||
*
|
*
|
||||||
* @param string|null $input The CSV string or a direct file path
|
* @param string|null $input The CSV string or a direct file path
|
||||||
* @param integer $offset Number of rows to ignore from the
|
* @param int|null $offset Number of rows to ignore from the
|
||||||
* beginning of the data
|
* beginning of the data
|
||||||
* @param integer $limit Limits the number of returned rows to
|
* @param int|null $limit Limits the number of returned rows to
|
||||||
* specified amount
|
* specified amount
|
||||||
* @param string $conditions Basic SQL-like conditions for row
|
* @param string|null $conditions Basic SQL-like conditions for row
|
||||||
* matching
|
* matching
|
||||||
*
|
*
|
||||||
* @return bool True on success
|
* @return bool True on success
|
||||||
@@ -474,8 +474,10 @@ class Csv {
|
|||||||
* Encoding
|
* Encoding
|
||||||
* Convert character encoding
|
* Convert character encoding
|
||||||
*
|
*
|
||||||
* @param string $input Input character encoding, uses default if left blank
|
* @param string|null $input Input character encoding, uses default if left blank
|
||||||
* @param string $output Output character encoding, uses default if left blank
|
* @param string|null $output Output character encoding, uses default if left blank
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function encoding($input = null, $output = null) {
|
public function encoding($input = null, $output = null) {
|
||||||
$this->convert_encoding = true;
|
$this->convert_encoding = true;
|
||||||
@@ -495,11 +497,11 @@ class Csv {
|
|||||||
*
|
*
|
||||||
* @param string|null $file Local CSV file
|
* @param string|null $file Local CSV file
|
||||||
* @param bool $parse True/false parse file directly
|
* @param bool $parse True/false parse file directly
|
||||||
* @param int $search_depth Number of rows to analyze
|
* @param int|null $search_depth Number of rows to analyze
|
||||||
* @param string $preferred Preferred delimiter characters
|
* @param string|null $preferred Preferred delimiter characters
|
||||||
* @param string|null $enclosure Enclosure character, default is double quote (").
|
* @param string|null $enclosure Enclosure character, default is double quote (").
|
||||||
*
|
*
|
||||||
* @return string The detected field delimiter
|
* @return string|false The detected field delimiter
|
||||||
*/
|
*/
|
||||||
public function auto($file = null, $parse = true, $search_depth = null, $preferred = null, $enclosure = null) {
|
public function auto($file = null, $parse = true, $search_depth = null, $preferred = null, $enclosure = null) {
|
||||||
if (is_null($file)) {
|
if (is_null($file)) {
|
||||||
@@ -572,12 +574,10 @@ class Csv {
|
|||||||
|
|
||||||
$headingRow = $this->heading ? 1 : 0;
|
$headingRow = $this->heading ? 1 : 0;
|
||||||
|
|
||||||
$count = substr_count($data, "\r")
|
return substr_count($data, "\r")
|
||||||
+ substr_count($data, "\n")
|
+ substr_count($data, "\n")
|
||||||
- substr_count($data, "\r\n")
|
- substr_count($data, "\r\n")
|
||||||
- $headingRow;
|
- $headingRow;
|
||||||
|
|
||||||
return $count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==============================================
|
// ==============================================
|
||||||
@@ -613,7 +613,7 @@ class Csv {
|
|||||||
*
|
*
|
||||||
* To detect field separators, please use auto() instead.
|
* To detect field separators, please use auto() instead.
|
||||||
*
|
*
|
||||||
* @param string $data CSV data
|
* @param string|null $data CSV data
|
||||||
*
|
*
|
||||||
* @return array|false - 2D array with CSV data, or false on failure
|
* @return array|false - 2D array with CSV data, or false on failure
|
||||||
*/
|
*/
|
||||||
@@ -861,7 +861,12 @@ class Csv {
|
|||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _validate_fields_for_unparse($fields) {
|
/**
|
||||||
|
* @param array $fields
|
||||||
|
*
|
||||||
|
* @return array|false
|
||||||
|
*/
|
||||||
|
private function _validate_fields_for_unparse(array $fields) {
|
||||||
if (empty($fields)) {
|
if (empty($fields)) {
|
||||||
$fields = $this->titles;
|
$fields = $this->titles;
|
||||||
}
|
}
|
||||||
@@ -1298,7 +1303,6 @@ class Csv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remove delimiter and its line-end (the data param is by-ref!)
|
// remove delimiter and its line-end (the data param is by-ref!)
|
||||||
/** @noinspection CallableParameterUseCaseInTypeContextInspection */
|
|
||||||
$data_string = substr($data_string, $pos);
|
$data_string = substr($data_string, $pos);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1309,7 +1313,7 @@ class Csv {
|
|||||||
* @param string $enclosure Enclosure character, default is double quote
|
* @param string $enclosure Enclosure character, default is double quote
|
||||||
* @param string $data The file content
|
* @param string $data The file content
|
||||||
*/
|
*/
|
||||||
protected function _guess_delimiter($search_depth, $preferred, $enclosure, &$data) {
|
protected function _guess_delimiter($search_depth, $preferred, $enclosure, $data) {
|
||||||
$chars = [];
|
$chars = [];
|
||||||
$strlen = strlen($data);
|
$strlen = strlen($data);
|
||||||
$enclosed = false;
|
$enclosed = false;
|
||||||
|
|||||||
@@ -26,5 +26,4 @@ class SortEnum extends AbstractEnum {
|
|||||||
|
|
||||||
return self::$sorting[self::__DEFAULT];
|
return self::$sorting[self::__DEFAULT];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace PHPUnit\Framework;
|
|
||||||
|
|
||||||
// Only needed to keep unit test code compatible with older PHPUnit versions
|
|
||||||
|
|
||||||
/** @noinspection PhpUndefinedClassInspection */
|
|
||||||
/** @noinspection AutoloadingIssuesInspection */
|
|
||||||
class TestCase extends \PHPUnit_Framework_TestCase {
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user