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);
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
$guess = Functions::flattenSingleValue($guess);
$x1 = 0.0;
$x2 = $guess ? $guess : 0.1;
$x2 = $guess ?: 0.1;
$f1 = self::xnpvOrdered($x1, $values, $dates, false);
$f2 = self::xnpvOrdered($x2, $values, $dates, false);
$found = false;

View File

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

View File

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

View File

@ -291,9 +291,9 @@ class GridLines extends Properties
$this->activateObject()
->setShadowPresetsProperties((int) $sh_presets)
->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_type === null ? $this->shadowProperties['color']['type'] : $sh_color_type
$sh_color_type ?? $this->shadowProperties['color']['type']
)
->setShadowBlur($sh_blur)
->setShadowAngle($sh_angle)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -421,7 +421,7 @@ class Xml extends BaseReader
$xml_ss = $xml->children($namespaces['ss']);
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']);
if (
@ -665,7 +665,7 @@ class Xml extends BaseReader
foreach ($xml->Styles[0] as $style) {
$style_ss = self::getAttributes($style, $namespaces['ss']);
$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) {
$styleData = $styleDatax ?? new SimpleXMLElement('<xml></xml>');
$styleAttributes = $styleData->attributes($namespaces['ss']);

View File

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

View File

@ -30,10 +30,8 @@ abstract class CellIterator implements Iterator
/**
* Get loop only existing cells.
*
* @return bool
*/
public function getIterateOnlyExistingCells()
public function getIterateOnlyExistingCells(): bool
{
return $this->onlyExistingCells;
}
@ -45,10 +43,8 @@ abstract class CellIterator implements Iterator
/**
* 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;

View File

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

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
@ -59,7 +60,7 @@ class ColumnCellIterator extends CellIterator
*
* @return $this
*/
public function resetStart($startRow = 1)
public function resetStart(int $startRow = 1)
{
$this->startRow = $startRow;
$this->adjustForExistingOnlyRange();
@ -77,7 +78,7 @@ class ColumnCellIterator extends CellIterator
*/
public function resetEnd($endRow = null)
{
$this->endRow = ($endRow) ? $endRow : $this->worksheet->getHighestRow();
$this->endRow = $endRow ?: $this->worksheet->getHighestRow();
$this->adjustForExistingOnlyRange();
return $this;
@ -90,7 +91,7 @@ class ColumnCellIterator extends CellIterator
*
* @return $this
*/
public function seek($row = 1)
public function seek(int $row = 1)
{
if ($this->onlyExistingCells && !($this->worksheet->cellExistsByColumnAndRow($this->columnIndex, $row))) {
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 \PhpOffice\PhpSpreadsheet\Cell\Cell
*/
public function current()
public function current(): ?Cell
{
return $this->worksheet->getCellByColumnAndRow($this->columnIndex, $this->currentRow);
}
/**
* Return the current iterator key.
*
* @return int
*/
public function key()
public function key(): int
{
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.
*
* @return bool
*/
public function valid()
public function valid(): bool
{
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'.
*
* @return string
*/
public function getColumnIndex()
public function getColumnIndex(): string
{
return $this->columnIndex;
}
@ -54,23 +52,19 @@ class ColumnDimension extends Dimension
/**
* Set column index as string eg: 'A'.
*
* @param string $pValue
*
* @return $this
*/
public function setColumnIndex($pValue)
public function setColumnIndex(string $index)
{
$this->columnIndex = $pValue;
$this->columnIndex = $index;
return $this;
}
/**
* Get Width.
*
* @return float
*/
public function getWidth()
public function getWidth(): float
{
return $this->width;
}
@ -78,23 +72,19 @@ class ColumnDimension extends Dimension
/**
* Set Width.
*
* @param float $pValue
*
* @return $this
*/
public function setWidth($pValue)
public function setWidth(float $width)
{
$this->width = $pValue;
$this->width = $width;
return $this;
}
/**
* Get Auto Size.
*
* @return bool
*/
public function getAutoSize()
public function getAutoSize(): bool
{
return $this->autoSize;
}
@ -102,13 +92,11 @@ class ColumnDimension extends Dimension
/**
* Set Auto Size.
*
* @param bool $pValue
*
* @return $this
*/
public function setAutoSize($pValue)
public function setAutoSize(bool $autosizeEnabled)
{
$this->autoSize = $pValue;
$this->autoSize = $autosizeEnabled;
return $this;
}

View File

@ -67,11 +67,13 @@ class ColumnIterator implements Iterator
*
* @return $this
*/
public function resetStart($startColumn = 'A')
public function resetStart(string $startColumn = 'A')
{
$startColumnIndex = Coordinate::columnIndexFromString($startColumn);
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;
@ -92,7 +94,7 @@ class ColumnIterator implements Iterator
*/
public function resetEnd($endColumn = null)
{
$endColumn = $endColumn ? $endColumn : $this->worksheet->getHighestColumn();
$endColumn = $endColumn ?: $this->worksheet->getHighestColumn();
$this->endColumnIndex = Coordinate::columnIndexFromString($endColumn);
return $this;
@ -105,11 +107,13 @@ class ColumnIterator implements Iterator
*
* @return $this
*/
public function seek($column = 'A')
public function seek(string $column = 'A')
{
$column = Coordinate::columnIndexFromString($column);
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;
@ -136,10 +140,8 @@ class ColumnIterator implements Iterator
/**
* Return the current iterator key.
*
* @return string
*/
public function key()
public function key(): string
{
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.
*
* @return bool
*/
public function valid()
public function valid(): bool
{
return $this->currentColumnIndex <= $this->endColumnIndex && $this->currentColumnIndex >= $this->startColumnIndex;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -65,10 +65,12 @@ class RowIterator implements Iterator
*
* @return $this
*/
public function resetStart($startRow = 1)
public function resetStart(int $startRow = 1)
{
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;
@ -89,7 +91,7 @@ class RowIterator implements Iterator
*/
public function resetEnd($endRow = null)
{
$this->endRow = ($endRow) ? $endRow : $this->subject->getHighestRow();
$this->endRow = $endRow ?: $this->subject->getHighestRow();
return $this;
}
@ -101,7 +103,7 @@ class RowIterator implements Iterator
*
* @return $this
*/
public function seek($row = 1)
public function seek(int $row = 1)
{
if (($row < $this->startRow) || ($row > $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 int
*/
public function key()
public function key(): int
{
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.
*
* @return bool
*/
public function valid()
public function valid(): bool
{
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
$iPaperSize = $this->phpSheet->getPageSetup()->getPaperSize(); // Paper size
$iScale = $this->phpSheet->getPageSetup()->getScale() ?
$this->phpSheet->getPageSetup()->getScale() : 100; // Print scaling factor
$iScale = $this->phpSheet->getPageSetup()->getScale() ?: 100; // Print scaling factor
$iPageStart = 0x01; // Starting page number
$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';
}
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 $k => $v) {
yield $k => $v;
foreach ($data as $row => $visibility) {
yield $row => $visibility;
}
}
@ -69,10 +68,11 @@ class SubTotalTest extends TestCase
* @dataProvider providerHiddenSUBTOTAL
*
* @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)
->setMethods(['getVisible'])

View File

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

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
{
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
@ -81,4 +97,12 @@ class ColumnIteratorTest extends TestCase
$iterator->prev();
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,11 +25,13 @@ class RowCellIterator2Test extends TestCase
$lastCoordinate = '';
$firstCoordinate = '';
foreach ($iterator as $cell) {
if ($cell !== null) {
$lastCoordinate = $cell->getCoordinate();
if (!$firstCoordinate) {
$firstCoordinate = $lastCoordinate;
}
}
}
self::assertEquals($expectedResultFirst, $firstCoordinate);
self::assertEquals($expectedResultLast, $lastCoordinate);
}

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
{
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
@ -79,4 +95,12 @@ class RowIteratorTest extends TestCase
$iterator->prev();
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],
];
$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 [
[
21,
$hiddenRows,
101,
$baseTestData,
],
[
5,
$hiddenRows,
102,
$baseTestData,
],
[
5,
$hiddenRows,
103,
$baseTestData,
],
[
55,
$hiddenRows,
104,
$baseTestData,
],
[
1,
$hiddenRows,
105,
$baseTestData,
],
[
48620,
$hiddenRows,
106,
$baseTestData,
],
[
23.1840462387393,
$hiddenRows,
107,
$baseTestData,
],
[
20.7364413533277,
$hiddenRows,
108,
$baseTestData,
],
[
105,
$hiddenRows,
109,
$baseTestData,
],
[
537.5,
$hiddenRows,
110,
$baseTestData,
],
[
430,
$hiddenRows,
111,
$baseTestData,
],