diff --git a/src/Spout/Common/Helper/GlobalFunctionsHelper.php b/src/Spout/Common/Helper/GlobalFunctionsHelper.php index c5d6e31..bd1a0bd 100644 --- a/src/Spout/Common/Helper/GlobalFunctionsHelper.php +++ b/src/Spout/Common/Helper/GlobalFunctionsHelper.php @@ -30,7 +30,7 @@ class GlobalFunctionsHelper * @see fgets() * * @param resource $handle - * @param int|void $length + * @param int|null $length * @return string */ public function fgets($handle, $length = null) @@ -81,9 +81,9 @@ class GlobalFunctionsHelper * @see fgetcsv() * * @param resource $handle - * @param int|void $length - * @param string|void $delimiter - * @param string|void $enclosure + * @param int|null $length + * @param string|null $delimiter + * @param string|null $enclosure * @return array */ public function fgetcsv($handle, $length = null, $delimiter = null, $enclosure = null) @@ -97,8 +97,8 @@ class GlobalFunctionsHelper * * @param resource $handle * @param array $fields - * @param string|void $delimiter - * @param string|void $enclosure + * @param string|null $delimiter + * @param string|null $enclosure * @return int */ public function fputcsv($handle, array $fields, $delimiter = null, $enclosure = null) @@ -207,7 +207,7 @@ class GlobalFunctionsHelper * Wrapper around global function feof() * @see feof() * - * @param resource + * @param resource $handle * @return bool */ public function feof($handle) @@ -232,7 +232,7 @@ class GlobalFunctionsHelper * @see basename() * * @param string $path - * @param string|void $suffix + * @param string|null $suffix * @return string */ public function basename($path, $suffix = null) diff --git a/src/Spout/Reader/ODS/Helper/CellValueFormatter.php b/src/Spout/Reader/ODS/Helper/CellValueFormatter.php index 661db30..359fea7 100644 --- a/src/Spout/Reader/ODS/Helper/CellValueFormatter.php +++ b/src/Spout/Reader/ODS/Helper/CellValueFormatter.php @@ -127,8 +127,8 @@ class CellValueFormatter { $nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_VALUE); $nodeIntValue = intval($nodeValue); - // The "==" is intentionally not a "===" because only the value matters, not the type - $cellValue = ($nodeIntValue == $nodeValue) ? $nodeIntValue : floatval($nodeValue); + $nodeFloatValue = (float) $nodeValue; + $cellValue = ((float) $nodeIntValue === $nodeFloatValue) ? $nodeIntValue : $nodeFloatValue; return $cellValue; } @@ -141,9 +141,7 @@ class CellValueFormatter protected function formatBooleanCellValue($node) { $nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_BOOLEAN_VALUE); - // !! is similar to boolval() - $cellValue = !!$nodeValue; - return $cellValue; + return (bool) $nodeValue; } /** @@ -162,16 +160,18 @@ class CellValueFormatter if ($this->shouldFormatDates) { // The date is already formatted in the "p" tag $nodeWithValueAlreadyFormatted = $node->getElementsByTagName(self::XML_NODE_P)->item(0); - return $nodeWithValueAlreadyFormatted->nodeValue; + $cellValue = $nodeWithValueAlreadyFormatted->nodeValue; } else { // otherwise, get it from the "date-value" attribute try { $nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_DATE_VALUE); - return new \DateTime($nodeValue); + $cellValue = new \DateTime($nodeValue); } catch (\Exception $e) { - return null; + $cellValue = null; } } + + return $cellValue; } /** @@ -190,16 +190,18 @@ class CellValueFormatter if ($this->shouldFormatDates) { // The date is already formatted in the "p" tag $nodeWithValueAlreadyFormatted = $node->getElementsByTagName(self::XML_NODE_P)->item(0); - return $nodeWithValueAlreadyFormatted->nodeValue; + $cellValue = $nodeWithValueAlreadyFormatted->nodeValue; } else { // otherwise, get it from the "time-value" attribute try { $nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_TIME_VALUE); - return new \DateInterval($nodeValue); + $cellValue = new \DateInterval($nodeValue); } catch (\Exception $e) { - return null; + $cellValue = null; } } + + return $cellValue; } /** diff --git a/src/Spout/Reader/ODS/RowIterator.php b/src/Spout/Reader/ODS/RowIterator.php index e7feeb3..7472c82 100644 --- a/src/Spout/Reader/ODS/RowIterator.php +++ b/src/Spout/Reader/ODS/RowIterator.php @@ -311,7 +311,7 @@ class RowIterator implements IteratorInterface * row data yet (as we still need to apply the "num-columns-repeated" attribute). * * @param array $rowData - * @param string|int|float|bool|\DateTime|\DateInterval|null The value of the last read cell + * @param string|int|float|bool|\DateTime|\DateInterval|null $lastReadCellValue The value of the last read cell * @return bool Whether the row is empty */ protected function isEmptyRow($rowData, $lastReadCellValue) diff --git a/src/Spout/Reader/ODS/SheetIterator.php b/src/Spout/Reader/ODS/SheetIterator.php index 6986d24..a18dc9f 100644 --- a/src/Spout/Reader/ODS/SheetIterator.php +++ b/src/Spout/Reader/ODS/SheetIterator.php @@ -136,7 +136,7 @@ class SheetIterator implements IteratorInterface * * @param string $sheetName Name of the current sheet * @param int $sheetIndex Index of the current sheet - * @param string|null Name of the sheet that was defined as active or NULL if none defined + * @param string|null $activeSheetName Name of the sheet that was defined as active or NULL if none defined * @return bool Whether the current sheet was defined as the active one */ private function isActiveSheet($sheetName, $sheetIndex, $activeSheetName) diff --git a/src/Spout/Reader/Wrapper/XMLReader.php b/src/Spout/Reader/Wrapper/XMLReader.php index ffe6818..7f81b43 100644 --- a/src/Spout/Reader/Wrapper/XMLReader.php +++ b/src/Spout/Reader/Wrapper/XMLReader.php @@ -115,7 +115,7 @@ class XMLReader extends \XMLReader * Move cursor to next node skipping all subtrees * @see \XMLReader::next * - * @param string|void $localName The name of the next node to move to + * @param string|null $localName The name of the next node to move to * @return bool TRUE on success or FALSE on failure * @throws \Box\Spout\Reader\Exception\XMLProcessingException If an error/warning occurred */ diff --git a/src/Spout/Reader/XLSX/Helper/CellHelper.php b/src/Spout/Reader/XLSX/Helper/CellHelper.php index 6077839..0d1dc29 100644 --- a/src/Spout/Reader/XLSX/Helper/CellHelper.php +++ b/src/Spout/Reader/XLSX/Helper/CellHelper.php @@ -26,7 +26,7 @@ class CellHelper * Calling fillMissingArrayIndexes($dataArray, 'FILL') will return this array: ['FILL', 1, 'FILL', 3] * * @param array $dataArray The array to fill - * @param string|void $fillValue optional + * @param string $fillValue optional * @return array */ public static function fillMissingArrayIndexes($dataArray, $fillValue = '') diff --git a/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php b/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php index 200991c..338ccad 100644 --- a/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php +++ b/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php @@ -175,11 +175,14 @@ class CellValueFormatter $shouldFormatAsDate = $this->styleManager->shouldFormatNumericValueAsDate($cellStyleId); if ($shouldFormatAsDate) { - return $this->formatExcelTimestampValue(floatval($nodeValue), $cellStyleId); + $cellValue = $this->formatExcelTimestampValue(floatval($nodeValue), $cellStyleId); } else { $nodeIntValue = intval($nodeValue); - return ($nodeIntValue == $nodeValue) ? $nodeIntValue : floatval($nodeValue); + $nodeFloatValue = (float) $nodeValue; + $cellValue = ((float) $nodeIntValue === $nodeFloatValue) ? $nodeIntValue : $nodeFloatValue; } + + return $cellValue; } /** @@ -200,14 +203,16 @@ class CellValueFormatter if ($nodeValue >= 1) { // Values greater than 1 represent "dates". The value 1.0 representing the "base" date: 1900-01-01. - return $this->formatExcelTimestampValueAsDateValue($nodeValue, $cellStyleId); + $cellValue = $this->formatExcelTimestampValueAsDateValue($nodeValue, $cellStyleId); } else if ($nodeValue >= 0) { // Values between 0 and 1 represent "times". - return $this->formatExcelTimestampValueAsTimeValue($nodeValue, $cellStyleId); + $cellValue = $this->formatExcelTimestampValueAsTimeValue($nodeValue, $cellStyleId); } else { // invalid date - return null; + $cellValue = null; } + + return $cellValue; } /** @@ -232,10 +237,12 @@ class CellValueFormatter if ($this->shouldFormatDates) { $styleNumberFormatCode = $this->styleManager->getNumberFormatCode($cellStyleId); $phpDateFormat = DateFormatHelper::toPHPDateFormat($styleNumberFormatCode); - return $dateObj->format($phpDateFormat); + $cellValue = $dateObj->format($phpDateFormat); } else { - return $dateObj; + $cellValue = $dateObj; } + + return $cellValue; } /** @@ -261,13 +268,15 @@ class CellValueFormatter if ($this->shouldFormatDates) { $styleNumberFormatCode = $this->styleManager->getNumberFormatCode($cellStyleId); $phpDateFormat = DateFormatHelper::toPHPDateFormat($styleNumberFormatCode); - return $dateObj->format($phpDateFormat); + $cellValue = $dateObj->format($phpDateFormat); } else { - return $dateObj; + $cellValue = $dateObj; } } catch (\Exception $e) { - return null; + $cellValue = null; } + + return $cellValue; } /** @@ -278,9 +287,7 @@ class CellValueFormatter */ protected function formatBooleanCellValue($nodeValue) { - // !! is similar to boolval() - $cellValue = !!$nodeValue; - return $cellValue; + return (bool) $nodeValue; } /** @@ -294,9 +301,11 @@ class CellValueFormatter { // Mitigate thrown Exception on invalid date-time format (http://php.net/manual/en/datetime.construct.php) try { - return ($this->shouldFormatDates) ? $nodeValue : new \DateTime($nodeValue); + $cellValue = ($this->shouldFormatDates) ? $nodeValue : new \DateTime($nodeValue); } catch (\Exception $e) { - return null; + $cellValue = null; } + + return $cellValue; } } diff --git a/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php b/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php index ff808e0..b05c896 100644 --- a/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php +++ b/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php @@ -89,11 +89,13 @@ class CachingStrategyFactory if ($memoryAvailable === -1) { // if cannot get memory limit or if memory limit set as unlimited, don't trust and play safe - return ($sharedStringsUniqueCount < self::MAX_NUM_STRINGS_PER_TEMP_FILE); + $isInMemoryStrategyUsageSafe = ($sharedStringsUniqueCount < self::MAX_NUM_STRINGS_PER_TEMP_FILE); } else { $memoryNeeded = $sharedStringsUniqueCount * self::AMOUNT_MEMORY_NEEDED_PER_STRING_IN_KB; - return ($memoryAvailable > $memoryNeeded); + $isInMemoryStrategyUsageSafe = ($memoryAvailable > $memoryNeeded); } + + return $isInMemoryStrategyUsageSafe; } /** diff --git a/src/Spout/Reader/XLSX/Manager/SheetManager.php b/src/Spout/Reader/XLSX/Manager/SheetManager.php index b90d0a8..6da8475 100644 --- a/src/Spout/Reader/XLSX/Manager/SheetManager.php +++ b/src/Spout/Reader/XLSX/Manager/SheetManager.php @@ -52,7 +52,7 @@ class SheetManager /** * @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 Manages shared strings + * @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 */ diff --git a/src/Spout/Writer/Common/Creator/Style/BorderBuilder.php b/src/Spout/Writer/Common/Creator/Style/BorderBuilder.php index 81609e0..f613e4b 100644 --- a/src/Spout/Writer/Common/Creator/Style/BorderBuilder.php +++ b/src/Spout/Writer/Common/Creator/Style/BorderBuilder.php @@ -24,9 +24,9 @@ class BorderBuilder } /** - * @param string|void $color Border A RGB color code - * @param string|void $width Border width @see BorderPart::allowedWidths - * @param string|void $style Border style @see BorderPart::allowedStyles + * @param string $color Border A RGB color code + * @param string $width Border width @see BorderPart::allowedWidths + * @param string $style Border style @see BorderPart::allowedStyles * @return BorderBuilder */ public function setBorderTop($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID) @@ -36,9 +36,9 @@ class BorderBuilder } /** - * @param string|void $color Border A RGB color code - * @param string|void $width Border width @see BorderPart::allowedWidths - * @param string|void $style Border style @see BorderPart::allowedStyles + * @param string $color Border A RGB color code + * @param string $width Border width @see BorderPart::allowedWidths + * @param string $style Border style @see BorderPart::allowedStyles * @return BorderBuilder */ public function setBorderRight($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID) @@ -48,9 +48,9 @@ class BorderBuilder } /** - * @param string|void $color Border A RGB color code - * @param string|void $width Border width @see BorderPart::allowedWidths - * @param string|void $style Border style @see BorderPart::allowedStyles + * @param string $color Border A RGB color code + * @param string $width Border width @see BorderPart::allowedWidths + * @param string $style Border style @see BorderPart::allowedStyles * @return BorderBuilder */ public function setBorderBottom($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID) @@ -60,9 +60,9 @@ class BorderBuilder } /** - * @param string|void $color Border A RGB color code - * @param string|void $width Border width @see BorderPart::allowedWidths - * @param string|void $style Border style @see BorderPart::allowedStyles + * @param string $color Border A RGB color code + * @param string $width Border width @see BorderPart::allowedWidths + * @param string $style Border style @see BorderPart::allowedStyles * @return BorderBuilder */ public function setBorderLeft($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID) diff --git a/src/Spout/Writer/Common/Entity/Cell.php b/src/Spout/Writer/Common/Entity/Cell.php index ab9f2ff..77b5d08 100644 --- a/src/Spout/Writer/Common/Entity/Cell.php +++ b/src/Spout/Writer/Common/Entity/Cell.php @@ -97,15 +97,18 @@ class Cell { if (CellHelper::isBoolean($value)) { return self::TYPE_BOOLEAN; - } elseif (CellHelper::isEmpty($value)) { - return self::TYPE_EMPTY; - } elseif (CellHelper::isNumeric($this->getValue())) { - return self::TYPE_NUMERIC; - } elseif (CellHelper::isNonEmptyString($value)) { - return self::TYPE_STRING; - } else { - return self::TYPE_ERROR; } + if (CellHelper::isEmpty($value)) { + return self::TYPE_EMPTY; + } + if (CellHelper::isNumeric($this->getValue())) { + return self::TYPE_NUMERIC; + } + if (CellHelper::isNonEmptyString($value)) { + return self::TYPE_STRING; + } + + return self::TYPE_ERROR; } /** diff --git a/src/Spout/Writer/Common/Entity/Style/Border.php b/src/Spout/Writer/Common/Entity/Style/Border.php index 7046897..f872d34 100644 --- a/src/Spout/Writer/Common/Entity/Style/Border.php +++ b/src/Spout/Writer/Common/Entity/Style/Border.php @@ -28,7 +28,7 @@ class Border private $parts = []; /** - * @param array|void $borderParts + * @param array $borderParts */ public function __construct(array $borderParts = []) { diff --git a/src/Spout/Writer/Common/Entity/Style/Style.php b/src/Spout/Writer/Common/Entity/Style/Style.php index 16268b1..e82b365 100644 --- a/src/Spout/Writer/Common/Entity/Style/Style.php +++ b/src/Spout/Writer/Common/Entity/Style/Style.php @@ -322,7 +322,7 @@ class Style } /** - * @param bool|void $shouldWrap Should the text be wrapped + * @param bool $shouldWrap Should the text be wrapped * @return Style */ public function setShouldWrapText($shouldWrap = true) diff --git a/src/Spout/Writer/Common/Helper/ZipHelper.php b/src/Spout/Writer/Common/Helper/ZipHelper.php index f47a240..95130d7 100644 --- a/src/Spout/Writer/Common/Helper/ZipHelper.php +++ b/src/Spout/Writer/Common/Helper/ZipHelper.php @@ -65,7 +65,7 @@ class ZipHelper * @param \ZipArchive $zip An opened zip archive object * @param string $rootFolderPath Path of the root folder that will be ignored in the archive tree. * @param string $localFilePath Path of the file to be added, under the root folder - * @param string|void $existingFileMode Controls what to do when trying to add an existing file + * @param string $existingFileMode Controls what to do when trying to add an existing file * @return void */ public function addFileToArchive($zip, $rootFolderPath, $localFilePath, $existingFileMode = self::EXISTING_FILES_OVERWRITE) @@ -90,7 +90,7 @@ class ZipHelper * @param \ZipArchive $zip An opened zip archive object * @param string $rootFolderPath Path of the root folder that will be ignored in the archive tree. * @param string $localFilePath Path of the file to be added, under the root folder - * @param string|void $existingFileMode Controls what to do when trying to add an existing file + * @param string $existingFileMode Controls what to do when trying to add an existing file * @return void */ public function addUncompressedFileToArchive($zip, $rootFolderPath, $localFilePath, $existingFileMode = self::EXISTING_FILES_OVERWRITE) @@ -143,7 +143,7 @@ class ZipHelper /** * @param \ZipArchive $zip An opened zip archive object * @param string $folderPath Path to the folder to be zipped - * @param string|void $existingFileMode Controls what to do when trying to add an existing file + * @param string $existingFileMode Controls what to do when trying to add an existing file * @return void */ public function addFolderToArchive($zip, $folderPath, $existingFileMode = self::EXISTING_FILES_OVERWRITE) diff --git a/tests/Spout/Reader/CSV/ReaderTest.php b/tests/Spout/Reader/CSV/ReaderTest.php index 4c705cf..e35bb5a 100644 --- a/tests/Spout/Reader/CSV/ReaderTest.php +++ b/tests/Spout/Reader/CSV/ReaderTest.php @@ -479,10 +479,10 @@ class ReaderTest extends \PHPUnit_Framework_TestCase /** * @param string $fileName - * @param string|void $fieldDelimiter - * @param string|void $fieldEnclosure - * @param string|void $encoding - * @param bool|void $shouldPreserveEmptyRows + * @param string $fieldDelimiter + * @param string $fieldEnclosure + * @param string $encoding + * @param bool $shouldPreserveEmptyRows * @return array All the read rows the given file */ private function getAllRowsForFile( diff --git a/tests/Spout/Reader/CSV/SpoutTestStream.php b/tests/Spout/Reader/CSV/SpoutTestStream.php index fdaeb18..f8409bd 100644 --- a/tests/Spout/Reader/CSV/SpoutTestStream.php +++ b/tests/Spout/Reader/CSV/SpoutTestStream.php @@ -81,7 +81,7 @@ class SpoutTestStream /** * @param int $offset - * @param int|void $whence + * @param int $whence * @return bool */ public function stream_seek($offset, $whence = SEEK_SET) diff --git a/tests/Spout/Reader/ODS/ReaderTest.php b/tests/Spout/Reader/ODS/ReaderTest.php index f36348f..63810a4 100644 --- a/tests/Spout/Reader/ODS/ReaderTest.php +++ b/tests/Spout/Reader/ODS/ReaderTest.php @@ -521,8 +521,8 @@ class ReaderTest extends \PHPUnit_Framework_TestCase /** * @param string $fileName - * @param bool|void $shouldFormatDates - * @param bool|void $shouldPreserveEmptyRows + * @param bool $shouldFormatDates + * @param bool $shouldPreserveEmptyRows * @return array All the read rows the given file */ private function getAllRowsForFile($fileName, $shouldFormatDates = false, $shouldPreserveEmptyRows = false) diff --git a/tests/Spout/Reader/XLSX/Manager/StyleManagerTest.php b/tests/Spout/Reader/XLSX/Manager/StyleManagerTest.php index c9834f1..917cc5f 100644 --- a/tests/Spout/Reader/XLSX/Manager/StyleManagerTest.php +++ b/tests/Spout/Reader/XLSX/Manager/StyleManagerTest.php @@ -16,8 +16,8 @@ class StyleManagerTest extends \PHPUnit_Framework_TestCase { /** - * @param array|void $styleAttributes - * @param array|void $customNumberFormats + * @param array $styleAttributes + * @param array $customNumberFormats * @return StyleManager */ private function getStyleManagerMock($styleAttributes = [], $customNumberFormats = []) diff --git a/tests/Spout/Reader/XLSX/ReaderTest.php b/tests/Spout/Reader/XLSX/ReaderTest.php index b9e032e..b6b0313 100644 --- a/tests/Spout/Reader/XLSX/ReaderTest.php +++ b/tests/Spout/Reader/XLSX/ReaderTest.php @@ -621,8 +621,8 @@ class ReaderTest extends \PHPUnit_Framework_TestCase /** * @param string $fileName - * @param bool|void $shouldFormatDates - * @param bool|void $shouldPreserveEmptyRows + * @param bool $shouldFormatDates + * @param bool $shouldPreserveEmptyRows * @return array All the read rows the given file */ private function getAllRowsForFile($fileName, $shouldFormatDates = false, $shouldPreserveEmptyRows = false) diff --git a/tests/Spout/ReflectionHelper.php b/tests/Spout/ReflectionHelper.php index df02de8..c6d860f 100644 --- a/tests/Spout/ReflectionHelper.php +++ b/tests/Spout/ReflectionHelper.php @@ -51,7 +51,7 @@ class ReflectionHelper * @param string $class * @param string $valueName * @param mixed|null $value - * @param bool|void $saveOriginalValue + * @param bool $saveOriginalValue * @return void */ public static function setStaticValue($class, $valueName, $value, $saveOriginalValue = true) diff --git a/tests/Spout/Writer/XLSX/WriterWithStyleTest.php b/tests/Spout/Writer/XLSX/WriterWithStyleTest.php index 34a9db3..2c152cc 100644 --- a/tests/Spout/Writer/XLSX/WriterWithStyleTest.php +++ b/tests/Spout/Writer/XLSX/WriterWithStyleTest.php @@ -504,7 +504,8 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $bordersApplied = 0; /** @var \DOMElement $node */ foreach ($styleXfsElements->childNodes as $node) { - if ($node->getAttribute('applyBorder') == 1) { + $shouldApplyBorder = ((int) $node->getAttribute('applyBorder') === 1); + if ($shouldApplyBorder) { $bordersApplied++; $this->assertTrue((int)$node->getAttribute('borderId') > 0, 'BorderId is greater than 0'); } else {