Let's see what Scrutinizer makes of these changes (#1859)

* Let's see what Scrutinizer makes of these changes
This commit is contained in:
Mark Baker 2021-02-18 12:39:24 +01:00 committed by GitHub
parent 10c9c4cf23
commit 7c7b229041
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 197 additions and 176 deletions

View File

@ -33,7 +33,7 @@ class Database
} }
$key = array_search($field, $fieldNames); $key = array_search($field, $fieldNames);
return ($key) ? $key : null; return $key ?: null;
} }
/** /**

View File

@ -2270,7 +2270,7 @@ class Financial
// create an initial range, with a root somewhere between 0 and guess // create an initial range, with a root somewhere between 0 and guess
$guess = Functions::flattenSingleValue($guess); $guess = Functions::flattenSingleValue($guess);
$x1 = 0.0; $x1 = 0.0;
$x2 = $guess ? $guess : 0.1; $x2 = $guess ?: 0.1;
$f1 = self::xnpvOrdered($x1, $values, $dates, false); $f1 = self::xnpvOrdered($x1, $values, $dates, false);
$f2 = self::xnpvOrdered($x2, $values, $dates, false); $f2 = self::xnpvOrdered($x2, $values, $dates, false);
$found = false; $found = false;
@ -2306,12 +2306,12 @@ class Financial
* *
* @param float $rate the discount rate to apply to the cash flows * @param float $rate the discount rate to apply to the cash flows
* @param float[] $values A series of cash flows that corresponds to a schedule of payments in dates. * @param float[] $values A series of cash flows that corresponds to a schedule of payments in dates.
* The first payment is optional and corresponds to a cost or payment that occurs at the beginning of the investment. * The first payment is optional and corresponds to a cost or payment that occurs at the beginning of the investment.
* If the first value is a cost or payment, it must be a negative value. All succeeding payments are discounted based on a 365-day year. * If the first value is a cost or payment, it must be a negative value. All succeeding payments are discounted based on a 365-day year.
* The series of values must contain at least one positive value and one negative value. * The series of values must contain at least one positive value and one negative value.
* @param mixed[] $dates A schedule of payment dates that corresponds to the cash flow payments. * @param mixed[] $dates A schedule of payment dates that corresponds to the cash flow payments.
* The first payment date indicates the beginning of the schedule of payments. * The first payment date indicates the beginning of the schedule of payments.
* All other dates must be later than this date, but they may occur in any order. * All other dates must be later than this date, but they may occur in any order.
* *
* @return float|mixed|string * @return float|mixed|string
*/ */

View File

@ -146,8 +146,8 @@ class MathTrig
$xCoordinate = Functions::flattenSingleValue($xCoordinate); $xCoordinate = Functions::flattenSingleValue($xCoordinate);
$yCoordinate = Functions::flattenSingleValue($yCoordinate); $yCoordinate = Functions::flattenSingleValue($yCoordinate);
$xCoordinate = ($xCoordinate !== null) ? $xCoordinate : 0.0; $xCoordinate = $xCoordinate ?? 0.0;
$yCoordinate = ($yCoordinate !== null) ? $yCoordinate : 0.0; $yCoordinate = $yCoordinate ?? 0.0;
if ( if (
((is_numeric($xCoordinate)) || (is_bool($xCoordinate))) && ((is_numeric($xCoordinate)) || (is_bool($xCoordinate))) &&

View File

@ -340,9 +340,9 @@ class Axis extends Properties
{ {
$this->setShadowPresetsProperties((int) $sh_presets) $this->setShadowPresetsProperties((int) $sh_presets)
->setShadowColor( ->setShadowColor(
$sh_color_value === null ? $this->shadowProperties['color']['value'] : $sh_color_value, $sh_color_value ?? $this->shadowProperties['color']['value'],
$sh_color_alpha === null ? (int) $this->shadowProperties['color']['alpha'] : $sh_color_alpha, $sh_color_alpha ?? (int) $this->shadowProperties['color']['alpha'],
$sh_color_type === null ? $this->shadowProperties['color']['type'] : $sh_color_type $sh_color_type ?? $this->shadowProperties['color']['type']
) )
->setShadowBlur($sh_blur) ->setShadowBlur($sh_blur)
->setShadowAngle($sh_angle) ->setShadowAngle($sh_angle)
@ -482,9 +482,9 @@ class Axis extends Properties
{ {
$this->setGlowSize($size) $this->setGlowSize($size)
->setGlowColor( ->setGlowColor(
$color_value === null ? $this->glowProperties['color']['value'] : $color_value, $color_value ?? $this->glowProperties['color']['value'],
$color_alpha === null ? (int) $this->glowProperties['color']['alpha'] : $color_alpha, $color_alpha ?? (int) $this->glowProperties['color']['alpha'],
$color_type === null ? $this->glowProperties['color']['type'] : $color_type $color_type ?? $this->glowProperties['color']['type']
); );
} }

View File

@ -291,9 +291,9 @@ class GridLines extends Properties
$this->activateObject() $this->activateObject()
->setShadowPresetsProperties((int) $sh_presets) ->setShadowPresetsProperties((int) $sh_presets)
->setShadowColor( ->setShadowColor(
$sh_color_value === null ? $this->shadowProperties['color']['value'] : $sh_color_value, $sh_color_value ?? $this->shadowProperties['color']['value'],
$sh_color_alpha === null ? (int) $this->shadowProperties['color']['alpha'] : $this->getTrueAlpha($sh_color_alpha), $sh_color_alpha === null ? (int) $this->shadowProperties['color']['alpha'] : $this->getTrueAlpha($sh_color_alpha),
$sh_color_type === null ? $this->shadowProperties['color']['type'] : $sh_color_type $sh_color_type ?? $this->shadowProperties['color']['type']
) )
->setShadowBlur($sh_blur) ->setShadowBlur($sh_blur)
->setShadowAngle($sh_angle) ->setShadowAngle($sh_angle)

View File

@ -711,7 +711,7 @@ class Html
} elseif (strpos(trim($attributeValue), '#') === 0) { } elseif (strpos(trim($attributeValue), '#') === 0) {
$this->$attributeName = ltrim($attributeValue, '#'); $this->$attributeName = ltrim($attributeValue, '#');
} else { } else {
$this->$attributeName = $this->colourNameLookup($attributeValue); $this->$attributeName = static::colourNameLookup($attributeValue);
} }
} else { } else {
$this->$attributeName = $attributeValue; $this->$attributeName = $attributeValue;

View File

@ -657,7 +657,7 @@ class Gnumeric extends BaseReader
$column = $columnAttributes['No']; $column = $columnAttributes['No'];
$columnWidth = ((float) $columnAttributes['Unit']) / 5.4; $columnWidth = ((float) $columnAttributes['Unit']) / 5.4;
$hidden = (isset($columnAttributes['Hidden'])) && ((string) $columnAttributes['Hidden'] == '1'); $hidden = (isset($columnAttributes['Hidden'])) && ((string) $columnAttributes['Hidden'] == '1');
$columnCount = (isset($columnAttributes['Count'])) ? $columnAttributes['Count'] : 1; $columnCount = $columnAttributes['Count'] ?? 1;
while ($c < $column) { while ($c < $column) {
$this->spreadsheet->getActiveSheet()->getColumnDimension(Coordinate::stringFromColumnIndex($c + 1))->setWidth($defaultWidth); $this->spreadsheet->getActiveSheet()->getColumnDimension(Coordinate::stringFromColumnIndex($c + 1))->setWidth($defaultWidth);
++$c; ++$c;
@ -696,7 +696,7 @@ class Gnumeric extends BaseReader
$row = $rowAttributes['No']; $row = $rowAttributes['No'];
$rowHeight = (float) $rowAttributes['Unit']; $rowHeight = (float) $rowAttributes['Unit'];
$hidden = (isset($rowAttributes['Hidden'])) && ((string) $rowAttributes['Hidden'] == '1'); $hidden = (isset($rowAttributes['Hidden'])) && ((string) $rowAttributes['Hidden'] == '1');
$rowCount = (isset($rowAttributes['Count'])) ? $rowAttributes['Count'] : 1; $rowCount = $rowAttributes['Count'] ?? 1;
while ($r < $row) { while ($r < $row) {
++$r; ++$r;
$this->spreadsheet->getActiveSheet()->getRowDimension($r)->setRowHeight($defaultHeight); $this->spreadsheet->getActiveSheet()->getRowDimension($r)->setRowHeight($defaultHeight);

View File

@ -419,14 +419,14 @@ class Slk extends BaseReader
if ($columnWidth > '') { if ($columnWidth > '') {
if ($startCol == $endCol) { if ($startCol == $endCol) {
$startCol = Coordinate::stringFromColumnIndex((int) $startCol); $startCol = Coordinate::stringFromColumnIndex((int) $startCol);
$spreadsheet->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth); $spreadsheet->getActiveSheet()->getColumnDimension($startCol)->setWidth((float) $columnWidth);
} else { } else {
$startCol = Coordinate::stringFromColumnIndex($startCol); $startCol = Coordinate::stringFromColumnIndex($startCol);
$endCol = Coordinate::stringFromColumnIndex($endCol); $endCol = Coordinate::stringFromColumnIndex($endCol);
$spreadsheet->getActiveSheet()->getColumnDimension($startCol)->setWidth((float) $columnWidth); $spreadsheet->getActiveSheet()->getColumnDimension($startCol)->setWidth((float) $columnWidth);
do { do {
$spreadsheet->getActiveSheet()->getColumnDimension(++$startCol)->setWidth($columnWidth); $spreadsheet->getActiveSheet()->getColumnDimension(++$startCol)->setWidth((float) $columnWidth);
} while ($startCol != $endCol); } while ($startCol !== $endCol);
} }
} }
} }

View File

@ -1703,7 +1703,8 @@ class Xls extends BaseReader
// max 2048 bytes will probably throw a wobbly. // max 2048 bytes will probably throw a wobbly.
$row = self::getUInt2d($recordData, 0); $row = self::getUInt2d($recordData, 0);
$extension = true; $extension = true;
$cellAddress = array_pop(array_keys($this->phpSheet->getComments())); $arrayKeys = array_keys($this->phpSheet->getComments());
$cellAddress = array_pop($arrayKeys);
} }
$cellAddress = str_replace('$', '', $cellAddress); $cellAddress = str_replace('$', '', $cellAddress);

View File

@ -516,7 +516,7 @@ class Xlsx extends BaseReader
} }
$style = (object) [ $style = (object) [
'numFmt' => $numFmt === null ? NumberFormat::FORMAT_GENERAL : $numFmt, 'numFmt' => $numFmt ?? NumberFormat::FORMAT_GENERAL,
'font' => $xmlStyles->fonts->font[(int) ($xf['fontId'])], 'font' => $xmlStyles->fonts->font[(int) ($xf['fontId'])],
'fill' => $xmlStyles->fills->fill[(int) ($xf['fillId'])], 'fill' => $xmlStyles->fills->fill[(int) ($xf['fillId'])],
'border' => $xmlStyles->borders->border[(int) ($xf['borderId'])], 'border' => $xmlStyles->borders->border[(int) ($xf['borderId'])],

View File

@ -421,7 +421,7 @@ class Xml extends BaseReader
$xml_ss = $xml->children($namespaces['ss']); $xml_ss = $xml->children($namespaces['ss']);
foreach ($xml_ss->Worksheet as $worksheetx) { foreach ($xml_ss->Worksheet as $worksheetx) {
$worksheet = ($worksheetx === null) ? new SimpleXMLElement('<xml></xml>') : $worksheetx; $worksheet = $worksheetx ?? new SimpleXMLElement('<xml></xml>');
$worksheet_ss = self::getAttributes($worksheet, $namespaces['ss']); $worksheet_ss = self::getAttributes($worksheet, $namespaces['ss']);
if ( if (
@ -665,7 +665,7 @@ class Xml extends BaseReader
foreach ($xml->Styles[0] as $style) { foreach ($xml->Styles[0] as $style) {
$style_ss = self::getAttributes($style, $namespaces['ss']); $style_ss = self::getAttributes($style, $namespaces['ss']);
$styleID = (string) $style_ss['ID']; $styleID = (string) $style_ss['ID'];
$this->styles[$styleID] = (isset($this->styles['Default'])) ? $this->styles['Default'] : []; $this->styles[$styleID] = $this->styles['Default'] ?? [];
foreach ($style as $styleType => $styleDatax) { foreach ($style as $styleType => $styleDatax) {
$styleData = $styleDatax ?? new SimpleXMLElement('<xml></xml>'); $styleData = $styleDatax ?? new SimpleXMLElement('<xml></xml>');
$styleAttributes = $styleData->attributes($namespaces['ss']); $styleAttributes = $styleData->attributes($namespaces['ss']);

View File

@ -359,7 +359,9 @@ class Style extends Supervisor
$cellIterator = $columnIterator->getCellIterator(); $cellIterator = $columnIterator->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true); $cellIterator->setIterateOnlyExistingCells(true);
foreach ($cellIterator as $columnCell) { foreach ($cellIterator as $columnCell) {
$columnCell->getStyle()->applyFromArray($pStyles); if ($columnCell !== null) {
$columnCell->getStyle()->applyFromArray($pStyles);
}
} }
} }
@ -367,7 +369,7 @@ class Style extends Supervisor
case 'ROW': case 'ROW':
$oldXfIndexes = []; $oldXfIndexes = [];
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
if ($this->getActiveSheet()->getRowDimension($row)->getXfIndex() == null) { if ($this->getActiveSheet()->getRowDimension($row)->getXfIndex() === null) {
$oldXfIndexes[0] = true; // row without explicit style should be formatted based on default style $oldXfIndexes[0] = true; // row without explicit style should be formatted based on default style
} else { } else {
$oldXfIndexes[$this->getActiveSheet()->getRowDimension($row)->getXfIndex()] = true; $oldXfIndexes[$this->getActiveSheet()->getRowDimension($row)->getXfIndex()] = true;
@ -377,7 +379,9 @@ class Style extends Supervisor
$cellIterator = $rowIterator->getCellIterator(); $cellIterator = $rowIterator->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true); $cellIterator->setIterateOnlyExistingCells(true);
foreach ($cellIterator as $rowCell) { foreach ($cellIterator as $rowCell) {
$rowCell->getStyle()->applyFromArray($pStyles); if ($rowCell !== null) {
$rowCell->getStyle()->applyFromArray($pStyles);
}
} }
} }
@ -423,8 +427,8 @@ class Style extends Supervisor
case 'ROW': case 'ROW':
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
$rowDimension = $this->getActiveSheet()->getRowDimension($row); $rowDimension = $this->getActiveSheet()->getRowDimension($row);
$oldXfIndex = $rowDimension->getXfIndex() === null ? // row without explicit style should be formatted based on default style
0 : $rowDimension->getXfIndex(); // row without explicit style should be formatted based on default style $oldXfIndex = $rowDimension->getXfIndex() ?? 0;
$rowDimension->setXfIndex($newXfIndexes[$oldXfIndex]); $rowDimension->setXfIndex($newXfIndexes[$oldXfIndex]);
} }

View File

@ -30,10 +30,8 @@ abstract class CellIterator implements Iterator
/** /**
* Get loop only existing cells. * Get loop only existing cells.
*
* @return bool
*/ */
public function getIterateOnlyExistingCells() public function getIterateOnlyExistingCells(): bool
{ {
return $this->onlyExistingCells; return $this->onlyExistingCells;
} }
@ -45,10 +43,8 @@ abstract class CellIterator implements Iterator
/** /**
* Set the iterator to loop only existing cells. * Set the iterator to loop only existing cells.
*
* @param bool $value
*/ */
public function setIterateOnlyExistingCells($value): void public function setIterateOnlyExistingCells(bool $value): void
{ {
$this->onlyExistingCells = (bool) $value; $this->onlyExistingCells = (bool) $value;

View File

@ -41,10 +41,8 @@ class Column
/** /**
* Get column index as string eg: 'A'. * Get column index as string eg: 'A'.
*
* @return string
*/ */
public function getColumnIndex() public function getColumnIndex(): string
{ {
return $this->columnIndex; return $this->columnIndex;
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Worksheet; namespace PhpOffice\PhpSpreadsheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
@ -59,7 +60,7 @@ class ColumnCellIterator extends CellIterator
* *
* @return $this * @return $this
*/ */
public function resetStart($startRow = 1) public function resetStart(int $startRow = 1)
{ {
$this->startRow = $startRow; $this->startRow = $startRow;
$this->adjustForExistingOnlyRange(); $this->adjustForExistingOnlyRange();
@ -77,7 +78,7 @@ class ColumnCellIterator extends CellIterator
*/ */
public function resetEnd($endRow = null) public function resetEnd($endRow = null)
{ {
$this->endRow = ($endRow) ? $endRow : $this->worksheet->getHighestRow(); $this->endRow = $endRow ?: $this->worksheet->getHighestRow();
$this->adjustForExistingOnlyRange(); $this->adjustForExistingOnlyRange();
return $this; return $this;
@ -90,7 +91,7 @@ class ColumnCellIterator extends CellIterator
* *
* @return $this * @return $this
*/ */
public function seek($row = 1) public function seek(int $row = 1)
{ {
if ($this->onlyExistingCells && !($this->worksheet->cellExistsByColumnAndRow($this->columnIndex, $row))) { if ($this->onlyExistingCells && !($this->worksheet->cellExistsByColumnAndRow($this->columnIndex, $row))) {
throw new PhpSpreadsheetException('In "IterateOnlyExistingCells" mode and Cell does not exist'); throw new PhpSpreadsheetException('In "IterateOnlyExistingCells" mode and Cell does not exist');
@ -113,20 +114,16 @@ class ColumnCellIterator extends CellIterator
/** /**
* Return the current cell in this worksheet column. * Return the current cell in this worksheet column.
*
* @return \PhpOffice\PhpSpreadsheet\Cell\Cell
*/ */
public function current() public function current(): ?Cell
{ {
return $this->worksheet->getCellByColumnAndRow($this->columnIndex, $this->currentRow); return $this->worksheet->getCellByColumnAndRow($this->columnIndex, $this->currentRow);
} }
/** /**
* Return the current iterator key. * Return the current iterator key.
*
* @return int
*/ */
public function key() public function key(): int
{ {
return $this->currentRow; return $this->currentRow;
} }
@ -161,10 +158,8 @@ class ColumnCellIterator extends CellIterator
/** /**
* Indicate if more rows exist in the worksheet range of rows that we're iterating. * Indicate if more rows exist in the worksheet range of rows that we're iterating.
*
* @return bool
*/ */
public function valid() public function valid(): bool
{ {
return $this->currentRow <= $this->endRow && $this->currentRow >= $this->startRow; return $this->currentRow <= $this->endRow && $this->currentRow >= $this->startRow;
} }

View File

@ -43,10 +43,8 @@ class ColumnDimension extends Dimension
/** /**
* Get column index as string eg: 'A'. * Get column index as string eg: 'A'.
*
* @return string
*/ */
public function getColumnIndex() public function getColumnIndex(): string
{ {
return $this->columnIndex; return $this->columnIndex;
} }
@ -54,23 +52,19 @@ class ColumnDimension extends Dimension
/** /**
* Set column index as string eg: 'A'. * Set column index as string eg: 'A'.
* *
* @param string $pValue
*
* @return $this * @return $this
*/ */
public function setColumnIndex($pValue) public function setColumnIndex(string $index)
{ {
$this->columnIndex = $pValue; $this->columnIndex = $index;
return $this; return $this;
} }
/** /**
* Get Width. * Get Width.
*
* @return float
*/ */
public function getWidth() public function getWidth(): float
{ {
return $this->width; return $this->width;
} }
@ -78,23 +72,19 @@ class ColumnDimension extends Dimension
/** /**
* Set Width. * Set Width.
* *
* @param float $pValue
*
* @return $this * @return $this
*/ */
public function setWidth($pValue) public function setWidth(float $width)
{ {
$this->width = $pValue; $this->width = $width;
return $this; return $this;
} }
/** /**
* Get Auto Size. * Get Auto Size.
*
* @return bool
*/ */
public function getAutoSize() public function getAutoSize(): bool
{ {
return $this->autoSize; return $this->autoSize;
} }
@ -102,13 +92,11 @@ class ColumnDimension extends Dimension
/** /**
* Set Auto Size. * Set Auto Size.
* *
* @param bool $pValue
*
* @return $this * @return $this
*/ */
public function setAutoSize($pValue) public function setAutoSize(bool $autosizeEnabled)
{ {
$this->autoSize = $pValue; $this->autoSize = $autosizeEnabled;
return $this; return $this;
} }

View File

@ -67,11 +67,13 @@ class ColumnIterator implements Iterator
* *
* @return $this * @return $this
*/ */
public function resetStart($startColumn = 'A') public function resetStart(string $startColumn = 'A')
{ {
$startColumnIndex = Coordinate::columnIndexFromString($startColumn); $startColumnIndex = Coordinate::columnIndexFromString($startColumn);
if ($startColumnIndex > Coordinate::columnIndexFromString($this->worksheet->getHighestColumn())) { if ($startColumnIndex > Coordinate::columnIndexFromString($this->worksheet->getHighestColumn())) {
throw new Exception("Start column ({$startColumn}) is beyond highest column ({$this->worksheet->getHighestColumn()})"); throw new Exception(
"Start column ({$startColumn}) is beyond highest column ({$this->worksheet->getHighestColumn()})"
);
} }
$this->startColumnIndex = $startColumnIndex; $this->startColumnIndex = $startColumnIndex;
@ -92,7 +94,7 @@ class ColumnIterator implements Iterator
*/ */
public function resetEnd($endColumn = null) public function resetEnd($endColumn = null)
{ {
$endColumn = $endColumn ? $endColumn : $this->worksheet->getHighestColumn(); $endColumn = $endColumn ?: $this->worksheet->getHighestColumn();
$this->endColumnIndex = Coordinate::columnIndexFromString($endColumn); $this->endColumnIndex = Coordinate::columnIndexFromString($endColumn);
return $this; return $this;
@ -105,11 +107,13 @@ class ColumnIterator implements Iterator
* *
* @return $this * @return $this
*/ */
public function seek($column = 'A') public function seek(string $column = 'A')
{ {
$column = Coordinate::columnIndexFromString($column); $column = Coordinate::columnIndexFromString($column);
if (($column < $this->startColumnIndex) || ($column > $this->endColumnIndex)) { if (($column < $this->startColumnIndex) || ($column > $this->endColumnIndex)) {
throw new PhpSpreadsheetException("Column $column is out of range ({$this->startColumnIndex} - {$this->endColumnIndex})"); throw new PhpSpreadsheetException(
"Column $column is out of range ({$this->startColumnIndex} - {$this->endColumnIndex})"
);
} }
$this->currentColumnIndex = $column; $this->currentColumnIndex = $column;
@ -136,10 +140,8 @@ class ColumnIterator implements Iterator
/** /**
* Return the current iterator key. * Return the current iterator key.
*
* @return string
*/ */
public function key() public function key(): string
{ {
return Coordinate::stringFromColumnIndex($this->currentColumnIndex); return Coordinate::stringFromColumnIndex($this->currentColumnIndex);
} }
@ -162,10 +164,8 @@ class ColumnIterator implements Iterator
/** /**
* Indicate if more columns exist in the worksheet range of columns that we're iterating. * Indicate if more columns exist in the worksheet range of columns that we're iterating.
*
* @return bool
*/ */
public function valid() public function valid(): bool
{ {
return $this->currentColumnIndex <= $this->endColumnIndex && $this->currentColumnIndex >= $this->startColumnIndex; return $this->currentColumnIndex <= $this->endColumnIndex && $this->currentColumnIndex >= $this->startColumnIndex;
} }

View File

@ -47,10 +47,8 @@ abstract class Dimension
/** /**
* Get Visible. * Get Visible.
*
* @return bool
*/ */
public function getVisible() public function getVisible(): bool
{ {
return $this->visible; return $this->visible;
} }
@ -58,23 +56,19 @@ abstract class Dimension
/** /**
* Set Visible. * Set Visible.
* *
* @param bool $pValue
*
* @return $this * @return $this
*/ */
public function setVisible($pValue) public function setVisible(bool $visible)
{ {
$this->visible = (bool) $pValue; $this->visible = $visible;
return $this; return $this;
} }
/** /**
* Get Outline Level. * Get Outline Level.
*
* @return int
*/ */
public function getOutlineLevel() public function getOutlineLevel(): int
{ {
return $this->outlineLevel; return $this->outlineLevel;
} }
@ -83,27 +77,23 @@ abstract class Dimension
* Set Outline Level. * Set Outline Level.
* Value must be between 0 and 7. * Value must be between 0 and 7.
* *
* @param int $pValue
*
* @return $this * @return $this
*/ */
public function setOutlineLevel($pValue) public function setOutlineLevel(int $level)
{ {
if ($pValue < 0 || $pValue > 7) { if ($level < 0 || $level > 7) {
throw new PhpSpreadsheetException('Outline level must range between 0 and 7.'); throw new PhpSpreadsheetException('Outline level must range between 0 and 7.');
} }
$this->outlineLevel = $pValue; $this->outlineLevel = $level;
return $this; return $this;
} }
/** /**
* Get Collapsed. * Get Collapsed.
*
* @return bool
*/ */
public function getCollapsed() public function getCollapsed(): bool
{ {
return $this->collapsed; return $this->collapsed;
} }
@ -111,13 +101,11 @@ abstract class Dimension
/** /**
* Set Collapsed. * Set Collapsed.
* *
* @param bool $pValue
*
* @return $this * @return $this
*/ */
public function setCollapsed($pValue) public function setCollapsed(bool $collapsed)
{ {
$this->collapsed = (bool) $pValue; $this->collapsed = $collapsed;
return $this; return $this;
} }
@ -127,7 +115,7 @@ abstract class Dimension
* *
* @return int * @return int
*/ */
public function getXfIndex() public function getXfIndex(): ?int
{ {
return $this->xfIndex; return $this->xfIndex;
} }
@ -135,11 +123,9 @@ abstract class Dimension
/** /**
* Set index to cellXf. * Set index to cellXf.
* *
* @param int $pValue
*
* @return $this * @return $this
*/ */
public function setXfIndex($pValue) public function setXfIndex(int $pValue)
{ {
$this->xfIndex = $pValue; $this->xfIndex = $pValue;

View File

@ -47,20 +47,16 @@ class Iterator implements \Iterator
/** /**
* Current Worksheet. * Current Worksheet.
*
* @return Worksheet
*/ */
public function current() public function current(): Worksheet
{ {
return $this->subject->getSheet($this->position); return $this->subject->getSheet($this->position);
} }
/** /**
* Current key. * Current key.
*
* @return int
*/ */
public function key() public function key(): int
{ {
return $this->position; return $this->position;
} }

View File

@ -41,10 +41,8 @@ class Row
/** /**
* Get row index. * Get row index.
*
* @return int
*/ */
public function getRowIndex() public function getRowIndex(): int
{ {
return $this->rowIndex; return $this->rowIndex;
} }
@ -64,10 +62,8 @@ class Row
/** /**
* Returns bound worksheet. * Returns bound worksheet.
*
* @return Worksheet
*/ */
public function getWorksheet() public function getWorksheet(): Worksheet
{ {
return $this->worksheet; return $this->worksheet;
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Worksheet; namespace PhpOffice\PhpSpreadsheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
@ -59,7 +60,7 @@ class RowCellIterator extends CellIterator
* *
* @return $this * @return $this
*/ */
public function resetStart($startColumn = 'A') public function resetStart(string $startColumn = 'A')
{ {
$this->startColumnIndex = Coordinate::columnIndexFromString($startColumn); $this->startColumnIndex = Coordinate::columnIndexFromString($startColumn);
$this->adjustForExistingOnlyRange(); $this->adjustForExistingOnlyRange();
@ -77,7 +78,7 @@ class RowCellIterator extends CellIterator
*/ */
public function resetEnd($endColumn = null) public function resetEnd($endColumn = null)
{ {
$endColumn = $endColumn ? $endColumn : $this->worksheet->getHighestColumn(); $endColumn = $endColumn ?: $this->worksheet->getHighestColumn();
$this->endColumnIndex = Coordinate::columnIndexFromString($endColumn); $this->endColumnIndex = Coordinate::columnIndexFromString($endColumn);
$this->adjustForExistingOnlyRange(); $this->adjustForExistingOnlyRange();
@ -91,7 +92,7 @@ class RowCellIterator extends CellIterator
* *
* @return $this * @return $this
*/ */
public function seek($column = 'A') public function seek(string $column = 'A')
{ {
$columnx = $column; $columnx = $column;
$column = Coordinate::columnIndexFromString($column); $column = Coordinate::columnIndexFromString($column);
@ -116,20 +117,16 @@ class RowCellIterator extends CellIterator
/** /**
* Return the current cell in this worksheet row. * Return the current cell in this worksheet row.
*
* @return \PhpOffice\PhpSpreadsheet\Cell\Cell
*/ */
public function current() public function current(): ?Cell
{ {
return $this->worksheet->getCellByColumnAndRow($this->currentColumnIndex, $this->rowIndex); return $this->worksheet->getCellByColumnAndRow($this->currentColumnIndex, $this->rowIndex);
} }
/** /**
* Return the current iterator key. * Return the current iterator key.
*
* @return string
*/ */
public function key() public function key(): string
{ {
return Coordinate::stringFromColumnIndex($this->currentColumnIndex); return Coordinate::stringFromColumnIndex($this->currentColumnIndex);
} }
@ -166,10 +163,8 @@ class RowCellIterator extends CellIterator
/** /**
* Return the current iterator position. * Return the current iterator position.
*
* @return int
*/ */
public function getCurrentColumnIndex() public function getCurrentColumnIndex(): int
{ {
return $this->currentColumnIndex; return $this->currentColumnIndex;
} }

View File

@ -43,10 +43,8 @@ class RowDimension extends Dimension
/** /**
* Get Row Index. * Get Row Index.
*
* @return int
*/ */
public function getRowIndex() public function getRowIndex(): int
{ {
return $this->rowIndex; return $this->rowIndex;
} }
@ -54,13 +52,11 @@ class RowDimension extends Dimension
/** /**
* Set Row Index. * Set Row Index.
* *
* @param int $pValue
*
* @return $this * @return $this
*/ */
public function setRowIndex($pValue) public function setRowIndex(int $index)
{ {
$this->rowIndex = $pValue; $this->rowIndex = $index;
return $this; return $this;
} }
@ -78,23 +74,21 @@ class RowDimension extends Dimension
/** /**
* Set Row Height. * Set Row Height.
* *
* @param float $pValue * @param float $height
* *
* @return $this * @return $this
*/ */
public function setRowHeight($pValue) public function setRowHeight($height)
{ {
$this->height = $pValue; $this->height = $height;
return $this; return $this;
} }
/** /**
* Get ZeroHeight. * Get ZeroHeight.
*
* @return bool
*/ */
public function getZeroHeight() public function getZeroHeight(): bool
{ {
return $this->zeroHeight; return $this->zeroHeight;
} }
@ -102,11 +96,9 @@ class RowDimension extends Dimension
/** /**
* Set ZeroHeight. * Set ZeroHeight.
* *
* @param bool $pValue
*
* @return $this * @return $this
*/ */
public function setZeroHeight($pValue) public function setZeroHeight(bool $pValue)
{ {
$this->zeroHeight = $pValue; $this->zeroHeight = $pValue;

View File

@ -65,10 +65,12 @@ class RowIterator implements Iterator
* *
* @return $this * @return $this
*/ */
public function resetStart($startRow = 1) public function resetStart(int $startRow = 1)
{ {
if ($startRow > $this->subject->getHighestRow()) { if ($startRow > $this->subject->getHighestRow()) {
throw new PhpSpreadsheetException("Start row ({$startRow}) is beyond highest row ({$this->subject->getHighestRow()})"); throw new PhpSpreadsheetException(
"Start row ({$startRow}) is beyond highest row ({$this->subject->getHighestRow()})"
);
} }
$this->startRow = $startRow; $this->startRow = $startRow;
@ -89,7 +91,7 @@ class RowIterator implements Iterator
*/ */
public function resetEnd($endRow = null) public function resetEnd($endRow = null)
{ {
$this->endRow = ($endRow) ? $endRow : $this->subject->getHighestRow(); $this->endRow = $endRow ?: $this->subject->getHighestRow();
return $this; return $this;
} }
@ -101,7 +103,7 @@ class RowIterator implements Iterator
* *
* @return $this * @return $this
*/ */
public function seek($row = 1) public function seek(int $row = 1)
{ {
if (($row < $this->startRow) || ($row > $this->endRow)) { if (($row < $this->startRow) || ($row > $this->endRow)) {
throw new PhpSpreadsheetException("Row $row is out of range ({$this->startRow} - {$this->endRow})"); throw new PhpSpreadsheetException("Row $row is out of range ({$this->startRow} - {$this->endRow})");
@ -131,10 +133,8 @@ class RowIterator implements Iterator
/** /**
* Return the current iterator key. * Return the current iterator key.
*
* @return int
*/ */
public function key() public function key(): int
{ {
return $this->position; return $this->position;
} }
@ -157,10 +157,8 @@ class RowIterator implements Iterator
/** /**
* Indicate if more rows exist in the worksheet range of rows that we're iterating. * Indicate if more rows exist in the worksheet range of rows that we're iterating.
*
* @return bool
*/ */
public function valid() public function valid(): bool
{ {
return $this->position <= $this->endRow && $this->position >= $this->startRow; return $this->position <= $this->endRow && $this->position >= $this->startRow;
} }

View File

@ -1715,9 +1715,7 @@ class Worksheet extends BIFFwriter
$length = 0x0022; // Number of bytes to follow $length = 0x0022; // Number of bytes to follow
$iPaperSize = $this->phpSheet->getPageSetup()->getPaperSize(); // Paper size $iPaperSize = $this->phpSheet->getPageSetup()->getPaperSize(); // Paper size
$iScale = $this->phpSheet->getPageSetup()->getScale() ?: 100; // Print scaling factor
$iScale = $this->phpSheet->getPageSetup()->getScale() ?
$this->phpSheet->getPageSetup()->getScale() : 100; // Print scaling factor
$iPageStart = 0x01; // Starting page number $iPageStart = 0x01; // Starting page number
$iFitWidth = (int) $this->phpSheet->getPageSetup()->getFitToWidth(); // Fit to number of pages wide $iFitWidth = (int) $this->phpSheet->getPageSetup()->getFitToWidth(); // Fit to number of pages wide

View File

@ -57,11 +57,10 @@ class SubTotalTest extends TestCase
return require 'tests/data/Calculation/MathTrig/SUBTOTAL.php'; return require 'tests/data/Calculation/MathTrig/SUBTOTAL.php';
} }
protected function rowVisibility() protected function rowVisibility($data)
{ {
$data = [1 => false, 2 => true, 3 => false, 4 => true, 5 => false, 6 => false, 7 => false, 8 => true, 9 => false, 10 => true, 11 => true]; foreach ($data as $row => $visibility) {
foreach ($data as $k => $v) { yield $row => $visibility;
yield $k => $v;
} }
} }
@ -69,10 +68,11 @@ class SubTotalTest extends TestCase
* @dataProvider providerHiddenSUBTOTAL * @dataProvider providerHiddenSUBTOTAL
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $hiddenRows
*/ */
public function testHiddenSUBTOTAL($expectedResult, ...$args): void public function testHiddenSUBTOTAL($expectedResult, $hiddenRows, ...$args): void
{ {
$visibilityGenerator = $this->rowVisibility(); $visibilityGenerator = $this->rowVisibility($hiddenRows);
$rowDimension = $this->getMockBuilder(RowDimension::class) $rowDimension = $this->getMockBuilder(RowDimension::class)
->setMethods(['getVisible']) ->setMethods(['getVisible'])

View File

@ -25,9 +25,11 @@ class ColumnCellIterator2Test extends TestCase
$lastCoordinate = ''; $lastCoordinate = '';
$firstCoordinate = ''; $firstCoordinate = '';
foreach ($iterator as $cell) { foreach ($iterator as $cell) {
$lastCoordinate = $cell->getCoordinate(); if ($cell !== null) {
if (!$firstCoordinate) { $lastCoordinate = $cell->getCoordinate();
$firstCoordinate = $lastCoordinate; if (!$firstCoordinate) {
$firstCoordinate = $lastCoordinate;
}
} }
} }
self::assertEquals($expectedResultFirst, $firstCoordinate); self::assertEquals($expectedResultFirst, $firstCoordinate);

View File

@ -67,6 +67,22 @@ class ColumnIteratorTest extends TestCase
} }
} }
public function testIteratorResetStart(): void
{
$iterator = new ColumnIterator($this->mockWorksheet, 'B', 'D');
$iterator->resetStart('E');
$key = $iterator->key();
self::assertSame('E', $key);
$lastColumn = $iterator->key();
while ($iterator->valid() !== false) {
$iterator->next();
$lastColumn = $iterator->key();
}
self::assertSame('F', $lastColumn);
}
public function testSeekOutOfRange(): void public function testSeekOutOfRange(): void
{ {
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class); $this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
@ -81,4 +97,12 @@ class ColumnIteratorTest extends TestCase
$iterator->prev(); $iterator->prev();
self::assertFalse($iterator->valid()); self::assertFalse($iterator->valid());
} }
public function testResetStartOutOfRange(): void
{
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
$iterator = new ColumnIterator($this->mockWorksheet, 'B', 'D');
$iterator->resetStart('H');
}
} }

View File

@ -25,9 +25,11 @@ class RowCellIterator2Test extends TestCase
$lastCoordinate = ''; $lastCoordinate = '';
$firstCoordinate = ''; $firstCoordinate = '';
foreach ($iterator as $cell) { foreach ($iterator as $cell) {
$lastCoordinate = $cell->getCoordinate(); if ($cell !== null) {
if (!$firstCoordinate) { $lastCoordinate = $cell->getCoordinate();
$firstCoordinate = $lastCoordinate; if (!$firstCoordinate) {
$firstCoordinate = $lastCoordinate;
}
} }
} }
self::assertEquals($expectedResultFirst, $firstCoordinate); self::assertEquals($expectedResultFirst, $firstCoordinate);

View File

@ -65,6 +65,22 @@ class RowIteratorTest extends TestCase
} }
} }
public function testIteratorResetStart(): void
{
$iterator = new RowIterator($this->mockWorksheet, 2, 4);
$iterator->resetStart(5);
$key = $iterator->key();
self::assertSame(5, $key);
$lastRow = $iterator->key();
while ($iterator->valid() !== false) {
$iterator->next();
$lastRow = $iterator->key();
}
self::assertSame(6, $lastRow);
}
public function testSeekOutOfRange(): void public function testSeekOutOfRange(): void
{ {
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class); $this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
@ -79,4 +95,12 @@ class RowIteratorTest extends TestCase
$iterator->prev(); $iterator->prev();
self::assertFalse($iterator->valid()); self::assertFalse($iterator->valid());
} }
public function testResetStartOutOfRange(): void
{
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
$iterator = new RowIterator($this->mockWorksheet, 2, 4);
$iterator->resetStart(10);
}
} }

View File

@ -15,59 +15,85 @@ $baseTestData = [
12 => ['A' => 89], 12 => ['A' => 89],
]; ];
$hiddenRows = [
1 => false,
2 => true,
3 => false,
4 => true,
5 => false,
6 => false,
7 => false,
8 => true,
9 => false,
10 => true,
11 => true,
12 => false,
];
return [ return [
[ [
21, 21,
$hiddenRows,
101, 101,
$baseTestData, $baseTestData,
], ],
[ [
5, 5,
$hiddenRows,
102, 102,
$baseTestData, $baseTestData,
], ],
[ [
5, 5,
$hiddenRows,
103, 103,
$baseTestData, $baseTestData,
], ],
[ [
55, 55,
$hiddenRows,
104, 104,
$baseTestData, $baseTestData,
], ],
[ [
1, 1,
$hiddenRows,
105, 105,
$baseTestData, $baseTestData,
], ],
[ [
48620, 48620,
$hiddenRows,
106, 106,
$baseTestData, $baseTestData,
], ],
[ [
23.1840462387393, 23.1840462387393,
$hiddenRows,
107, 107,
$baseTestData, $baseTestData,
], ],
[ [
20.7364413533277, 20.7364413533277,
$hiddenRows,
108, 108,
$baseTestData, $baseTestData,
], ],
[ [
105, 105,
$hiddenRows,
109, 109,
$baseTestData, $baseTestData,
], ],
[ [
537.5, 537.5,
$hiddenRows,
110, 110,
$baseTestData, $baseTestData,
], ],
[ [
430, 430,
$hiddenRows,
111, 111,
$baseTestData, $baseTestData,
], ],