New code review fixs

This commit is contained in:
Antoine Lamirault 2021-03-05 14:12:20 +01:00 committed by Adrien Loison
parent 11d91e1740
commit c6f596c776
5 changed files with 10 additions and 21 deletions

View File

@ -490,13 +490,13 @@ class Style
return $this->isRegistered; return $this->isRegistered;
} }
public function register(int $id) : void public function markAsRegistered(?int $id) : void
{ {
$this->setId($id); $this->setId($id);
$this->isRegistered = true; $this->isRegistered = true;
} }
public function unregister() : void public function unmarkAsRegistered() : void
{ {
$this->setId(0); $this->setId(0);
$this->isRegistered = false; $this->isRegistered = false;

View File

@ -24,7 +24,7 @@ interface StyleManagerInterface
* Typically, set "wrap text" if a cell contains a new line. * Typically, set "wrap text" if a cell contains a new line.
* *
* @param Cell $cell * @param Cell $cell
* @return ManagedStyle|null The eventually updated style * @return ManagedStyle The eventually updated style
*/ */
public function applyExtraStylesIfNeeded(Cell $cell) : ManagedStyle; public function applyExtraStylesIfNeeded(Cell $cell) : ManagedStyle;
} }

View File

@ -38,7 +38,7 @@ class StyleRegistry
if (!$this->hasSerializedStyleAlreadyBeenRegistered($serializedStyle)) { if (!$this->hasSerializedStyleAlreadyBeenRegistered($serializedStyle)) {
$nextStyleId = \count($this->serializedStyleToStyleIdMappingTable); $nextStyleId = \count($this->serializedStyleToStyleIdMappingTable);
$style->register($nextStyleId); $style->markAsRegistered($nextStyleId);
$this->serializedStyleToStyleIdMappingTable[$serializedStyle] = $nextStyleId; $this->serializedStyleToStyleIdMappingTable[$serializedStyle] = $nextStyleId;
$this->styleIdToStyleMappingTable[$nextStyleId] = $style; $this->styleIdToStyleMappingTable[$nextStyleId] = $style;
@ -47,19 +47,6 @@ class StyleRegistry
return $this->getStyleFromSerializedStyle($serializedStyle); return $this->getStyleFromSerializedStyle($serializedStyle);
} }
/**
* Returns whether the given style has already been registered.
*
* @param Style $style
* @return bool
*/
protected function hasStyleAlreadyBeenRegistered(Style $style)
{
$serializedStyle = $this->serialize($style);
return $this->hasSerializedStyleAlreadyBeenRegistered($serializedStyle);
}
/** /**
* Returns whether the serialized style has already been registered. * Returns whether the serialized style has already been registered.
* *
@ -114,11 +101,11 @@ class StyleRegistry
{ {
// In order to be able to properly compare style, set static ID value and reset registration // In order to be able to properly compare style, set static ID value and reset registration
$currentId = $style->getId(); $currentId = $style->getId();
$style->unregister(); $style->unmarkAsRegistered();
$serializedStyle = \serialize($style); $serializedStyle = \serialize($style);
$style->setId($currentId); $style->markAsRegistered($currentId);
return $serializedStyle; return $serializedStyle;
} }

View File

@ -165,7 +165,8 @@ class WorksheetManager implements WorksheetManagerInterface
if ($managedStyle->isUpdated()) { if ($managedStyle->isUpdated()) {
$registeredStyle = $this->styleManager->registerStyle($managedStyle->getStyle()); $registeredStyle = $this->styleManager->registerStyle($managedStyle->getStyle());
} else { } else {
$registeredStyle = $rowStyle = $this->styleManager->registerStyle($rowStyle); $registeredStyle = $this->styleManager->registerStyle($rowStyle);
$rowStyle = $registeredStyle;
} }
} else { } else {
$mergedCellAndRowStyle = $this->styleMerger->merge($cell->getStyle(), $rowStyle); $mergedCellAndRowStyle = $this->styleMerger->merge($cell->getStyle(), $rowStyle);

View File

@ -193,7 +193,8 @@ EOD;
if ($managedStyle->isUpdated()) { if ($managedStyle->isUpdated()) {
$registeredStyle = $this->styleManager->registerStyle($managedStyle->getStyle()); $registeredStyle = $this->styleManager->registerStyle($managedStyle->getStyle());
} else { } else {
$registeredStyle = $rowStyle = $this->styleManager->registerStyle($rowStyle); $registeredStyle = $this->styleManager->registerStyle($rowStyle);
$rowStyle = $registeredStyle;
} }
} else { } else {
$mergedCellAndRowStyle = $this->styleMerger->merge($cell->getStyle(), $rowStyle); $mergedCellAndRowStyle = $this->styleMerger->merge($cell->getStyle(), $rowStyle);