diff --git a/.travis.yml b/.travis.yml index e3ceefd..8341b0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,20 @@ language: php php: + - 7.3 - 7.2 - 7.1 - 7.0 - 5.6 - 5.5 +before_install: + - composer update + script: - - phpunit --version - - phpunit --configuration tests/phpunit.xml + - composer validate + - vendor/bin/phpunit --version + - vendor/bin/phpunit --configuration tests/phpunit.xml notifications: email: diff --git a/composer.json b/composer.json index cf6af5a..de3d7d7 100644 --- a/composer.json +++ b/composer.json @@ -20,14 +20,14 @@ "homepage": "https://github.com/Fonata" } ], - "autoload":{ - "psr-4":{ + "autoload": { + "psr-4": { "ParseCsv\\": "src", "ParseCsv\\extensions\\": "src\\extensions" } }, - "autoload-dev":{ - "psr-4":{ + "autoload-dev": { + "psr-4": { "ParseCsv\\tests\\": "tests" } }, @@ -40,6 +40,11 @@ "suggest": { "illuminate/support": "Fluent array interface for map functions" }, + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, "support": { "issues": "https://github.com/parsecsv/parsecsv-for-php/issues", "source": "https://github.com/parsecsv/parsecsv-for-php" diff --git a/examples/basic.php b/examples/basic.php index 66f1abc..7ed355a 100644 --- a/examples/basic.php +++ b/examples/basic.php @@ -3,6 +3,7 @@ # include parseCSV class. require __DIR__ . '/../vendor/autoload.php'; + use ParseCsv\Csv; diff --git a/examples/conditions.php b/examples/conditions.php index 547d43a..f085064 100644 --- a/examples/conditions.php +++ b/examples/conditions.php @@ -4,6 +4,7 @@ # include parseCSV class. require __DIR__ . '/../vendor/autoload.php'; + use ParseCsv\Csv; diff --git a/examples/download.php b/examples/download.php index 4a54d4f..9babb87 100644 --- a/examples/download.php +++ b/examples/download.php @@ -3,6 +3,7 @@ # include parseCSV class. require __DIR__ . '/../vendor/autoload.php'; + use ParseCsv\Csv; diff --git a/examples/limit.php b/examples/limit.php index 8734f77..4adeb0c 100644 --- a/examples/limit.php +++ b/examples/limit.php @@ -4,6 +4,7 @@ # include parseCSV class. require __DIR__ . '/../vendor/autoload.php'; + use ParseCsv\Csv; diff --git a/src/Csv.php b/src/Csv.php index ec2e998..cf9a208 100644 --- a/src/Csv.php +++ b/src/Csv.php @@ -151,7 +151,7 @@ class Csv { public $auto_depth = 15; /** - * Auto Non Charts + * Auto Non Chars * Characters that should be ignored when attempting to auto-detect delimiter * * @var string @@ -287,7 +287,7 @@ class Csv { /** * Data - * Two dimensional array of CSV data + * Two-dimensional array of CSV data * * @var array */ @@ -299,7 +299,7 @@ class Csv { * Constructor * Class constructor * - * @param string|null $input The CSV string or a direct filepath + * @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 @@ -355,7 +355,7 @@ class Csv { * Parse * Parse a CSV file or string * - * @param string|null $input The CSV string or a direct filepath + * @param string|null $input The CSV string or a direct file path * @param integer $offset Number of rows to ignore from the * beginning of the data * @param integer $limit Limits the number of returned rows to diff --git a/src/enums/AbstractEnum.php b/src/enums/AbstractEnum.php index aae78e1..19dae3f 100644 --- a/src/enums/AbstractEnum.php +++ b/src/enums/AbstractEnum.php @@ -1,9 +1,9 @@ isValid($value)) { throw new \UnexpectedValueException("Value '$value' is not part of the enum " . get_called_class()); } $this->value = $value; } - public static function getConstants(){ + public static function getConstants() { $class = get_called_class(); $reflection = new \ReflectionClass($class); @@ -33,8 +32,7 @@ abstract class AbstractEnum { * * @return bool */ - public static function isValid($value) - { + public static function isValid($value) { return in_array($value, static::getConstants(), true); } } diff --git a/src/enums/FileProcessingModeEnum.php b/src/enums/FileProcessingModeEnum.php index ab88055..b545c68 100644 --- a/src/enums/FileProcessingModeEnum.php +++ b/src/enums/FileProcessingModeEnum.php @@ -19,7 +19,7 @@ class FileProcessingModeEnum { const MODE_FILE_OVERWRITE = false; public static function getAppendMode($mode) { - if ($mode == self::MODE_FILE_APPEND){ + if ($mode == self::MODE_FILE_APPEND) { return 'ab'; } diff --git a/src/enums/SortEnum.php b/src/enums/SortEnum.php index 54c3040..fd1cb1e 100644 --- a/src/enums/SortEnum.php +++ b/src/enums/SortEnum.php @@ -1,8 +1,10 @@ SORT_REGULAR, self::SORT_TYPE_STRING => SORT_STRING, - self::SORT_TYPE_NUMERIC => SORT_NUMERIC + self::SORT_TYPE_NUMERIC => SORT_NUMERIC, ); - public static function getSorting($type){ - if (array_key_exists($type, self::$sorting)){ + public static function getSorting($type) { + if (array_key_exists($type, self::$sorting)) { return self::$sorting[$type]; } diff --git a/src/extensions/DatatypeTrait.php b/src/extensions/DatatypeTrait.php index 475fc40..a939006 100644 --- a/src/extensions/DatatypeTrait.php +++ b/src/extensions/DatatypeTrait.php @@ -7,10 +7,10 @@ use ParseCsv\enums\DatatypeEnum; trait DatatypeTrait { /** - * Datatypes - * Datatypes of CSV data-columns + * Data Types + * Data types of CSV data-columns, keyed by the column name. Possible values + * are string, float, integer, boolean, date. See DatatypeEnum. * - * @access public * @var array */ public $data_types = []; @@ -19,8 +19,6 @@ trait DatatypeTrait { * Check data type for one column. * Check for most commonly data type for one column. * - * @access private - * * @param array $datatypes * * @return string|false @@ -47,8 +45,6 @@ trait DatatypeTrait { * * Requires PHP >= 5.5 * - * @access public - * * @uses DatatypeEnum::getValidTypeFromSample * * @return array|bool @@ -80,34 +76,28 @@ trait DatatypeTrait { * * Requires PHP >= 5.5 * - * @access public - * * @uses DatatypeEnum::getValidTypeFromSample * * @return bool */ - public function autoDetectFileHasHeading(){ - if (empty($this->data)){ + public function autoDetectFileHasHeading() { + if (empty($this->data)) { throw new \UnexpectedValueException('No data set yet.'); } - if ($this->heading){ + if ($this->heading) { $firstRow = $this->titles; } else { $firstRow = $this->data[0]; } $firstRow = array_filter($firstRow); - if (empty($firstRow)){ + if (empty($firstRow)) { return false; } $firstRowDatatype = array_map(DatatypeEnum::class . '::getValidTypeFromSample', $firstRow); - if ($this->getMostFrequentDatatypeForColumn($firstRowDatatype) !== DatatypeEnum::TYPE_STRING){ - return false; - } - - return true; + return $this->getMostFrequentDatatypeForColumn($firstRowDatatype) === DatatypeEnum::TYPE_STRING; } } diff --git a/tests/methods/DatatypeTest.php b/tests/methods/DatatypeTest.php index 35c7f9e..cd1cf95 100644 --- a/tests/methods/DatatypeTest.php +++ b/tests/methods/DatatypeTest.php @@ -8,12 +8,12 @@ namespace ParseCsv\tests\methods; -use PHPUnit\Framework\TestCase; use ParseCsv\enums\DatatypeEnum; +use PHPUnit\Framework\TestCase; -class DatatypeTest extends TestCase -{ - public function testSampleIsValidInteger(){ +class DatatypeTest extends TestCase { + + public function testSampleIsValidInteger() { $this->assertEquals(DatatypeEnum::TYPE_INT, DatatypeEnum::getValidTypeFromSample('1')); $this->assertEquals(DatatypeEnum::TYPE_INT, DatatypeEnum::getValidTypeFromSample('+1')); $this->assertEquals(DatatypeEnum::TYPE_INT, DatatypeEnum::getValidTypeFromSample('-1')); @@ -27,7 +27,7 @@ class DatatypeTest extends TestCase $this->assertNotEquals(DatatypeEnum::TYPE_INT, DatatypeEnum::getValidTypeFromSample('2018-02-19')); } - public function testSampleIsValidBool(){ + public function testSampleIsValidBool() { $this->assertEquals(DatatypeEnum::TYPE_BOOL, DatatypeEnum::getValidTypeFromSample('true')); $this->assertEquals(DatatypeEnum::TYPE_BOOL, DatatypeEnum::getValidTypeFromSample('TRUE')); $this->assertEquals(DatatypeEnum::TYPE_BOOL, DatatypeEnum::getValidTypeFromSample('false')); @@ -39,7 +39,7 @@ class DatatypeTest extends TestCase $this->assertNotEquals(DatatypeEnum::TYPE_BOOL, DatatypeEnum::getValidTypeFromSample('0.1')); } - public function testSampleIsValidFloat(){ + public function testSampleIsValidFloat() { $this->assertEquals(DatatypeEnum::TYPE_FLOAT, DatatypeEnum::getValidTypeFromSample('1.0')); $this->assertEquals(DatatypeEnum::TYPE_FLOAT, DatatypeEnum::getValidTypeFromSample('-1.1')); $this->assertEquals(DatatypeEnum::TYPE_FLOAT, DatatypeEnum::getValidTypeFromSample('+1,1')); @@ -54,7 +54,7 @@ class DatatypeTest extends TestCase $this->assertNotEquals(DatatypeEnum::TYPE_FLOAT, DatatypeEnum::getValidTypeFromSample('2018-02-19')); } - public function testSampleIsValidDate(){ + public function testSampleIsValidDate() { $this->assertEquals(DatatypeEnum::TYPE_DATE, DatatypeEnum::getValidTypeFromSample('2018-02-19')); $this->assertEquals(DatatypeEnum::TYPE_DATE, DatatypeEnum::getValidTypeFromSample('18-2-19')); $this->assertEquals(DatatypeEnum::TYPE_DATE, DatatypeEnum::getValidTypeFromSample('01.02.2018')); diff --git a/tests/methods/ParseTest.php b/tests/methods/ParseTest.php index 39cc3cd..4aa4bcd 100644 --- a/tests/methods/ParseTest.php +++ b/tests/methods/ParseTest.php @@ -238,9 +238,9 @@ class ParseTest extends TestCase { /** * Call protected/private method of a class. * - * @param object &$object Instantiated object that we will run method on. - * @param string $methodName Method name to call - * @param array $parameters Array of parameters to pass into method. + * @param object &$object Instantiated object that we will run method on. + * @param string $methodName Method name to call + * @param array $parameters Array of parameters to pass into method. * * @return mixed Method return. */ diff --git a/tests/methods/SaveTest.php b/tests/methods/SaveTest.php index 335844c..88d2fae 100644 --- a/tests/methods/SaveTest.php +++ b/tests/methods/SaveTest.php @@ -1,11 +1,11 @@ unparseAndCompare($expected, $fields); } - public function testUnparseDefaultFirstRowMissing(){ + public function testUnparseDefaultFirstRowMissing() { unset($this->csv->data[0]); $expected = "column1,column2\rvalue3,value4\r"; $this->unparseAndCompare($expected); } - public function testUnparseDefaultWithoutData(){ + public function testUnparseDefaultWithoutData() { unset($this->csv->data[0]); unset($this->csv->data[1]); $expected = "column1,column2\r"; diff --git a/tests/properties/BaseClass.php b/tests/properties/BaseClass.php index a81f5c6..9341293 100644 --- a/tests/properties/BaseClass.php +++ b/tests/properties/BaseClass.php @@ -11,7 +11,6 @@ class BaseClass extends TestCase { * CSV * The parseCSV object * - * @access protected * @var Csv */ protected $csv; @@ -19,10 +18,8 @@ class BaseClass extends TestCase { /** * Setup * Setup our test environment objects - * - * @access public */ - public function setUp() { + protected function setUp() { $this->csv = new Csv(); } diff --git a/tests/properties/OffsetTest.php b/tests/properties/OffsetTest.php index 728201c..3c9b2eb 100644 --- a/tests/properties/OffsetTest.php +++ b/tests/properties/OffsetTest.php @@ -6,6 +6,7 @@ namespace ParseCsv\tests\properties; * Tests related to the $offset property */ class OffsetTest extends BaseClass { + public function testOffsetOfOne() { $this->csv->offset = 1; $this->csv->auto(__DIR__ . '/../methods/fixtures/datatype.csv'); diff --git a/tests/properties/PublicPropertiesTest.php b/tests/properties/PublicPropertiesTest.php index ed49354..b90c32f 100644 --- a/tests/properties/PublicPropertiesTest.php +++ b/tests/properties/PublicPropertiesTest.php @@ -147,25 +147,25 @@ class PublicPropertiesTest extends TestCase { $this->assertCount($counter, $this->properties); } - public function testDefaultSortTypeIsRegular(){ - $this->assertEquals(SortEnum::SORT_TYPE_REGULAR, $this->csv->sort_type); + public function testDefaultSortTypeIsRegular() { + $this->assertEquals(SortEnum::SORT_TYPE_REGULAR, $this->csv->sort_type); } - public function testSetSortType(){ + public function testSetSortType() { $this->csv->sort_type = 'numeric'; - $this->assertEquals(SortEnum::SORT_TYPE_NUMERIC, $this->csv->sort_type); + $this->assertEquals(SortEnum::SORT_TYPE_NUMERIC, $this->csv->sort_type); $this->csv->sort_type = 'string'; - $this->assertEquals(SortEnum::SORT_TYPE_STRING, $this->csv->sort_type); + $this->assertEquals(SortEnum::SORT_TYPE_STRING, $this->csv->sort_type); } - public function testGetSorting(){ + public function testGetSorting() { $this->csv->sort_type = 'numeric'; $sorting = SortEnum::getSorting($this->csv->sort_type); - $this->assertEquals(SORT_NUMERIC, $sorting); + $this->assertEquals(SORT_NUMERIC, $sorting); $this->csv->sort_type = 'string'; $sorting = SortEnum::getSorting($this->csv->sort_type); - $this->assertEquals(SORT_STRING, $sorting); + $this->assertEquals(SORT_STRING, $sorting); } }