Skip to content

Commit ca12ffd

Browse files
authored
refactor: using function count instead
1 parent ea6ed77 commit ca12ffd

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/PhpSpreadsheet/Spreadsheet.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ public function addSheet(Worksheet $worksheet, ?int $sheetIndex = null, bool $re
608608
*/
609609
public function removeSheetByIndex(int $sheetIndex): void
610610
{
611-
$numSheets = count($this->workSheetCollection);
611+
$numSheets = $this->getSheetCount();
612612
if ($sheetIndex > $numSheets - 1) {
613613
throw new Exception(
614614
"You tried to remove a sheet by the out of bounds index: {$sheetIndex}. The actual number of sheets is {$numSheets}."
@@ -660,10 +660,9 @@ public function getAllSheets(): array
660660
*/
661661
public function getSheetByName(string $worksheetName): ?Worksheet
662662
{
663-
$worksheetCount = count($this->workSheetCollection);
664663
$trimWorksheetName = trim($worksheetName, "'");
665664

666-
for ($i = 0; $i < $worksheetCount; ++$i) {
665+
for ($i = 0; $i < $this->getSheetCount(); ++$i) {
667666
if (strcasecmp($this->workSheetCollection[$i]->getTitle(), $trimWorksheetName) === 0) {
668667
return $this->workSheetCollection[$i];
669668
}
@@ -792,8 +791,8 @@ public function setActiveSheetIndexByName(string $worksheetName): Worksheet
792791
public function getSheetNames(): array
793792
{
794793
$returnValue = [];
795-
$worksheetCount = $this->getSheetCount();
796-
for ($i = 0; $i < $worksheetCount; ++$i) {
794+
795+
for ($i = 0; $i < $this->getSheetCount(); ++$i) {
797796
$returnValue[] = $this->getSheet($i)->getTitle();
798797
}
799798

0 commit comments

Comments
 (0)