From b4e4c14b42bd49eaf1bcbc8abce7f420ba443364 Mon Sep 17 00:00:00 2001 From: Petri Haikonen Date: Wed, 8 Apr 2020 23:08:55 +0300 Subject: [PATCH] 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 --- .travis.yml | 2 - composer.json | 3 +- ruleset.xml | 3 ++ src/Csv.php | 62 +++++++++++++----------- src/enums/SortEnum.php | 1 - tests/PHPUnit_Framework_TestCase.inc.php | 11 ----- 6 files changed, 38 insertions(+), 44 deletions(-) create mode 100644 ruleset.xml delete mode 100644 tests/PHPUnit_Framework_TestCase.inc.php diff --git a/.travis.yml b/.travis.yml index 942aac3..8c1ee62 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,6 @@ php: - '7.2' - '7.1' - '7.0' - - '5.6' - - '5.5' before_install: - composer update diff --git a/composer.json b/composer.json index ec210cb..8a34e64 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,8 @@ "php": ">=5.5" }, "require-dev": { - "phpunit/phpunit": "4.1.*" + "phpunit/phpunit": "^6", + "squizlabs/php_codesniffer": "^3.5" }, "suggest": { "illuminate/support": "Fluent array interface for map functions" diff --git a/ruleset.xml b/ruleset.xml new file mode 100644 index 0000000..0697ff5 --- /dev/null +++ b/ruleset.xml @@ -0,0 +1,3 @@ + + + diff --git a/src/Csv.php b/src/Csv.php index 6d8920c..56cc974 100644 --- a/src/Csv.php +++ b/src/Csv.php @@ -311,16 +311,16 @@ class Csv { * Constructor * Class constructor * - * @param string|null $input The CSV string or a direct file path - * @param integer|null $offset Number of rows to ignore from the - * beginning of the data - * @param integer|null $limit Limits the number of returned rows - * to specified amount - * @param string|null $conditions Basic SQL-like conditions for row - * matching - * @param null|true $keep_file_data Keep raw file data in memory after - * successful parsing - * (useful for debugging) + * @param string|null $input The CSV string or a direct file path + * @param int|null $offset Number of rows to ignore from the + * beginning of the data + * @param int|null $limit Limits the number of returned rows + * to specified amount + * @param string|null $conditions Basic SQL-like conditions for row + * matching + * @param null|true $keep_file_data Keep raw file data in memory after + * successful parsing + * (useful for debugging) */ public function __construct($input = null, $offset = null, $limit = null, $conditions = null, $keep_file_data = null) { $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 - * @param integer|null $limit Limits the number of returned rows + * @param int|null $limit Limits the number of returned rows * to specified amount - * @param string|null $conditions Basic SQL-like conditions for row + * @param string|null $conditions Basic SQL-like conditions for row * 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 * (useful for debugging) */ @@ -368,11 +368,11 @@ class Csv { * Parse a CSV file or string * * @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 - * @param integer $limit Limits the number of returned rows to + * @param int|null $limit Limits the number of returned rows to * specified amount - * @param string $conditions Basic SQL-like conditions for row + * @param string|null $conditions Basic SQL-like conditions for row * matching * * @return bool True on success @@ -474,8 +474,10 @@ class Csv { * Encoding * Convert character encoding * - * @param string $input Input character encoding, uses default if left blank - * @param string $output Output character encoding, uses default if left blank + * @param string|null $input Input 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) { $this->convert_encoding = true; @@ -495,11 +497,11 @@ class Csv { * * @param string|null $file Local CSV file * @param bool $parse True/false parse file directly - * @param int $search_depth Number of rows to analyze - * @param string $preferred Preferred delimiter characters + * @param int|null $search_depth Number of rows to analyze + * @param string|null $preferred Preferred delimiter characters * @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) { if (is_null($file)) { @@ -572,12 +574,10 @@ class Csv { $headingRow = $this->heading ? 1 : 0; - $count = substr_count($data, "\r") + return substr_count($data, "\r") + substr_count($data, "\n") - substr_count($data, "\r\n") - $headingRow; - - return $count; } // ============================================== @@ -613,7 +613,7 @@ class Csv { * * 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 */ @@ -861,7 +861,12 @@ class Csv { 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)) { $fields = $this->titles; } @@ -1298,7 +1303,6 @@ class Csv { } // remove delimiter and its line-end (the data param is by-ref!) - /** @noinspection CallableParameterUseCaseInTypeContextInspection */ $data_string = substr($data_string, $pos); return true; } @@ -1309,7 +1313,7 @@ class Csv { * @param string $enclosure Enclosure character, default is double quote * @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 = []; $strlen = strlen($data); $enclosed = false; diff --git a/src/enums/SortEnum.php b/src/enums/SortEnum.php index fd1cb1e..5d50e79 100644 --- a/src/enums/SortEnum.php +++ b/src/enums/SortEnum.php @@ -26,5 +26,4 @@ class SortEnum extends AbstractEnum { return self::$sorting[self::__DEFAULT]; } - } diff --git a/tests/PHPUnit_Framework_TestCase.inc.php b/tests/PHPUnit_Framework_TestCase.inc.php deleted file mode 100644 index 56babef..0000000 --- a/tests/PHPUnit_Framework_TestCase.inc.php +++ /dev/null @@ -1,11 +0,0 @@ -