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).
This commit is contained in:
oleibman
2025-01-27 21:50:05 -08:00
parent 414f8a2aa1
commit dd8fee52ac
2 changed files with 15 additions and 23 deletions
+4 -21
View File
@@ -63,7 +63,7 @@ class Worksheet
/**
* Invalid characters in sheet title.
*/
private static array $invalidCharacters = ['*', ':', '/', '\\', '?', '[', ']'];
private const INVALID_CHARACTERS = ['*', ':', '/', '\\', '?', '[', ']'];
/**
* Parent spreadsheet.
@@ -157,13 +157,6 @@ class Worksheet
*/
private Protection $protection;
/**
* Collection of styles.
*
* @var Style[]
*/
private array $styles = [];
/**
* Conditional styles. Indexed by cell coordinate, e.g. 'A1'.
*/
@@ -399,7 +392,7 @@ class Worksheet
*/
public static function getInvalidCharacters(): array
{
return self::$invalidCharacters;
return self::INVALID_CHARACTERS;
}
/**
@@ -417,7 +410,7 @@ class Worksheet
}
// Some of the printable ASCII characters are invalid: * : / \ ? [ ] and first and last characters cannot be a "'"
if (
(str_replace(self::$invalidCharacters, '', $sheetCodeName) !== $sheetCodeName)
(str_replace(self::INVALID_CHARACTERS, '', $sheetCodeName) !== $sheetCodeName)
|| (Shared\StringHelper::substring($sheetCodeName, -1, 1) == '\'')
|| (Shared\StringHelper::substring($sheetCodeName, 0, 1) == '\'')
) {
@@ -442,7 +435,7 @@ class Worksheet
private static function checkSheetTitle(string $sheetTitle): string
{
// Some of the printable ASCII characters are invalid: * : / \ ? [ ]
if (str_replace(self::$invalidCharacters, '', $sheetTitle) !== $sheetTitle) {
if (str_replace(self::INVALID_CHARACTERS, '', $sheetTitle) !== $sheetTitle) {
throw new Exception('Invalid character found in sheet title');
}
@@ -1392,16 +1385,6 @@ class Worksheet
);
}
/**
* Get styles.
*
* @return Style[]
*/
public function getStyles(): array
{
return $this->styles;
}
/**
* Get style for cell.
*
@@ -16,9 +16,18 @@ class Worksheet2Test extends TestCase
$invalid = Worksheet::getInvalidCharacters();
self::assertSame(['*', ':', '/', '\\', '?', '[', ']'], $invalid);
$worksheet = new Worksheet();
self::assertEmpty($worksheet->getStyles());
$coord1 = $worksheet->getCoordinates();
self::assertSame([], $coord1);
$worksheet->getCell('B3')->setValue(1);
$worksheet->getCell('G2')->setValue(2);
$coord2 = $worksheet->getCoordinates(false); // in order added
self::assertSame(['B3', 'G2'], $coord2);
$coord3 = $worksheet->getCoordinates(); // sorted by row then column
self::assertSame(['G2', 'B3'], $coord3);
$worksheet = new Worksheet();
$worksheet->disconnectCells();
self::assertSame([], $worksheet->getCoordinates());
$coord4 = $worksheet->getCoordinates();
self::assertSame([], $coord4);
}
public function testHighestColumn(): void