Skip to content

Commit

Permalink
PHP 7.4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed Nov 29, 2019
1 parent f734783 commit 9fa45f7
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 45 deletions.
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ php:
- 7.3
- 7.4snapshot

matrix:
fast_finish: true
allow_failures:
- php: 7.4snapshot

cache:
directories:
- cache
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com)
and this project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]

### Changed

- PHP 7.4 compatibility

### Added

- ...

### Fixed

- ...

## [1.10.0] - 2019-11-18

### Changed
Expand Down
40 changes: 20 additions & 20 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3459,7 +3459,7 @@ private function _parseFormula($formula, Cell $pCell = null)
$parenthesisDepthMap[$pendingStoreKey] -= 1;
}

if (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/i', $d['value'], $matches)) { // Did this parenthesis just close a function?
if (is_array($d) && preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/i', $d['value'], $matches)) { // Did this parenthesis just close a function?
if (!empty($pendingStoreKey) && $parenthesisDepthMap[$pendingStoreKey] == -1) {
// we are closing an IF(
if ($d['value'] != 'IF(') {
Expand Down
6 changes: 4 additions & 2 deletions src/PhpSpreadsheet/Calculation/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,12 @@ public static function isCellValue($idx)
public static function ifCondition($condition)
{
$condition = self::flattenSingleValue($condition);
if (!isset($condition[0]) && !is_numeric($condition)) {

if ($condition === '') {
$condition = '=""';
}
if (!in_array($condition[0], ['>', '<', '='])) {

if (!is_string($condition) || !in_array($condition[0], ['>', '<', '='])) {
if (!is_numeric($condition)) {
$condition = Calculation::wrapResult(strtoupper($condition));
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Chart/DataSeriesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public function refresh(Worksheet $worksheet, $flatten = true)
if ($flatten) {
$this->dataValues = Functions::flattenArray($newDataValues);
foreach ($this->dataValues as &$dataValue) {
if ((!empty($dataValue)) && ($dataValue[0] == '#')) {
if (is_string($dataValue) && !empty($dataValue) && $dataValue[0] == '#') {
$dataValue = 0.0;
}
}
Expand Down
28 changes: 15 additions & 13 deletions src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,18 +429,20 @@ public function load($pFilename)

$sharedStrings = [];
$xpath = self::getArrayItem($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings']"));
//~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"
$xmlStrings = simplexml_load_string(
$this->securityScanner->scan($this->getFromZipArchive($zip, "$dir/$xpath[Target]")),
'SimpleXMLElement',
Settings::getLibXmlLoaderOptions()
);
if (isset($xmlStrings, $xmlStrings->si)) {
foreach ($xmlStrings->si as $val) {
if (isset($val->t)) {
$sharedStrings[] = StringHelper::controlCharacterOOXML2PHP((string) $val->t);
} elseif (isset($val->r)) {
$sharedStrings[] = $this->parseRichText($val);
if ($xpath) {
//~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"
$xmlStrings = simplexml_load_string(
$this->securityScanner->scan($this->getFromZipArchive($zip, "$dir/$xpath[Target]")),
'SimpleXMLElement',
Settings::getLibXmlLoaderOptions()
);
if (isset($xmlStrings, $xmlStrings->si)) {
foreach ($xmlStrings->si as $val) {
if (isset($val->t)) {
$sharedStrings[] = StringHelper::controlCharacterOOXML2PHP((string) $val->t);
} elseif (isset($val->r)) {
$sharedStrings[] = $this->parseRichText($val);
}
}
}
}
Expand Down Expand Up @@ -1421,7 +1423,7 @@ public function load($pFilename)
}
}

if ((!$this->readDataOnly) || (!empty($this->loadSheetsOnly))) {
if ((!$this->readDataOnly || !empty($this->loadSheetsOnly)) && isset($xmlWorkbook->bookViews->workbookView)) {
$workbookView = $xmlWorkbook->bookViews->workbookView;

// active sheet index
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Writer/Xls/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ private function match($token)
public function parse($formula)
{
$this->currentCharacter = 0;
$this->formula = $formula;
$this->formula = (string) $formula;
$this->lookAhead = $formula[1] ?? '';
$this->advance();
$this->parseTree = $this->condition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected function cellValues(array $cellValues)
protected function cellIsFormula(array $cellValues)
{
foreach ($cellValues as $cellValue) {
yield $cellValue[0] === '=';
yield is_string($cellValue) && $cellValue[0] === '=';
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/PhpSpreadsheetTests/Writer/Xlsx/UnparsedDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function testLoadSaveXlsxWithUnparsedData()
$this->assertContains('<mc:AlternateContent', $resultSheet1Raw, 'AlternateContent at sheet1.xml not found!');
$xmlWorksheet = simplexml_load_string($resultSheet1Raw, 'SimpleXMLElement', Settings::getLibXmlLoaderOptions());
$pageSetupAttributes = $xmlWorksheet->pageSetup->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$this->assertNotEmpty($pageSetupAttributes['id'], 'sheet1.xml/pageSetup[r:id] not found!');
$this->assertTrue(isset($pageSetupAttributes->id), 'sheet1.xml/pageSetup[r:id] not found!');
if (!$xmlWorksheet->sheetProtection) {
$this->fail('sheet1.xml/sheetProtection not found!');
} else {
Expand Down

0 comments on commit 9fa45f7

Please sign in to comment.