Make CSV reader return Row objects

This commit is contained in:
Adrien Loison 2017-11-18 18:32:11 +01:00
parent 139f7fdfb3
commit a665b974fa
37 changed files with 664 additions and 214 deletions

View File

@ -0,0 +1,54 @@
<?php
namespace Box\Spout\Common\Helper;
/**
* Class CellTypeHelper
* This class provides helper functions to determine the type of the cell value
*/
class CellTypeHelper
{
/**
* @param $value
* @return bool Whether the given value is considered "empty"
*/
public static function isEmpty($value)
{
return ($value === null || $value === '');
}
/**
* @param $value
* @return bool Whether the given value is a non empty string
*/
public static function isNonEmptyString($value)
{
return (gettype($value) === 'string' && $value !== '');
}
/**
* Returns whether the given value is numeric.
* A numeric value is from type "integer" or "double" ("float" is not returned by gettype).
*
* @param $value
* @return bool Whether the given value is numeric
*/
public static function isNumeric($value)
{
$valueType = gettype($value);
return ($valueType === 'integer' || $valueType === 'double');
}
/**
* Returns whether the given value is boolean.
* "true"/"false" and 0/1 are not booleans.
*
* @param $value
* @return bool Whether the given value is boolean
*/
public static function isBoolean($value)
{
return gettype($value) === 'boolean';
}
}

View File

@ -5,7 +5,9 @@ namespace Box\Spout\Reader\CSV\Creator;
use Box\Spout\Common\Creator\HelperFactory;
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Reader\Common\Creator\EntityFactoryInterface;
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface;
use Box\Spout\Reader\Common\Entity\Cell;
use Box\Spout\Reader\Common\Entity\Row;
use Box\Spout\Reader\CSV\RowIterator;
use Box\Spout\Reader\CSV\Sheet;
use Box\Spout\Reader\CSV\SheetIterator;
@ -14,7 +16,7 @@ use Box\Spout\Reader\CSV\SheetIterator;
* Class EntityFactory
* Factory to create entities
*/
class EntityFactory implements EntityFactoryInterface
class InternalEntityFactory implements InternalEntityFactoryInterface
{
/** @var HelperFactory */
private $helperFactory;
@ -60,6 +62,19 @@ class EntityFactory implements EntityFactoryInterface
{
$encodingHelper = $this->helperFactory->createEncodingHelper($globalFunctionsHelper);
return new RowIterator($filePointer, $optionsManager, $encodingHelper, $globalFunctionsHelper);
return new RowIterator($filePointer, $optionsManager, $encodingHelper, $this, $globalFunctionsHelper);
}
/**
* @param array $cellValues
* @return Row
*/
public function createRowFromArray(array $cellValues = [])
{
$cells = array_map(function ($cellValue) {
return new Cell($cellValue);
}, $cellValues);
return new Row($cells);
}
}

View File

@ -4,7 +4,7 @@ namespace Box\Spout\Reader\CSV;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Reader\Common\Entity\Options;
use Box\Spout\Reader\CSV\Creator\EntityFactory;
use Box\Spout\Reader\CSV\Creator\InternalEntityFactory;
use Box\Spout\Reader\ReaderAbstract;
/**
@ -92,7 +92,7 @@ class Reader extends ReaderAbstract
throw new IOException("Could not open file $filePath for reading.");
}
/** @var EntityFactory $entityFactory */
/** @var InternalEntityFactory $entityFactory */
$entityFactory = $this->entityFactory;
$this->sheetIterator = $entityFactory->createSheetIterator(

View File

@ -3,7 +3,11 @@
namespace Box\Spout\Reader\CSV;
use Box\Spout\Common\Helper\EncodingHelper;
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Reader\Common\Entity\Options;
use Box\Spout\Reader\Common\Entity\Row;
use Box\Spout\Reader\CSV\Creator\InternalEntityFactory;
use Box\Spout\Reader\IteratorInterface;
/**
@ -23,7 +27,7 @@ class RowIterator implements IteratorInterface
/** @var int Number of read rows */
protected $numReadRows = 0;
/** @var array|null Buffer used to store the row data, while checking if there are more rows to read */
/** @var Row|null Buffer used to store the row data, while checking if there are more rows to read */
protected $rowDataBuffer;
/** @var bool Indicates whether all rows have been read */
@ -41,26 +45,36 @@ class RowIterator implements IteratorInterface
/** @var bool Whether empty rows should be returned or skipped */
protected $shouldPreserveEmptyRows;
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */
protected $globalFunctionsHelper;
/** @var \Box\Spout\Common\Helper\EncodingHelper Helper to work with different encodings */
protected $encodingHelper;
/** @var \Box\Spout\Reader\CSV\Creator\InternalEntityFactory Factory to create entities */
protected $entityFactory;
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */
protected $globalFunctionsHelper;
/**
* @param resource $filePointer Pointer to the CSV file to read
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager
* @param \Box\Spout\Common\Helper\EncodingHelper $encodingHelper
* @param \Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper
* @param OptionsManagerInterface $optionsManager
* @param EncodingHelper $encodingHelper
* @param InternalEntityFactory $entityFactory
* @param GlobalFunctionsHelper $globalFunctionsHelper
*/
public function __construct($filePointer, $optionsManager, $encodingHelper, $globalFunctionsHelper)
{
public function __construct(
$filePointer,
OptionsManagerInterface $optionsManager,
EncodingHelper $encodingHelper,
InternalEntityFactory $entityFactory,
GlobalFunctionsHelper $globalFunctionsHelper
) {
$this->filePointer = $filePointer;
$this->fieldDelimiter = $optionsManager->getOption(Options::FIELD_DELIMITER);
$this->fieldEnclosure = $optionsManager->getOption(Options::FIELD_ENCLOSURE);
$this->encoding = $optionsManager->getOption(Options::ENCODING);
$this->shouldPreserveEmptyRows = $optionsManager->getOption(Options::SHOULD_PRESERVE_EMPTY_ROWS);
$this->encodingHelper = $encodingHelper;
$this->entityFactory = $entityFactory;
$this->globalFunctionsHelper = $globalFunctionsHelper;
}
@ -133,7 +147,8 @@ class RowIterator implements IteratorInterface
if ($rowData !== false) {
// str_replace will replace NULL values by empty strings
$this->rowDataBuffer = str_replace(null, null, $rowData);
$rowDataBufferAsArray = str_replace(null, null, $rowData);
$this->rowDataBuffer = $this->entityFactory->createRowFromArray($rowDataBufferAsArray);
$this->numReadRows++;
} else {
// If we reach this point, it means end of file was reached.
@ -207,7 +222,7 @@ class RowIterator implements IteratorInterface
* Return the current element from the buffer
* @see http://php.net/manual/en/iterator.current.php
*
* @return array|null
* @return Row|null
*/
public function current()
{

View File

@ -0,0 +1,25 @@
<?php
namespace Box\Spout\Reader\Common\Creator;
use Box\Spout\Reader\ReaderFactory;
use Box\Spout\Reader\ReaderInterface;
/**
* Class EntityFactory
* Factory to create external entities
*/
class EntityFactory
{
/**
* This creates an instance of the appropriate reader, given the type of the file to be read
*
* @param string $readerType Type of the reader to instantiate
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException
* @return ReaderInterface
*/
public static function createReader($readerType)
{
return (new ReaderFactory())->create($readerType);
}
}

View File

@ -5,6 +5,6 @@ namespace Box\Spout\Reader\Common\Creator;
/**
* Interface EntityFactoryInterface
*/
interface EntityFactoryInterface
interface InternalEntityFactoryInterface
{
}

View File

@ -0,0 +1,159 @@
<?php
namespace Box\Spout\Reader\Common\Entity;
use Box\Spout\Common\Helper\CellTypeHelper;
/**
* Class Cell
*/
class Cell
{
/**
* Numeric cell type (whole numbers, fractional numbers, dates)
*/
const TYPE_NUMERIC = 0;
/**
* String (text) cell type
*/
const TYPE_STRING = 1;
/**
* Formula cell type
* Not used at the moment
*/
const TYPE_FORMULA = 2;
/**
* Empty cell type
*/
const TYPE_EMPTY = 3;
/**
* Boolean cell type
*/
const TYPE_BOOLEAN = 4;
/**
* Error cell type
*/
const TYPE_ERROR = 5;
/**
* The value of this cell
* @var mixed|null
*/
protected $value;
/**
* The cell type
* @var int|null
*/
protected $type;
/**
* @param $value mixed
*/
public function __construct($value)
{
$this->setValue($value);
}
/**
* @param mixed|null $value
*/
public function setValue($value)
{
$this->value = $value;
$this->type = $this->detectType($value);
}
/**
* @return mixed|null
*/
public function getValue()
{
return $this->value;
}
/**
* @return int|null
*/
public function getType()
{
return $this->type;
}
/**
* Get the current value type
*
* @param mixed|null $value
* @return int
*/
protected function detectType($value)
{
if (CellTypeHelper::isBoolean($value)) {
return self::TYPE_BOOLEAN;
}
if (CellTypeHelper::isEmpty($value)) {
return self::TYPE_EMPTY;
}
if (CellTypeHelper::isNumeric($this->getValue())) {
return self::TYPE_NUMERIC;
}
if (CellTypeHelper::isNonEmptyString($value)) {
return self::TYPE_STRING;
}
return self::TYPE_ERROR;
}
/**
* @return bool
*/
public function isBoolean()
{
return $this->type === self::TYPE_BOOLEAN;
}
/**
* @return bool
*/
public function isEmpty()
{
return $this->type === self::TYPE_EMPTY;
}
/**
* @return bool
*/
public function isNumeric()
{
return $this->type === self::TYPE_NUMERIC;
}
/**
* @return bool
*/
public function isString()
{
return $this->type === self::TYPE_STRING;
}
/**
* @return bool
*/
public function isError()
{
return $this->type === self::TYPE_ERROR;
}
/**
* @return string
*/
public function __toString()
{
return (string) $this->value;
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace Box\Spout\Reader\Common\Entity;
class Row
{
/**
* The cells in this row
* @var Cell[]
*/
protected $cells = [];
/**
* Row constructor.
* @param Cell[] $cells
*/
public function __construct(array $cells)
{
$this->setCells($cells);
}
/**
* @return Cell[] $cells
*/
public function getCells()
{
return $this->cells;
}
/**
* @param Cell[] $cells
* @return $this
*/
public function setCells(array $cells)
{
$this->cells = [];
foreach ($cells as $cell) {
$this->addCell($cell);
}
return $this;
}
/**
* @param Cell $cell
* @return Row
*/
public function addCell(Cell $cell)
{
$this->cells[] = $cell;
return $this;
}
/**
* @return array The row values, as array
*/
public function toArray()
{
return array_map(function (Cell $cell) {
return $cell->getValue();
}, $this->cells);
}
}

View File

@ -23,7 +23,7 @@ class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory
}
/**
* @param EntityFactory $entityFactory
* @param InternalEntityFactory $entityFactory
* @return SettingsHelper
*/
public function createSettingsHelper($entityFactory)

View File

@ -2,7 +2,7 @@
namespace Box\Spout\Reader\ODS\Creator;
use Box\Spout\Reader\Common\Creator\EntityFactoryInterface;
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface;
use Box\Spout\Reader\Common\Entity\Options;
use Box\Spout\Reader\Common\XMLProcessor;
use Box\Spout\Reader\ODS\RowIterator;
@ -14,7 +14,7 @@ use Box\Spout\Reader\Wrapper\XMLReader;
* Class EntityFactory
* Factory to create entities
*/
class EntityFactory implements EntityFactoryInterface
class InternalEntityFactory implements InternalEntityFactoryInterface
{
/** @var HelperFactory */
private $helperFactory;

View File

@ -3,7 +3,7 @@
namespace Box\Spout\Reader\ODS\Helper;
use Box\Spout\Reader\Exception\XMLProcessingException;
use Box\Spout\Reader\ODS\Creator\EntityFactory;
use Box\Spout\Reader\ODS\Creator\InternalEntityFactory;
/**
* Class SettingsHelper
@ -18,11 +18,11 @@ class SettingsHelper
const XML_ATTRIBUTE_CONFIG_NAME = 'config:name';
const XML_ATTRIBUTE_VALUE_ACTIVE_TABLE = 'ActiveTable';
/** @var EntityFactory Factory to create entities */
/** @var InternalEntityFactory Factory to create entities */
private $entityFactory;
/**
* @param EntityFactory $entityFactory Factory to create entities
* @param InternalEntityFactory $entityFactory Factory to create entities
*/
public function __construct($entityFactory)
{

View File

@ -3,7 +3,7 @@
namespace Box\Spout\Reader\ODS;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Reader\ODS\Creator\EntityFactory;
use Box\Spout\Reader\ODS\Creator\InternalEntityFactory;
use Box\Spout\Reader\ReaderAbstract;
/**
@ -38,13 +38,13 @@ class Reader extends ReaderAbstract
*/
protected function openReader($filePath)
{
/** @var EntityFactory $entityFactory */
/** @var InternalEntityFactory $entityFactory */
$entityFactory = $this->entityFactory;
$this->zip = $entityFactory->createZipArchive();
if ($this->zip->open($filePath) === true) {
/** @var EntityFactory $entityFactory */
/** @var InternalEntityFactory $entityFactory */
$entityFactory = $this->entityFactory;
$this->sheetIterator = $entityFactory->createSheetIterator($filePath, $this->optionsManager);
} else {

View File

@ -5,7 +5,7 @@ namespace Box\Spout\Reader\ODS;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Reader\Exception\XMLProcessingException;
use Box\Spout\Reader\IteratorInterface;
use Box\Spout\Reader\ODS\Creator\EntityFactory;
use Box\Spout\Reader\ODS\Creator\InternalEntityFactory;
use Box\Spout\Reader\ODS\Helper\SettingsHelper;
use Box\Spout\Reader\Wrapper\XMLReader;
@ -34,7 +34,7 @@ class SheetIterator implements IteratorInterface
/** @var \Box\Spout\Common\Manager\OptionsManagerInterface Reader's options manager */
protected $optionsManager;
/** @var EntityFactory $entityFactory Factory to create entities */
/** @var InternalEntityFactory $entityFactory Factory to create entities */
protected $entityFactory;
/** @var XMLReader The XMLReader object that will help read sheet's XML data */
@ -60,7 +60,7 @@ class SheetIterator implements IteratorInterface
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager
* @param \Box\Spout\Common\Helper\Escaper\ODS $escaper Used to unescape XML data
* @param SettingsHelper $settingsHelper Helper to get data from "settings.xml"
* @param EntityFactory $entityFactory Factory to create entities
* @param InternalEntityFactory $entityFactory Factory to create entities
*/
public function __construct($filePath, $optionsManager, $escaper, $settingsHelper, $entityFactory)
{

View File

@ -5,7 +5,7 @@ namespace Box\Spout\Reader;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Reader\Common\Creator\EntityFactoryInterface;
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface;
use Box\Spout\Reader\Common\Entity\Options;
use Box\Spout\Reader\Exception\ReaderNotOpenedException;
@ -19,7 +19,7 @@ abstract class ReaderAbstract implements ReaderInterface
/** @var bool Indicates whether the stream is currently open */
protected $isStreamOpened = false;
/** @var EntityFactoryInterface Factory to create entities */
/** @var InternalEntityFactoryInterface Factory to create entities */
protected $entityFactory;
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */
@ -60,12 +60,12 @@ abstract class ReaderAbstract implements ReaderInterface
/**
* @param OptionsManagerInterface $optionsManager
* @param GlobalFunctionsHelper $globalFunctionsHelper
* @param EntityFactoryInterface $entityFactory
* @param InternalEntityFactoryInterface $entityFactory
*/
public function __construct(
OptionsManagerInterface $optionsManager,
GlobalFunctionsHelper $globalFunctionsHelper,
EntityFactoryInterface $entityFactory
InternalEntityFactoryInterface $entityFactory
) {
$this->optionsManager = $optionsManager;
$this->globalFunctionsHelper = $globalFunctionsHelper;

View File

@ -39,7 +39,7 @@ class ReaderFactory
{
$optionsManager = new CSV\Manager\OptionsManager();
$helperFactory = new HelperFactory();
$entityFactory = new CSV\Creator\EntityFactory($helperFactory);
$entityFactory = new CSV\Creator\InternalEntityFactory($helperFactory);
$globalFunctionsHelper = $helperFactory->createGlobalFunctionsHelper();
return new CSV\Reader($optionsManager, $globalFunctionsHelper, $entityFactory);
@ -53,7 +53,7 @@ class ReaderFactory
$optionsManager = new XLSX\Manager\OptionsManager();
$helperFactory = new XLSX\Creator\HelperFactory();
$managerFactory = new XLSX\Creator\ManagerFactory($helperFactory, new CachingStrategyFactory());
$entityFactory = new XLSX\Creator\EntityFactory($managerFactory, $helperFactory);
$entityFactory = new XLSX\Creator\InternalEntityFactory($managerFactory, $helperFactory);
$globalFunctionsHelper = $helperFactory->createGlobalFunctionsHelper();
return new XLSX\Reader($optionsManager, $globalFunctionsHelper, $entityFactory, $managerFactory);
@ -66,7 +66,7 @@ class ReaderFactory
{
$optionsManager = new ODS\Manager\OptionsManager();
$helperFactory = new ODS\Creator\HelperFactory();
$entityFactory = new ODS\Creator\EntityFactory($helperFactory);
$entityFactory = new ODS\Creator\InternalEntityFactory($helperFactory);
$globalFunctionsHelper = $helperFactory->createGlobalFunctionsHelper();
return new ODS\Reader($optionsManager, $globalFunctionsHelper, $entityFactory);

View File

@ -2,7 +2,7 @@
namespace Box\Spout\Reader\XLSX\Creator;
use Box\Spout\Reader\Common\Creator\EntityFactoryInterface;
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface;
use Box\Spout\Reader\Common\Entity\Options;
use Box\Spout\Reader\Common\XMLProcessor;
use Box\Spout\Reader\Wrapper\XMLReader;
@ -10,13 +10,12 @@ use Box\Spout\Reader\XLSX\Manager\SharedStringsManager;
use Box\Spout\Reader\XLSX\RowIterator;
use Box\Spout\Reader\XLSX\Sheet;
use Box\Spout\Reader\XLSX\SheetIterator;
use MongoDB\Driver\Manager;
/**
* Class EntityFactory
* Factory to create entities
*/
class EntityFactory implements EntityFactoryInterface
class InternalEntityFactory implements InternalEntityFactoryInterface
{
/** @var HelperFactory */
private $helperFactory;

View File

@ -36,7 +36,7 @@ class ManagerFactory
/**
* @param string $filePath Path of the XLSX file being read
* @param string $tempFolder Temporary folder where the temporary files to store shared strings will be stored
* @param EntityFactory $entityFactory Factory to create entities
* @param InternalEntityFactory $entityFactory Factory to create entities
* @return SharedStringsManager
*/
public function createSharedStringsManager($filePath, $tempFolder, $entityFactory)
@ -55,7 +55,7 @@ class ManagerFactory
/**
* @param string $filePath Path of the XLSX file being read
* @param EntityFactory $entityFactory Factory to create entities
* @param InternalEntityFactory $entityFactory Factory to create entities
* @return WorkbookRelationshipsManager
*/
private function createWorkbookRelationshipsManager($filePath, $entityFactory)
@ -71,7 +71,7 @@ class ManagerFactory
* @param string $filePath Path of the XLSX file being read
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
* @param \Box\Spout\Reader\XLSX\Manager\SharedStringsManager $sharedStringsManager Manages shared strings
* @param EntityFactory $entityFactory Factory to create entities
* @param InternalEntityFactory $entityFactory Factory to create entities
* @return SheetManager
*/
public function createSheetManager($filePath, $optionsManager, $sharedStringsManager, $entityFactory)
@ -83,7 +83,7 @@ class ManagerFactory
/**
* @param string $filePath Path of the XLSX file being read
* @param EntityFactory $entityFactory Factory to create entities
* @param InternalEntityFactory $entityFactory Factory to create entities
* @return StyleManager
*/
public function createStyleManager($filePath, $entityFactory)

View File

@ -5,8 +5,8 @@ namespace Box\Spout\Reader\XLSX\Manager;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Reader\Exception\XMLProcessingException;
use Box\Spout\Reader\Wrapper\XMLReader;
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
use Box\Spout\Reader\XLSX\Creator\HelperFactory;
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory;
use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyInterface;
use Box\Spout\Writer\Common\Entity\Workbook;
@ -41,7 +41,7 @@ class SharedStringsManager
/** @var WorkbookRelationshipsManager Helps retrieving workbook relationships */
protected $workbookRelationshipsManager;
/** @var EntityFactory Factory to create entities */
/** @var InternalEntityFactory Factory to create entities */
protected $entityFactory;
/** @var HelperFactory $helperFactory Factory to create helpers */
@ -57,7 +57,7 @@ class SharedStringsManager
* @param string $filePath Path of the XLSX file being read
* @param string $tempFolder Temporary folder where the temporary files to store shared strings will be stored
* @param WorkbookRelationshipsManager $workbookRelationshipsManager Helps retrieving workbook relationships
* @param EntityFactory $entityFactory Factory to create entities
* @param InternalEntityFactory $entityFactory Factory to create entities
* @param HelperFactory $helperFactory Factory to create helpers
* @param CachingStrategyFactory $cachingStrategyFactory Factory to create shared strings caching strategies
*/

View File

@ -4,7 +4,7 @@ namespace Box\Spout\Reader\XLSX\Manager;
use Box\Spout\Reader\Common\Entity\Options;
use Box\Spout\Reader\Common\XMLProcessor;
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
use Box\Spout\Reader\XLSX\Sheet;
/**
@ -48,7 +48,7 @@ class SheetManager
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */
protected $globalFunctionsHelper;
/** @var EntityFactory Factory to create entities */
/** @var InternalEntityFactory Factory to create entities */
protected $entityFactory;
/** @var \Box\Spout\Common\Helper\Escaper\XLSX Used to unescape XML data */
@ -68,7 +68,7 @@ class SheetManager
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
* @param \Box\Spout\Reader\XLSX\Manager\SharedStringsManager $sharedStringsManager Manages shared strings
* @param \Box\Spout\Common\Helper\Escaper\XLSX $escaper Used to unescape XML data
* @param EntityFactory $entityFactory Factory to create entities
* @param InternalEntityFactory $entityFactory Factory to create entities
* @param mixed $sharedStringsManager
*/
public function __construct($filePath, $optionsManager, $sharedStringsManager, $escaper, $entityFactory)

View File

@ -2,7 +2,7 @@
namespace Box\Spout\Reader\XLSX\Manager;
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
/**
* Class StyleManager
@ -51,7 +51,7 @@ class StyleManager
/** @var string Path of the styles XML file */
protected $stylesXMLFilePath;
/** @var EntityFactory Factory to create entities */
/** @var InternalEntityFactory Factory to create entities */
protected $entityFactory;
/** @var array Array containing the IDs of built-in number formats indicating a date */
@ -69,7 +69,7 @@ class StyleManager
/**
* @param string $filePath Path of the XLSX file being read
* @param WorkbookRelationshipsManager $workbookRelationshipsManager Helps retrieving workbook relationships
* @param EntityFactory $entityFactory Factory to create entities
* @param InternalEntityFactory $entityFactory Factory to create entities
*/
public function __construct($filePath, $workbookRelationshipsManager, $entityFactory)
{

View File

@ -4,7 +4,7 @@ namespace Box\Spout\Reader\XLSX\Manager;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Reader\Wrapper\XMLReader;
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
/**
* Class WorkbookRelationshipsManager
@ -30,7 +30,7 @@ class WorkbookRelationshipsManager
/** @var string Path of the XLSX file being read */
private $filePath;
/** @var EntityFactory Factory to create entities */
/** @var InternalEntityFactory Factory to create entities */
private $entityFactory;
/** @var array Cache of the already read workbook relationships: [TYPE] => [FILE_NAME] */
@ -38,7 +38,7 @@ class WorkbookRelationshipsManager
/**
* @param string $filePath Path of the XLSX file being read
* @param EntityFactory $entityFactory Factory to create entities
* @param InternalEntityFactory $entityFactory Factory to create entities
*/
public function __construct($filePath, $entityFactory)
{

View File

@ -5,10 +5,10 @@ namespace Box\Spout\Reader\XLSX;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Reader\Common\Creator\EntityFactoryInterface;
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface;
use Box\Spout\Reader\Common\Entity\Options;
use Box\Spout\Reader\ReaderAbstract;
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
use Box\Spout\Reader\XLSX\Creator\ManagerFactory;
/**
@ -32,13 +32,13 @@ class Reader extends ReaderAbstract
/**
* @param OptionsManagerInterface $optionsManager
* @param GlobalFunctionsHelper $globalFunctionsHelper
* @param EntityFactoryInterface $entityFactory
* @param InternalEntityFactoryInterface $entityFactory
* @param ManagerFactory $managerFactory
*/
public function __construct(
OptionsManagerInterface $optionsManager,
GlobalFunctionsHelper $globalFunctionsHelper,
EntityFactoryInterface $entityFactory,
InternalEntityFactoryInterface $entityFactory,
ManagerFactory $managerFactory
) {
parent::__construct($optionsManager, $globalFunctionsHelper, $entityFactory);
@ -78,7 +78,7 @@ class Reader extends ReaderAbstract
*/
protected function openReader($filePath)
{
/** @var EntityFactory $entityFactory */
/** @var InternalEntityFactory $entityFactory */
$entityFactory = $this->entityFactory;
$this->zip = $entityFactory->createZipArchive();

View File

@ -14,7 +14,7 @@ use Box\Spout\Writer\WriterInterface;
class EntityFactory
{
/**
* This creates an instance of the appropriate writer, given the type of the file to be read
* This creates an instance of the appropriate writer, given the type of the file to be written
*
* @param string $writerType Type of the writer to instantiate
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException

View File

@ -2,8 +2,8 @@
namespace Box\Spout\Writer\Common\Entity;
use Box\Spout\Common\Helper\CellTypeHelper;
use Box\Spout\Writer\Common\Entity\Style\Style;
use Box\Spout\Writer\Common\Helper\CellHelper;
/**
* Class Cell
@ -118,16 +118,16 @@ class Cell
*/
protected function detectType($value)
{
if (CellHelper::isBoolean($value)) {
if (CellTypeHelper::isBoolean($value)) {
return self::TYPE_BOOLEAN;
}
if (CellHelper::isEmpty($value)) {
if (CellTypeHelper::isEmpty($value)) {
return self::TYPE_EMPTY;
}
if (CellHelper::isNumeric($this->getValue())) {
if (CellTypeHelper::isNumeric($this->getValue())) {
return self::TYPE_NUMERIC;
}
if (CellHelper::isNonEmptyString($value)) {
if (CellTypeHelper::isNonEmptyString($value)) {
return self::TYPE_STRING;
}

View File

@ -42,48 +42,4 @@ class CellHelper
return self::$columnIndexToCellIndexCache[$originalColumnIndex];
}
/**
* @param $value
* @return bool Whether the given value is considered "empty"
*/
public static function isEmpty($value)
{
return ($value === null || $value === '');
}
/**
* @param $value
* @return bool Whether the given value is a non empty string
*/
public static function isNonEmptyString($value)
{
return (gettype($value) === 'string' && $value !== '');
}
/**
* Returns whether the given value is numeric.
* A numeric value is from type "integer" or "double" ("float" is not returned by gettype).
*
* @param $value
* @return bool Whether the given value is numeric
*/
public static function isNumeric($value)
{
$valueType = gettype($value);
return ($valueType === 'integer' || $valueType === 'double');
}
/**
* Returns whether the given value is boolean.
* "true"/"false" and 0/1 are not booleans.
*
* @param $value
* @return bool Whether the given value is boolean
*/
public static function isBoolean($value)
{
return gettype($value) === 'boolean';
}
}

View File

@ -0,0 +1,84 @@
<?php
namespace Box\Spout\Common\Helper;
/**
* Class CellTypeHelperTest
*/
class CellTypeHelperTest extends \PHPUnit_Framework_TestCase
{
/**
* @return array
*/
public function testIsEmpty()
{
$this->assertTrue(CellTypeHelper::isEmpty(null));
$this->assertTrue(CellTypeHelper::isEmpty(''));
$this->assertFalse(CellTypeHelper::isEmpty('string'));
$this->assertFalse(CellTypeHelper::isEmpty(0));
$this->assertFalse(CellTypeHelper::isEmpty(1));
$this->assertFalse(CellTypeHelper::isEmpty(true));
$this->assertFalse(CellTypeHelper::isEmpty(false));
$this->assertFalse(CellTypeHelper::isEmpty(['string']));
$this->assertFalse(CellTypeHelper::isEmpty(new \stdClass()));
}
/**
* @return array
*/
public function testIsNonEmptyString()
{
$this->assertTrue(CellTypeHelper::isNonEmptyString('string'));
$this->assertFalse(CellTypeHelper::isNonEmptyString(''));
$this->assertFalse(CellTypeHelper::isNonEmptyString(0));
$this->assertFalse(CellTypeHelper::isNonEmptyString(1));
$this->assertFalse(CellTypeHelper::isNonEmptyString(true));
$this->assertFalse(CellTypeHelper::isNonEmptyString(false));
$this->assertFalse(CellTypeHelper::isNonEmptyString(['string']));
$this->assertFalse(CellTypeHelper::isNonEmptyString(new \stdClass()));
$this->assertFalse(CellTypeHelper::isNonEmptyString(null));
}
/**
* @return array
*/
public function testIsNumeric()
{
$this->assertTrue(CellTypeHelper::isNumeric(0));
$this->assertTrue(CellTypeHelper::isNumeric(10));
$this->assertTrue(CellTypeHelper::isNumeric(10.1));
$this->assertTrue(CellTypeHelper::isNumeric(10.10000000000000000000001));
$this->assertTrue(CellTypeHelper::isNumeric(0x539));
$this->assertTrue(CellTypeHelper::isNumeric(02471));
$this->assertTrue(CellTypeHelper::isNumeric(0b10100111001));
$this->assertTrue(CellTypeHelper::isNumeric(1337e0));
$this->assertFalse(CellTypeHelper::isNumeric('0'));
$this->assertFalse(CellTypeHelper::isNumeric('42'));
$this->assertFalse(CellTypeHelper::isNumeric(true));
$this->assertFalse(CellTypeHelper::isNumeric([2]));
$this->assertFalse(CellTypeHelper::isNumeric(new \stdClass()));
$this->assertFalse(CellTypeHelper::isNumeric(null));
}
/**
* @return array
*/
public function testIsBoolean()
{
$this->assertTrue(CellTypeHelper::isBoolean(true));
$this->assertTrue(CellTypeHelper::isBoolean(false));
$this->assertFalse(CellTypeHelper::isBoolean(0));
$this->assertFalse(CellTypeHelper::isBoolean(1));
$this->assertFalse(CellTypeHelper::isBoolean('0'));
$this->assertFalse(CellTypeHelper::isBoolean('1'));
$this->assertFalse(CellTypeHelper::isBoolean('true'));
$this->assertFalse(CellTypeHelper::isBoolean('false'));
$this->assertFalse(CellTypeHelper::isBoolean([true]));
$this->assertFalse(CellTypeHelper::isBoolean(new \stdClass()));
$this->assertFalse(CellTypeHelper::isBoolean(null));
}
}

View File

@ -6,7 +6,7 @@ use Box\Spout\Common\Creator\HelperFactory;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Helper\EncodingHelper;
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
use Box\Spout\Reader\CSV\Creator\EntityFactory;
use Box\Spout\Reader\CSV\Creator\InternalEntityFactory;
use Box\Spout\Reader\CSV\Manager\OptionsManager;
use Box\Spout\Reader\Exception\ReaderNotOpenedException;
use Box\Spout\Reader\ReaderInterface;
@ -320,7 +320,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
foreach ($reader->getSheetIterator() as $sheet) {
foreach ($sheet->getRowIterator() as $row) {
$allRows[] = $row;
$allRows[] = $row->toArray();
}
}
@ -351,19 +351,19 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
foreach ($reader->getSheetIterator() as $sheet) {
foreach ($sheet->getRowIterator() as $row) {
$allRows[] = $row;
$allRows[] = $row->toArray();
break;
}
foreach ($sheet->getRowIterator() as $row) {
$allRows[] = $row;
$allRows[] = $row->toArray();
break;
}
}
foreach ($reader->getSheetIterator() as $sheet) {
foreach ($sheet->getRowIterator() as $row) {
$allRows[] = $row;
$allRows[] = $row->toArray();
break;
}
}
@ -444,7 +444,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
foreach ($reader->getSheetIterator() as $sheet) {
foreach ($sheet->getRowIterator() as $row) {
$allRows[] = $row;
$allRows[] = $row->toArray();
}
}
@ -482,7 +482,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
{
$optionsManager = $optionsManager ?: new OptionsManager();
$globalFunctionsHelper = $globalFunctionsHelper ?: new GlobalFunctionsHelper();
$entityFactory = new EntityFactory(new HelperFactory());
$entityFactory = new InternalEntityFactory(new HelperFactory());
return new Reader($optionsManager, $globalFunctionsHelper, $entityFactory);
}
@ -516,7 +516,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
foreach ($reader->getSheetIterator() as $sheetIndex => $sheet) {
foreach ($sheet->getRowIterator() as $rowIndex => $row) {
$allRows[] = $row;
$allRows[] = $row->toArray();
}
}

View File

@ -3,7 +3,7 @@
namespace Box\Spout\Reader\CSV;
use Box\Spout\Common\Type;
use Box\Spout\Reader\ReaderFactory;
use Box\Spout\Reader\Common\Creator\EntityFactory;
use Box\Spout\TestUsingResource;
/**
@ -32,7 +32,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
private function openFileAndReturnSheet($fileName)
{
$resourcePath = $this->getResourcePath($fileName);
$reader = ReaderFactory::create(Type::CSV);
$reader = EntityFactory::createReader(Type::CSV);
$reader->open($resourcePath);
$sheet = $reader->getSheetIterator()->current();

View File

@ -0,0 +1,64 @@
<?php
namespace Box\Spout\Reader\Common\Entity;
class CellTest extends \PHPUnit\Framework\TestCase
{
/**
* @return void
*/
public function testValidInstance()
{
$this->assertInstanceOf(Cell::class, new Cell('cell'));
}
/**
* @return void
*/
public function testCellTypeNumeric()
{
$this->assertTrue((new Cell(0))->isNumeric());
$this->assertTrue((new Cell(1))->isNumeric());
}
/**
* @return void
*/
public function testCellTypeString()
{
$this->assertTrue((new Cell('String!'))->isString());
}
/**
* @return void
*/
public function testCellTypeEmptyString()
{
$this->assertTrue((new Cell(''))->isEmpty());
}
/**
* @return void
*/
public function testCellTypeEmptyNull()
{
$this->assertTrue((new Cell(null))->isEmpty());
}
/**
* @return void
*/
public function testCellTypeBool()
{
$this->assertTrue((new Cell(true))->isBoolean());
$this->assertTrue((new Cell(false))->isBoolean());
}
/**
* @return void
*/
public function testCellTypeError()
{
$this->assertTrue((new Cell([]))->isError());
}
}

View File

@ -0,0 +1,90 @@
<?php
namespace Box\Spout\Reader\Common\Entity;
class RowTest extends \PHPUnit\Framework\TestCase
{
/**
* @return \PHPUnit_Framework_MockObject_MockObject|Cell
*/
private function getCellMock()
{
return $this->createMock(Cell::class);
}
/**
* @return void
*/
public function testValidInstance()
{
$this->assertInstanceOf(Row::class, new Row([], null));
}
/**
* @return void
*/
public function testSetCells()
{
$row = new Row([], null);
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
$this->assertEquals(2, count($row->getCells()));
}
/**
* @return void
*/
public function testSetCellsResets()
{
$row = new Row([], null);
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
$this->assertEquals(2, count($row->getCells()));
$row->setCells([$this->getCellMock()]);
$this->assertEquals(1, count($row->getCells()));
}
/**
* @return void
*/
public function testGetCells()
{
$row = new Row([], null);
$this->assertEquals(0, count($row->getCells()));
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
$this->assertEquals(2, count($row->getCells()));
}
/**
* @return void
*/
public function testAddCell()
{
$row = new Row([], null);
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
$this->assertEquals(2, count($row->getCells()));
$row->addCell($this->getCellMock());
$this->assertEquals(3, count($row->getCells()));
}
/**
* @return void
*/
public function testFluentInterface()
{
$row = new Row([], null);
$row
->addCell($this->getCellMock())
->setCells([]);
$this->assertTrue(is_object($row));
}
}

View File

@ -4,8 +4,8 @@ namespace Box\Spout\Reader\ODS;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Type;
use Box\Spout\Reader\Common\Creator\EntityFactory;
use Box\Spout\Reader\Exception\IteratorNotRewindableException;
use Box\Spout\Reader\ReaderFactory;
use Box\Spout\TestUsingResource;
/**
@ -353,7 +353,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
$this->expectException(IteratorNotRewindableException::class);
$resourcePath = $this->getResourcePath('one_sheet_with_strings.ods');
$reader = ReaderFactory::create(Type::ODS);
$reader = EntityFactory::createReader(Type::ODS);
$reader->open($resourcePath);
foreach ($reader->getSheetIterator() as $sheet) {
@ -377,7 +377,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
$allRows = [];
$resourcePath = $this->getResourcePath('two_sheets_with_strings.ods');
$reader = ReaderFactory::create(Type::ODS);
$reader = EntityFactory::createReader(Type::ODS);
$reader->open($resourcePath);
foreach ($reader->getSheetIterator() as $sheet) {
@ -421,7 +421,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
$this->expectException(IOException::class);
/** @var \Box\Spout\Reader\ODS\Reader $reader */
$reader = ReaderFactory::create(Type::ODS);
$reader = EntityFactory::createReader(Type::ODS);
$reader->open('unsupported://foobar');
}
@ -433,7 +433,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
$this->expectException(IOException::class);
/** @var \Box\Spout\Reader\ODS\Reader $reader */
$reader = ReaderFactory::create(Type::ODS);
$reader = EntityFactory::createReader(Type::ODS);
$reader->open('php://memory');
}
@ -529,7 +529,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
$resourcePath = $this->getResourcePath($fileName);
/** @var \Box\Spout\Reader\ODS\Reader $reader */
$reader = ReaderFactory::create(Type::ODS);
$reader = EntityFactory::createReader(Type::ODS);
$reader->setShouldFormatDates($shouldFormatDates);
$reader->setShouldPreserveEmptyRows($shouldPreserveEmptyRows);
$reader->open($resourcePath);

View File

@ -3,7 +3,7 @@
namespace Box\Spout\Reader\ODS;
use Box\Spout\Common\Type;
use Box\Spout\Reader\ReaderFactory;
use Box\Spout\Reader\Common\Creator\EntityFactory;
use Box\Spout\TestUsingResource;
/**
@ -60,7 +60,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
private function openFileAndReturnSheets($fileName)
{
$resourcePath = $this->getResourcePath($fileName);
$reader = ReaderFactory::create(Type::ODS);
$reader = EntityFactory::createReader(Type::ODS);
$reader->open($resourcePath);
$sheets = [];

View File

@ -3,8 +3,8 @@
namespace Box\Spout\Reader\XLSX\Manager;
use Box\Spout\Reader\Exception\SharedStringNotFoundException;
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
use Box\Spout\Reader\XLSX\Creator\HelperFactory;
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
use Box\Spout\Reader\XLSX\Creator\ManagerFactory;
use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory;
use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\FileBasedStrategy;
@ -50,7 +50,7 @@ class SharedStringsManagerTest extends \PHPUnit_Framework_TestCase
$cachingStrategyFactory = new CachingStrategyFactory();
$helperFactory = new HelperFactory();
$managerFactory = new ManagerFactory($helperFactory, $cachingStrategyFactory);
$entityFactory = new EntityFactory($managerFactory, $helperFactory);
$entityFactory = new InternalEntityFactory($managerFactory, $helperFactory);
$workbookRelationshipsManager = new WorkbookRelationshipsManager($resourcePath, $entityFactory);
$this->sharedStringsManager = new SharedStringsManager(

View File

@ -2,7 +2,7 @@
namespace Box\Spout\Reader\XLSX\Manager;
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
/**
* Class StyleManagerTest
@ -16,7 +16,7 @@ class StyleManagerTest extends \PHPUnit_Framework_TestCase
*/
private function getStyleManagerMock($styleAttributes = [], $customNumberFormats = [])
{
$entityFactory = $this->createMock(EntityFactory::class);
$entityFactory = $this->createMock(InternalEntityFactory::class);
$workbookRelationshipsManager = $this->createMock(WorkbookRelationshipsManager::class);
/** @var StyleManager $styleManager */

View File

@ -4,7 +4,7 @@ namespace Box\Spout\Reader\XLSX;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Type;
use Box\Spout\Reader\ReaderFactory;
use Box\Spout\Reader\Common\Creator\EntityFactory;
use Box\Spout\TestUsingResource;
/**
@ -570,7 +570,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
$allRows = [];
$resourcePath = $this->getResourcePath('two_sheets_with_inline_strings.xlsx');
$reader = ReaderFactory::create(Type::XLSX);
$reader = EntityFactory::createReader(Type::XLSX);
$reader->open($resourcePath);
foreach ($reader->getSheetIterator() as $sheet) {
@ -624,7 +624,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
$this->expectException(IOException::class);
/** @var \Box\Spout\Reader\XLSX\Reader $reader */
$reader = ReaderFactory::create(Type::XLSX);
$reader = EntityFactory::createReader(Type::XLSX);
$reader->open('unsupported://foobar');
}
@ -636,7 +636,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
$this->expectException(IOException::class);
/** @var \Box\Spout\Reader\XLSX\Reader $reader */
$reader = ReaderFactory::create(Type::XLSX);
$reader = EntityFactory::createReader(Type::XLSX);
$reader->open('php://memory');
}
@ -701,7 +701,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
$resourcePath = $this->getResourcePath($fileName);
/** @var \Box\Spout\Reader\XLSX\Reader $reader */
$reader = ReaderFactory::create(Type::XLSX);
$reader = EntityFactory::createReader(Type::XLSX);
$reader->setShouldFormatDates($shouldFormatDates);
$reader->setShouldPreserveEmptyRows($shouldPreserveEmptyRows);
$reader->open($resourcePath);

View File

@ -3,7 +3,7 @@
namespace Box\Spout\Reader\XLSX;
use Box\Spout\Common\Type;
use Box\Spout\Reader\ReaderFactory;
use Box\Spout\Reader\Common\Creator\EntityFactory;
use Box\Spout\TestUsingResource;
/**
@ -48,7 +48,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
private function openFileAndReturnSheets($fileName)
{
$resourcePath = $this->getResourcePath($fileName);
$reader = ReaderFactory::create(Type::XLSX);
$reader = EntityFactory::createReader(Type::XLSX);
$reader->open($resourcePath);
$sheets = [];

View File

@ -32,79 +32,4 @@ class CellHelperTest extends \PHPUnit_Framework_TestCase
{
$this->assertEquals($expectedCellIndex, CellHelper::getCellIndexFromColumnIndex($columnIndex));
}
/**
* @return array
*/
public function testIsEmpty()
{
$this->assertTrue(CellHelper::isEmpty(null));
$this->assertTrue(CellHelper::isEmpty(''));
$this->assertFalse(CellHelper::isEmpty('string'));
$this->assertFalse(CellHelper::isEmpty(0));
$this->assertFalse(CellHelper::isEmpty(1));
$this->assertFalse(CellHelper::isEmpty(true));
$this->assertFalse(CellHelper::isEmpty(false));
$this->assertFalse(CellHelper::isEmpty(['string']));
$this->assertFalse(CellHelper::isEmpty(new \stdClass()));
}
/**
* @return array
*/
public function testIsNonEmptyString()
{
$this->assertTrue(CellHelper::isNonEmptyString('string'));
$this->assertFalse(CellHelper::isNonEmptyString(''));
$this->assertFalse(CellHelper::isNonEmptyString(0));
$this->assertFalse(CellHelper::isNonEmptyString(1));
$this->assertFalse(CellHelper::isNonEmptyString(true));
$this->assertFalse(CellHelper::isNonEmptyString(false));
$this->assertFalse(CellHelper::isNonEmptyString(['string']));
$this->assertFalse(CellHelper::isNonEmptyString(new \stdClass()));
$this->assertFalse(CellHelper::isNonEmptyString(null));
}
/**
* @return array
*/
public function testIsNumeric()
{
$this->assertTrue(CellHelper::isNumeric(0));
$this->assertTrue(CellHelper::isNumeric(10));
$this->assertTrue(CellHelper::isNumeric(10.1));
$this->assertTrue(CellHelper::isNumeric(10.10000000000000000000001));
$this->assertTrue(CellHelper::isNumeric(0x539));
$this->assertTrue(CellHelper::isNumeric(02471));
$this->assertTrue(CellHelper::isNumeric(0b10100111001));
$this->assertTrue(CellHelper::isNumeric(1337e0));
$this->assertFalse(CellHelper::isNumeric('0'));
$this->assertFalse(CellHelper::isNumeric('42'));
$this->assertFalse(CellHelper::isNumeric(true));
$this->assertFalse(CellHelper::isNumeric([2]));
$this->assertFalse(CellHelper::isNumeric(new \stdClass()));
$this->assertFalse(CellHelper::isNumeric(null));
}
/**
* @return array
*/
public function testIsBoolean()
{
$this->assertTrue(CellHelper::isBoolean(true));
$this->assertTrue(CellHelper::isBoolean(false));
$this->assertFalse(CellHelper::isBoolean(0));
$this->assertFalse(CellHelper::isBoolean(1));
$this->assertFalse(CellHelper::isBoolean('0'));
$this->assertFalse(CellHelper::isBoolean('1'));
$this->assertFalse(CellHelper::isBoolean('true'));
$this->assertFalse(CellHelper::isBoolean('false'));
$this->assertFalse(CellHelper::isBoolean([true]));
$this->assertFalse(CellHelper::isBoolean(new \stdClass()));
$this->assertFalse(CellHelper::isBoolean(null));
}
}