diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 9794aff..42f2492 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -15,10 +15,13 @@ tools: php_pdepend: true php_loc: enabled: true - excluded_dirs: [vendor, tests] - php_cpd: + filter: + paths: ['src'] + php_cpd: false # Must be disabled to use php_sim instead + php_sim: enabled: true - excluded_dirs: [vendor, tests] + filter: + paths: ['src'] build_failure_conditions: - 'project.metric("scrutinizer.quality", < 9)' # Code Quality Rating drops below 9 diff --git a/src/Spout/Common/Helper/GlobalFunctionsHelper.php b/src/Spout/Common/Helper/GlobalFunctionsHelper.php index 1d660c1..dd4356e 100644 --- a/src/Spout/Common/Helper/GlobalFunctionsHelper.php +++ b/src/Spout/Common/Helper/GlobalFunctionsHelper.php @@ -252,6 +252,17 @@ class GlobalFunctionsHelper header($string); } + /** + * Wrapper around global function ob_end_clean() + * @see ob_end_clean() + * + * @return void + */ + public function ob_end_clean() + { + ob_end_clean(); + } + /** * Wrapper around global function iconv() * @see iconv() diff --git a/src/Spout/Reader/ODS/Helper/CellValueFormatter.php b/src/Spout/Reader/ODS/Helper/CellValueFormatter.php index 38c1c85..99d8563 100644 --- a/src/Spout/Reader/ODS/Helper/CellValueFormatter.php +++ b/src/Spout/Reader/ODS/Helper/CellValueFormatter.php @@ -24,6 +24,7 @@ class CellValueFormatter const XML_NODE_P = 'p'; const XML_NODE_S = 'text:s'; const XML_NODE_A = 'text:a'; + const XML_NODE_SPAN = 'text:span'; /** Definition of XML attribute used to parse data */ const XML_ATTRIBUTE_TYPE = 'office:value-type'; @@ -104,7 +105,7 @@ class CellValueFormatter $spaceAttribute = $childNode->getAttribute(self::XML_ATTRIBUTE_C); $numSpaces = (!empty($spaceAttribute)) ? intval($spaceAttribute) : 1; $currentPValue .= str_repeat(' ', $numSpaces); - } else if ($childNode->nodeName === self::XML_NODE_A) { + } else if ($childNode->nodeName === self::XML_NODE_A || $childNode->nodeName === self::XML_NODE_SPAN) { $currentPValue .= $childNode->nodeValue; } } diff --git a/src/Spout/Writer/AbstractWriter.php b/src/Spout/Writer/AbstractWriter.php index effa45b..46f47cc 100755 --- a/src/Spout/Writer/AbstractWriter.php +++ b/src/Spout/Writer/AbstractWriter.php @@ -121,6 +121,10 @@ abstract class AbstractWriter implements WriterInterface $this->filePointer = $this->globalFunctionsHelper->fopen('php://output', 'w'); $this->throwIfFilePointerIsNotAvailable(); + // Clear any previous output (otherwise the generated file will be corrupted) + // @see https://github.com/box/spout/issues/241 + $this->globalFunctionsHelper->ob_end_clean(); + // Set headers $this->globalFunctionsHelper->header('Content-Type: ' . static::$headerContentType); $this->globalFunctionsHelper->header('Content-Disposition: attachment; filename="' . $this->outputFilePath . '"'); @@ -238,7 +242,8 @@ abstract class AbstractWriter implements WriterInterface public function addRows(array $dataRows) { if (!empty($dataRows)) { - if (!is_array($dataRows[0])) { + $firstRow = reset($dataRows); + if (!is_array($firstRow)) { throw new InvalidArgumentException('The input should be an array of arrays'); } diff --git a/tests/Spout/Reader/ODS/ReaderTest.php b/tests/Spout/Reader/ODS/ReaderTest.php index 759d842..dee4164 100644 --- a/tests/Spout/Reader/ODS/ReaderTest.php +++ b/tests/Spout/Reader/ODS/ReaderTest.php @@ -468,6 +468,20 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedRows, $allRows, 'Text in hyperlinks should be read'); } + /** + * @return void + */ + public function testReaderShouldReadInlineFontFormattingAsText() + { + $allRows = $this->getAllRowsForFile('sheet_with_inline_font_formatting.ods'); + + $expectedRows = [ + ['I am a yellow bird'] + ]; + + $this->assertEquals($expectedRows, $allRows, 'Text formatted inline should be read'); + } + /** * @param string $fileName * @param bool|void $shouldFormatDates diff --git a/tests/resources/ods/sheet_with_inline_font_formatting.ods b/tests/resources/ods/sheet_with_inline_font_formatting.ods new file mode 100644 index 0000000..60d4eee Binary files /dev/null and b/tests/resources/ods/sheet_with_inline_font_formatting.ods differ