diff --git a/.travis.yml b/.travis.yml index 9e90442..d4306c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ install: script: - mkdir -p build/logs - - php vendor/bin/phpunit --coverage-clover build/logs/clover.xml --coverage-text + - php vendor/bin/phpunit --coverage-clover build/logs/clover.xml after_script: - if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != '7.0' ]]; then php vendor/bin/ocular code-coverage:upload --format=php-clover build/logs/clover.xml; fi diff --git a/src/Spout/Common/Helper/GlobalFunctionsHelper.php b/src/Spout/Common/Helper/GlobalFunctionsHelper.php index feeb782..47ed052 100644 --- a/src/Spout/Common/Helper/GlobalFunctionsHelper.php +++ b/src/Spout/Common/Helper/GlobalFunctionsHelper.php @@ -160,7 +160,7 @@ class GlobalFunctionsHelper * @see file_get_contents() * * @param string $filePath - * @return bool + * @return string */ public function file_get_contents($filePath) { diff --git a/src/Spout/Reader/CSV/RowIterator.php b/src/Spout/Reader/CSV/RowIterator.php index 2316fa7..ffb533f 100644 --- a/src/Spout/Reader/CSV/RowIterator.php +++ b/src/Spout/Reader/CSV/RowIterator.php @@ -111,9 +111,9 @@ class RowIterator implements IteratorInterface if (!$this->hasReachedEndOfFile) { do { $lineData = $this->globalFunctionsHelper->fgetcsv($this->filePointer, 0, $this->fieldDelimiter, $this->fieldEnclosure); - } while ($lineData && $this->isEmptyLine($lineData)); + } while ($lineData === false || ($lineData !== null && $this->isEmptyLine($lineData))); - if ($lineData !== null) { + if ($lineData !== false && $lineData !== null) { $this->rowDataBuffer = $lineData; $this->numReadRows++; } @@ -133,7 +133,7 @@ class RowIterator implements IteratorInterface * Return the current element from the buffer * @link http://php.net/manual/en/iterator.current.php * - * @return array + * @return array|null */ public function current() { diff --git a/src/Spout/Reader/XLSX/Helper/SharedStringsCaching/FileBasedStrategy.php b/src/Spout/Reader/XLSX/Helper/SharedStringsCaching/FileBasedStrategy.php index 6670bfe..9f1f19f 100644 --- a/src/Spout/Reader/XLSX/Helper/SharedStringsCaching/FileBasedStrategy.php +++ b/src/Spout/Reader/XLSX/Helper/SharedStringsCaching/FileBasedStrategy.php @@ -26,6 +26,9 @@ class FileBasedStrategy implements CachingStrategyInterface /** @var \Box\Spout\Common\Helper\FileSystemHelper Helper to perform file system operations */ protected $fileSystemHelper; + /** @var string Temporary folder where the temporary files will be created */ + protected $tempFolder; + /** * @var int Maximum number of strings that can be stored in one temp file * @see CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE @@ -42,7 +45,7 @@ class FileBasedStrategy implements CachingStrategyInterface protected $inMemoryTempFilePath; /** - * @var string Contents of the temporary file that was last read + * @var array Contents of the temporary file that was last read * @see CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE */ protected $inMemoryTempFileContents; diff --git a/src/Spout/Reader/XLSX/Helper/SheetHelper.php b/src/Spout/Reader/XLSX/Helper/SheetHelper.php index 3cbe9cb..a3431ae 100644 --- a/src/Spout/Reader/XLSX/Helper/SheetHelper.php +++ b/src/Spout/Reader/XLSX/Helper/SheetHelper.php @@ -72,8 +72,9 @@ class SheetHelper // find all nodes defining a sheet $sheetNodes = $contentTypesAsXMLElement->xpath('//ns:Override[@ContentType="' . self::OVERRIDE_CONTENT_TYPES_ATTRIBUTE . '"]'); + $numSheetNodes = count($sheetNodes); - for ($i = 0; $i < count($sheetNodes); $i++) { + for ($i = 0; $i < $numSheetNodes; $i++) { $sheetNode = $sheetNodes[$i]; $sheetDataXMLFilePath = (string) $sheetNode->attributes()->PartName; @@ -95,7 +96,7 @@ class SheetHelper * * @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml * @param int $sheetIndexZeroBased Index of the sheet, based on order in [Content_Types].xml (zero-based) - * @return \Box\Spout\Reader\Sheet Sheet instance + * @return \Box\Spout\Reader\XLSX\Sheet Sheet instance */ protected function getSheetFromXML($sheetDataXMLFilePath, $sheetIndexZeroBased) { @@ -136,7 +137,7 @@ class SheetHelper * Returns the default name of the sheet whose data is located * at the given path. * - * @param $sheetDataXMLFilePath + * @param string $sheetDataXMLFilePath Path of the sheet data XML file * @return string The default sheet name */ protected function getDefaultSheetName($sheetDataXMLFilePath) diff --git a/src/Spout/Reader/XLSX/Sheet.php b/src/Spout/Reader/XLSX/Sheet.php index e2eebec..9510ecd 100644 --- a/src/Spout/Reader/XLSX/Sheet.php +++ b/src/Spout/Reader/XLSX/Sheet.php @@ -32,7 +32,7 @@ class Sheet implements SheetInterface * @param int $sheetIndex Index of the sheet, based on order of creation (zero-based) * @param string $sheetName Name of the sheet */ - function __construct($filePath, $sheetDataXMLFilePath, $sharedStringsHelper, $sheetId, $sheetIndex, $sheetName) + public function __construct($filePath, $sheetDataXMLFilePath, $sharedStringsHelper, $sheetId, $sheetIndex, $sheetName) { $this->rowIterator = new RowIterator($filePath, $sheetDataXMLFilePath, $sharedStringsHelper); $this->id = $sheetId; diff --git a/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php b/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php index c78364c..8a544f9 100644 --- a/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php +++ b/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php @@ -25,6 +25,9 @@ EOD; */ const DEFAULT_STRINGS_COUNT_PART = 'count="9999999999999" uniqueCount="9999999999999"'; + /** @var resource Pointer to the sharedStrings.xml file */ + protected $sharedStringsFilePointer; + /** @var int Number of shared strings already written */ protected $numSharedStrings = 0; diff --git a/src/Spout/Writer/XLSX/Sheet.php b/src/Spout/Writer/XLSX/Sheet.php index 46380a2..858adcd 100644 --- a/src/Spout/Writer/XLSX/Sheet.php +++ b/src/Spout/Writer/XLSX/Sheet.php @@ -21,7 +21,7 @@ class Sheet /** * @param int $sheetIndex Index of the sheet, based on order of creation (zero-based) */ - function __construct($sheetIndex) + public function __construct($sheetIndex) { $this->index = $sheetIndex; $this->name = self::DEFAULT_SHEET_NAME_PREFIX . ($sheetIndex + 1); diff --git a/tests/Spout/Reader/XLSX/ReaderTest.php b/tests/Spout/Reader/XLSX/ReaderTest.php index 8c8376b..0037ca9 100644 --- a/tests/Spout/Reader/XLSX/ReaderTest.php +++ b/tests/Spout/Reader/XLSX/ReaderTest.php @@ -93,6 +93,9 @@ class ReaderTest extends \PHPUnit_Framework_TestCase */ public function testReadShouldSupportAllCellTypes() { + // make sure dates are always created with the same timezone + date_default_timezone_set('UTC'); + $allRows = $this->getAllRowsForFile('sheet_with_all_cell_types.xlsx'); $expectedRows = [