Skip to content

Commit dd8fee5

Browse files
committed
Remove Styles Property From Worksheet
Styles are a property of Spreadsheet, not Worksheet. There is a Styles property in Worksheet, initially set to an empty array and *never* updated. This PR removes the property and the getStyles method of Worksheet. This is, technically, a breaking change, so it will be installed with PhpSpreadsheet V4 (PR #4240).
1 parent 414f8a2 commit dd8fee5

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

src/PhpSpreadsheet/Worksheet/Worksheet.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Worksheet
6363
/**
6464
* Invalid characters in sheet title.
6565
*/
66-
private static array $invalidCharacters = ['*', ':', '/', '\\', '?', '[', ']'];
66+
private const INVALID_CHARACTERS = ['*', ':', '/', '\\', '?', '[', ']'];
6767

6868
/**
6969
* Parent spreadsheet.
@@ -157,13 +157,6 @@ class Worksheet
157157
*/
158158
private Protection $protection;
159159

160-
/**
161-
* Collection of styles.
162-
*
163-
* @var Style[]
164-
*/
165-
private array $styles = [];
166-
167160
/**
168161
* Conditional styles. Indexed by cell coordinate, e.g. 'A1'.
169162
*/
@@ -399,7 +392,7 @@ public function getCellCollection(): Cells
399392
*/
400393
public static function getInvalidCharacters(): array
401394
{
402-
return self::$invalidCharacters;
395+
return self::INVALID_CHARACTERS;
403396
}
404397

405398
/**
@@ -417,7 +410,7 @@ private static function checkSheetCodeName(string $sheetCodeName): string
417410
}
418411
// Some of the printable ASCII characters are invalid: * : / \ ? [ ] and first and last characters cannot be a "'"
419412
if (
420-
(str_replace(self::$invalidCharacters, '', $sheetCodeName) !== $sheetCodeName)
413+
(str_replace(self::INVALID_CHARACTERS, '', $sheetCodeName) !== $sheetCodeName)
421414
|| (Shared\StringHelper::substring($sheetCodeName, -1, 1) == '\'')
422415
|| (Shared\StringHelper::substring($sheetCodeName, 0, 1) == '\'')
423416
) {
@@ -442,7 +435,7 @@ private static function checkSheetCodeName(string $sheetCodeName): string
442435
private static function checkSheetTitle(string $sheetTitle): string
443436
{
444437
// Some of the printable ASCII characters are invalid: * : / \ ? [ ]
445-
if (str_replace(self::$invalidCharacters, '', $sheetTitle) !== $sheetTitle) {
438+
if (str_replace(self::INVALID_CHARACTERS, '', $sheetTitle) !== $sheetTitle) {
446439
throw new Exception('Invalid character found in sheet title');
447440
}
448441

@@ -1392,16 +1385,6 @@ public function getColumnStyle(string $column): ?Style
13921385
);
13931386
}
13941387

1395-
/**
1396-
* Get styles.
1397-
*
1398-
* @return Style[]
1399-
*/
1400-
public function getStyles(): array
1401-
{
1402-
return $this->styles;
1403-
}
1404-
14051388
/**
14061389
* Get style for cell.
14071390
*

tests/PhpSpreadsheetTests/Worksheet/Worksheet2Test.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@ public function testMiscellaneous(): void
1616
$invalid = Worksheet::getInvalidCharacters();
1717
self::assertSame(['*', ':', '/', '\\', '?', '[', ']'], $invalid);
1818
$worksheet = new Worksheet();
19-
self::assertEmpty($worksheet->getStyles());
19+
$coord1 = $worksheet->getCoordinates();
20+
self::assertSame([], $coord1);
21+
$worksheet->getCell('B3')->setValue(1);
22+
$worksheet->getCell('G2')->setValue(2);
23+
$coord2 = $worksheet->getCoordinates(false); // in order added
24+
self::assertSame(['B3', 'G2'], $coord2);
25+
$coord3 = $worksheet->getCoordinates(); // sorted by row then column
26+
self::assertSame(['G2', 'B3'], $coord3);
27+
$worksheet = new Worksheet();
2028
$worksheet->disconnectCells();
21-
self::assertSame([], $worksheet->getCoordinates());
29+
$coord4 = $worksheet->getCoordinates();
30+
self::assertSame([], $coord4);
2231
}
2332

2433
public function testHighestColumn(): void

0 commit comments

Comments
 (0)