mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
Only improved code formatting
This commit is contained in:
@@ -20,14 +20,14 @@
|
|||||||
"homepage": "https://github.com/Fonata"
|
"homepage": "https://github.com/Fonata"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"autoload":{
|
"autoload": {
|
||||||
"psr-4":{
|
"psr-4": {
|
||||||
"ParseCsv\\": "src",
|
"ParseCsv\\": "src",
|
||||||
"ParseCsv\\extensions\\": "src\\extensions"
|
"ParseCsv\\extensions\\": "src\\extensions"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload-dev":{
|
"autoload-dev": {
|
||||||
"psr-4":{
|
"psr-4": {
|
||||||
"ParseCsv\\tests\\": "tests"
|
"ParseCsv\\tests\\": "tests"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
# include parseCSV class.
|
# include parseCSV class.
|
||||||
require __DIR__ . '/../vendor/autoload.php';
|
require __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
use ParseCsv\Csv;
|
use ParseCsv\Csv;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
# include parseCSV class.
|
# include parseCSV class.
|
||||||
require __DIR__ . '/../vendor/autoload.php';
|
require __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
use ParseCsv\Csv;
|
use ParseCsv\Csv;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
# include parseCSV class.
|
# include parseCSV class.
|
||||||
require __DIR__ . '/../vendor/autoload.php';
|
require __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
use ParseCsv\Csv;
|
use ParseCsv\Csv;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
# include parseCSV class.
|
# include parseCSV class.
|
||||||
require __DIR__ . '/../vendor/autoload.php';
|
require __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
use ParseCsv\Csv;
|
use ParseCsv\Csv;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ParseCsv\enums;
|
namespace ParseCsv\enums;
|
||||||
|
|
||||||
use ReflectionClass;
|
|
||||||
|
|
||||||
abstract class AbstractEnum {
|
abstract class AbstractEnum {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new value of some type
|
* Creates a new value of some type
|
||||||
*
|
*
|
||||||
@@ -11,15 +11,14 @@ abstract class AbstractEnum {
|
|||||||
*
|
*
|
||||||
* @throws \UnexpectedValueException if incompatible type is given.
|
* @throws \UnexpectedValueException if incompatible type is given.
|
||||||
*/
|
*/
|
||||||
public function __construct($value)
|
public function __construct($value) {
|
||||||
{
|
|
||||||
if (!$this->isValid($value)) {
|
if (!$this->isValid($value)) {
|
||||||
throw new \UnexpectedValueException("Value '$value' is not part of the enum " . get_called_class());
|
throw new \UnexpectedValueException("Value '$value' is not part of the enum " . get_called_class());
|
||||||
}
|
}
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getConstants(){
|
public static function getConstants() {
|
||||||
$class = get_called_class();
|
$class = get_called_class();
|
||||||
$reflection = new \ReflectionClass($class);
|
$reflection = new \ReflectionClass($class);
|
||||||
|
|
||||||
@@ -33,8 +32,7 @@ abstract class AbstractEnum {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isValid($value)
|
public static function isValid($value) {
|
||||||
{
|
|
||||||
return in_array($value, static::getConstants(), true);
|
return in_array($value, static::getConstants(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class FileProcessingModeEnum {
|
|||||||
const MODE_FILE_OVERWRITE = false;
|
const MODE_FILE_OVERWRITE = false;
|
||||||
|
|
||||||
public static function getAppendMode($mode) {
|
public static function getAppendMode($mode) {
|
||||||
if ($mode == self::MODE_FILE_APPEND){
|
if ($mode == self::MODE_FILE_APPEND) {
|
||||||
return 'ab';
|
return 'ab';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ParseCsv\enums;
|
namespace ParseCsv\enums;
|
||||||
|
|
||||||
|
|
||||||
class SortEnum extends AbstractEnum {
|
class SortEnum extends AbstractEnum {
|
||||||
|
|
||||||
const __DEFAULT = self::SORT_TYPE_REGULAR;
|
const __DEFAULT = self::SORT_TYPE_REGULAR;
|
||||||
|
|
||||||
const SORT_TYPE_REGULAR = 'regular';
|
const SORT_TYPE_REGULAR = 'regular';
|
||||||
@@ -14,11 +16,11 @@ class SortEnum extends AbstractEnum {
|
|||||||
private static $sorting = array(
|
private static $sorting = array(
|
||||||
self::SORT_TYPE_REGULAR => SORT_REGULAR,
|
self::SORT_TYPE_REGULAR => SORT_REGULAR,
|
||||||
self::SORT_TYPE_STRING => SORT_STRING,
|
self::SORT_TYPE_STRING => SORT_STRING,
|
||||||
self::SORT_TYPE_NUMERIC => SORT_NUMERIC
|
self::SORT_TYPE_NUMERIC => SORT_NUMERIC,
|
||||||
);
|
);
|
||||||
|
|
||||||
public static function getSorting($type){
|
public static function getSorting($type) {
|
||||||
if (array_key_exists($type, self::$sorting)){
|
if (array_key_exists($type, self::$sorting)) {
|
||||||
return self::$sorting[$type];
|
return self::$sorting[$type];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,19 +80,19 @@ trait DatatypeTrait {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function autoDetectFileHasHeading(){
|
public function autoDetectFileHasHeading() {
|
||||||
if (empty($this->data)){
|
if (empty($this->data)) {
|
||||||
throw new \UnexpectedValueException('No data set yet.');
|
throw new \UnexpectedValueException('No data set yet.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->heading){
|
if ($this->heading) {
|
||||||
$firstRow = $this->titles;
|
$firstRow = $this->titles;
|
||||||
} else {
|
} else {
|
||||||
$firstRow = $this->data[0];
|
$firstRow = $this->data[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$firstRow = array_filter($firstRow);
|
$firstRow = array_filter($firstRow);
|
||||||
if (empty($firstRow)){
|
if (empty($firstRow)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,12 @@
|
|||||||
|
|
||||||
namespace ParseCsv\tests\methods;
|
namespace ParseCsv\tests\methods;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use ParseCsv\enums\DatatypeEnum;
|
use ParseCsv\enums\DatatypeEnum;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class DatatypeTest extends TestCase
|
class DatatypeTest extends TestCase {
|
||||||
{
|
|
||||||
public function testSampleIsValidInteger(){
|
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'));
|
$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'));
|
$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('TRUE'));
|
$this->assertEquals(DatatypeEnum::TYPE_BOOL, DatatypeEnum::getValidTypeFromSample('TRUE'));
|
||||||
$this->assertEquals(DatatypeEnum::TYPE_BOOL, DatatypeEnum::getValidTypeFromSample('false'));
|
$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'));
|
$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.0'));
|
||||||
$this->assertEquals(DatatypeEnum::TYPE_FLOAT, DatatypeEnum::getValidTypeFromSample('-1.1'));
|
$this->assertEquals(DatatypeEnum::TYPE_FLOAT, DatatypeEnum::getValidTypeFromSample('-1.1'));
|
||||||
$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'));
|
$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('2018-02-19'));
|
||||||
$this->assertEquals(DatatypeEnum::TYPE_DATE, DatatypeEnum::getValidTypeFromSample('18-2-19'));
|
$this->assertEquals(DatatypeEnum::TYPE_DATE, DatatypeEnum::getValidTypeFromSample('18-2-19'));
|
||||||
$this->assertEquals(DatatypeEnum::TYPE_DATE, DatatypeEnum::getValidTypeFromSample('01.02.2018'));
|
$this->assertEquals(DatatypeEnum::TYPE_DATE, DatatypeEnum::getValidTypeFromSample('01.02.2018'));
|
||||||
|
|||||||
@@ -238,9 +238,9 @@ class ParseTest extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* Call protected/private method of a class.
|
* Call protected/private method of a class.
|
||||||
*
|
*
|
||||||
* @param object &$object Instantiated object that we will run method on.
|
* @param object &$object Instantiated object that we will run method on.
|
||||||
* @param string $methodName Method name to call
|
* @param string $methodName Method name to call
|
||||||
* @param array $parameters Array of parameters to pass into method.
|
* @param array $parameters Array of parameters to pass into method.
|
||||||
*
|
*
|
||||||
* @return mixed Method return.
|
* @return mixed Method return.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace ParseCsv\tests\methods;
|
namespace ParseCsv\tests\methods;
|
||||||
|
|
||||||
use ParseCsv\Csv;
|
use ParseCsv\Csv;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class SaveTest extends TestCase
|
class SaveTest extends TestCase {
|
||||||
{
|
|
||||||
|
|
||||||
/** @var Csv */
|
/** @var Csv */
|
||||||
private $csv;
|
private $csv;
|
||||||
|
|||||||
@@ -75,13 +75,13 @@ class UnparseTest extends Testcase {
|
|||||||
$this->unparseAndCompare($expected, $fields);
|
$this->unparseAndCompare($expected, $fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnparseDefaultFirstRowMissing(){
|
public function testUnparseDefaultFirstRowMissing() {
|
||||||
unset($this->csv->data[0]);
|
unset($this->csv->data[0]);
|
||||||
$expected = "column1,column2\rvalue3,value4\r";
|
$expected = "column1,column2\rvalue3,value4\r";
|
||||||
$this->unparseAndCompare($expected);
|
$this->unparseAndCompare($expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnparseDefaultWithoutData(){
|
public function testUnparseDefaultWithoutData() {
|
||||||
unset($this->csv->data[0]);
|
unset($this->csv->data[0]);
|
||||||
unset($this->csv->data[1]);
|
unset($this->csv->data[1]);
|
||||||
$expected = "column1,column2\r";
|
$expected = "column1,column2\r";
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace ParseCsv\tests\properties;
|
|||||||
* Tests related to the $offset property
|
* Tests related to the $offset property
|
||||||
*/
|
*/
|
||||||
class OffsetTest extends BaseClass {
|
class OffsetTest extends BaseClass {
|
||||||
|
|
||||||
public function testOffsetOfOne() {
|
public function testOffsetOfOne() {
|
||||||
$this->csv->offset = 1;
|
$this->csv->offset = 1;
|
||||||
$this->csv->auto(__DIR__ . '/../methods/fixtures/datatype.csv');
|
$this->csv->auto(__DIR__ . '/../methods/fixtures/datatype.csv');
|
||||||
|
|||||||
@@ -147,25 +147,25 @@ class PublicPropertiesTest extends TestCase {
|
|||||||
$this->assertCount($counter, $this->properties);
|
$this->assertCount($counter, $this->properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefaultSortTypeIsRegular(){
|
public function testDefaultSortTypeIsRegular() {
|
||||||
$this->assertEquals(SortEnum::SORT_TYPE_REGULAR, $this->csv->sort_type);
|
$this->assertEquals(SortEnum::SORT_TYPE_REGULAR, $this->csv->sort_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetSortType(){
|
public function testSetSortType() {
|
||||||
$this->csv->sort_type = 'numeric';
|
$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->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';
|
$this->csv->sort_type = 'numeric';
|
||||||
$sorting = SortEnum::getSorting($this->csv->sort_type);
|
$sorting = SortEnum::getSorting($this->csv->sort_type);
|
||||||
$this->assertEquals(SORT_NUMERIC, $sorting);
|
$this->assertEquals(SORT_NUMERIC, $sorting);
|
||||||
|
|
||||||
$this->csv->sort_type = 'string';
|
$this->csv->sort_type = 'string';
|
||||||
$sorting = SortEnum::getSorting($this->csv->sort_type);
|
$sorting = SortEnum::getSorting($this->csv->sort_type);
|
||||||
$this->assertEquals(SORT_STRING, $sorting);
|
$this->assertEquals(SORT_STRING, $sorting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user