diff --git a/src/PhpSpreadsheet/Worksheet/Worksheet.php b/src/PhpSpreadsheet/Worksheet/Worksheet.php index 7dde970f78..59f3ac266a 100644 --- a/src/PhpSpreadsheet/Worksheet/Worksheet.php +++ b/src/PhpSpreadsheet/Worksheet/Worksheet.php @@ -3,33 +3,33 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; use ArrayObject; -use PhpOffice\PhpSpreadsheet\Shared; -use PhpOffice\PhpSpreadsheet\Comment; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Cell\AddressRange; use PhpOffice\PhpSpreadsheet\Cell\Cell; -use PhpOffice\PhpSpreadsheet\Exception; +use PhpOffice\PhpSpreadsheet\Cell\CellAddress; +use PhpOffice\PhpSpreadsheet\Cell\Coordinate; +use PhpOffice\PhpSpreadsheet\Cell\DataType; +use PhpOffice\PhpSpreadsheet\Cell\DataValidation; +use PhpOffice\PhpSpreadsheet\Cell\Hyperlink; +use PhpOffice\PhpSpreadsheet\Cell\IValueBinder; use PhpOffice\PhpSpreadsheet\Chart\Chart; +use PhpOffice\PhpSpreadsheet\Collection\Cells; +use PhpOffice\PhpSpreadsheet\Collection\CellsFactory; +use PhpOffice\PhpSpreadsheet\Comment; use PhpOffice\PhpSpreadsheet\DefinedName; +use PhpOffice\PhpSpreadsheet\Exception; use PhpOffice\PhpSpreadsheet\IComparable; -use PhpOffice\PhpSpreadsheet\Spreadsheet; -use PhpOffice\PhpSpreadsheet\Style\Color; -use PhpOffice\PhpSpreadsheet\Style\Style; -use PhpOffice\PhpSpreadsheet\Cell\DataType; -use PhpOffice\PhpSpreadsheet\Cell\Hyperlink; -use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\ReferenceHelper; -use PhpOffice\PhpSpreadsheet\Style\Alignment; -use PhpOffice\PhpSpreadsheet\Cell\CellAddress; -use PhpOffice\PhpSpreadsheet\Collection\Cells; -use PhpOffice\PhpSpreadsheet\Cell\AddressRange; -use PhpOffice\PhpSpreadsheet\Cell\IValueBinder; use PhpOffice\PhpSpreadsheet\RichText\RichText; +use PhpOffice\PhpSpreadsheet\Shared; +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Style\Alignment; +use PhpOffice\PhpSpreadsheet\Style\Color; use PhpOffice\PhpSpreadsheet\Style\Conditional; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; -use PhpOffice\PhpSpreadsheet\Cell\DataValidation; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\Calculation; -use PhpOffice\PhpSpreadsheet\Collection\CellsFactory; use PhpOffice\PhpSpreadsheet\Style\Protection as StyleProtection; +use PhpOffice\PhpSpreadsheet\Style\Style; class Worksheet implements IComparable { @@ -3641,7 +3641,8 @@ public function repeatSourceRange(string $sourceRange, int $repetitions = 2, int // Copy the cells and merge them in the new locations $groupCount = 0; $rowOffset = 0; - for ($i = 1; $i <= $repetitions + 1; $i++) { + + for ($i = 1; $i <= $repetitions + 1; ++$i) { if ($i % $groupSize != 1 && $i > $groupSize) { $offset = ($i - 1) % $groupSize * ($sourceEndColumnIndex - $sourceStartColumnIndex + 1); } else { @@ -3682,7 +3683,8 @@ public function repeatSourceRange(string $sourceRange, int $repetitions = 2, int // Increase group count and row offset after every groupSize repetitions if ($i % $groupSize == 0) { $rowOffset += $sourceEnd[1] - $sourceStart[1] + 2; // 2 is the number of rows to skip - $groupCount++; + + ++$groupCount; } } } diff --git a/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php b/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php index fdcd0a6711..578fc83ae1 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php @@ -651,13 +651,13 @@ public function testRepeatSourceRangeBasic(): void $worksheet->repeatSourceRange($sourceRange, $repetitions, $groupSize); // Assert that cells are copied correctly - $this->assertEquals('Test1', $worksheet->getCell('A1')->getValue()); - $this->assertEquals('Test3', $worksheet->getCell('A2')->getValue()); - $this->assertEquals('Test5', $worksheet->getCell('A3')->getValue()); + self::assertEquals('Test1', $worksheet->getCell('A1')->getValue()); + self::assertEquals('Test3', $worksheet->getCell('A2')->getValue()); + self::assertEquals('Test5', $worksheet->getCell('A3')->getValue()); // Assert that merged cells are copied correctly - $this->assertContains('A1:B1', $worksheet->getMergeCells()); - $this->assertContains('A2:B2', $worksheet->getMergeCells()); - $this->assertContains('A3:B3', $worksheet->getMergeCells()); + self::assertContains('A1:B1', $worksheet->getMergeCells()); + self::assertContains('A2:B2', $worksheet->getMergeCells()); + self::assertContains('A3:B3', $worksheet->getMergeCells()); } }