Code review changes
This commit is contained in:
1 parent
197fb9987a
commit
11d91e1740
20 files changed
+105
-59
No files matched your search
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\Common\Manager\Style;
|
||||
|
||||
use Box\Spout\Common\Entity\Style\Style;
|
||||
|
||||
class ManagedStyle
|
||||
{
|
||||
private $style;
|
||||
private $isUpdated;
|
||||
|
||||
public function __construct(Style $style, bool $isUpdated)
|
||||
{
|
||||
$this->style = $style;
|
||||
$this->isUpdated = $isUpdated;
|
||||
}
|
||||
|
||||
public function getStyle() : Style
|
||||
{
|
||||
return $this->style;
|
||||
}
|
||||
|
||||
public function isUpdated() : bool
|
||||
{
|
||||
return $this->isUpdated;
|
||||
}
|
||||
}
|
||||
@@ -50,9 +50,9 @@ class StyleManager implements StyleManagerInterface
|
||||
* Typically, set "wrap text" if a cell contains a new line.
|
||||
*
|
||||
* @param Cell $cell
|
||||
* @return Style|null The eventually updated style
|
||||
* @return ManagedStyle The eventually updated style
|
||||
*/
|
||||
public function applyExtraStylesIfNeeded(Cell $cell) : ?Style
|
||||
public function applyExtraStylesIfNeeded(Cell $cell) : ManagedStyle
|
||||
{
|
||||
return $this->applyWrapTextIfCellContainsNewLine($cell);
|
||||
}
|
||||
@@ -67,23 +67,19 @@ class StyleManager implements StyleManagerInterface
|
||||
* on the Windows version of Excel...
|
||||
*
|
||||
* @param Cell $cell The cell the style should be applied to
|
||||
* @return Style|null The eventually updated style
|
||||
* @return ManagedStyle The eventually updated style
|
||||
*/
|
||||
protected function applyWrapTextIfCellContainsNewLine(Cell $cell) : ?Style
|
||||
protected function applyWrapTextIfCellContainsNewLine(Cell $cell) : ManagedStyle
|
||||
{
|
||||
$cellStyle = $cell->getStyle();
|
||||
|
||||
// if the "wrap text" option is already set, no-op
|
||||
if ($cellStyle->hasSetWrapText()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($cell->isString() && \strpos($cell->getValue(), "\n") !== false) {
|
||||
if (!$cellStyle->hasSetWrapText() && $cell->isString() && \strpos($cell->getValue(), "\n") !== false) {
|
||||
$cellStyle->setShouldWrapText();
|
||||
|
||||
return $cellStyle;
|
||||
return new ManagedStyle($cellStyle, true);
|
||||
}
|
||||
|
||||
return null;
|
||||
return new ManagedStyle($cellStyle, false);
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ interface StyleManagerInterface
|
||||
* Typically, set "wrap text" if a cell contains a new line.
|
||||
*
|
||||
* @param Cell $cell
|
||||
* @return Style|null The eventually updated style
|
||||
* @return ManagedStyle|null The eventually updated style
|
||||
*/
|
||||
public function applyExtraStylesIfNeeded(Cell $cell) : ?Style;
|
||||
public function applyExtraStylesIfNeeded(Cell $cell) : ManagedStyle;
|
||||
}
|
||||
@@ -114,8 +114,7 @@ class StyleRegistry
|
||||
{
|
||||
// In order to be able to properly compare style, set static ID value and reset registration
|
||||
$currentId = $style->getId();
|
||||
$style->setId(0);
|
||||
$style->setRegistered(false);
|
||||
$style->unregister();
|
||||
|
||||
$serializedStyle = \serialize($style);
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Box\Spout\Writer\ODS\Manager;
|
||||
|
||||
use Box\Spout\Common\Entity\Cell;
|
||||
use Box\Spout\Common\Entity\Row;
|
||||
use Box\Spout\Common\Entity\Style\EmptyStyle;
|
||||
use Box\Spout\Common\Entity\Style\Style;
|
||||
use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
@@ -158,13 +157,13 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
*/
|
||||
private function applyStyleAndGetCellXML(Cell $cell, Style &$rowStyle, $currentCellIndex, $nextCellIndex)
|
||||
{
|
||||
if ($cell->getStyle() instanceof EmptyStyle) {
|
||||
if ($cell->getStyle()->isEmpty()) {
|
||||
$cell->setStyle($rowStyle);
|
||||
|
||||
$extraStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
||||
$managedStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
||||
|
||||
if ($extraStyle) {
|
||||
$registeredStyle = $this->styleManager->registerStyle($extraStyle);
|
||||
if ($managedStyle->isUpdated()) {
|
||||
$registeredStyle = $this->styleManager->registerStyle($managedStyle->getStyle());
|
||||
} else {
|
||||
$registeredStyle = $rowStyle = $this->styleManager->registerStyle($rowStyle);
|
||||
}
|
||||
@@ -172,7 +171,13 @@ class WorksheetManager implements WorksheetManagerInterface
|
||||
$mergedCellAndRowStyle = $this->styleMerger->merge($cell->getStyle(), $rowStyle);
|
||||
$cell->setStyle($mergedCellAndRowStyle);
|
||||
|
||||
$newCellStyle = $this->styleManager->applyExtraStylesIfNeeded($cell) ?: $mergedCellAndRowStyle;
|
||||
$managedStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
||||
if ($managedStyle->isUpdated()) {
|
||||
$newCellStyle = $managedStyle->getStyle();
|
||||
} else {
|
||||
$newCellStyle = $mergedCellAndRowStyle;
|
||||
}
|
||||
|
||||
$registeredStyle = $this->styleManager->registerStyle($newCellStyle);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Box\Spout\Writer\XLSX\Manager;
|
||||
|
||||
use Box\Spout\Common\Entity\Cell;
|
||||
use Box\Spout\Common\Entity\Row;
|
||||
use Box\Spout\Common\Entity\Style\EmptyStyle;
|
||||
use Box\Spout\Common\Entity\Style\Style;
|
||||
use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
@@ -186,13 +185,13 @@ EOD;
|
||||
*/
|
||||
private function applyStyleAndGetCellXML(Cell $cell, Style &$rowStyle, $rowIndexOneBased, $columnIndexZeroBased)
|
||||
{
|
||||
if ($cell->getStyle() instanceof EmptyStyle) {
|
||||
if ($cell->getStyle()->isEmpty()) {
|
||||
$cell->setStyle($rowStyle);
|
||||
|
||||
$extraStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
||||
$managedStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
||||
|
||||
if ($extraStyle) {
|
||||
$registeredStyle = $this->styleManager->registerStyle($extraStyle);
|
||||
if ($managedStyle->isUpdated()) {
|
||||
$registeredStyle = $this->styleManager->registerStyle($managedStyle->getStyle());
|
||||
} else {
|
||||
$registeredStyle = $rowStyle = $this->styleManager->registerStyle($rowStyle);
|
||||
}
|
||||
@@ -200,7 +199,14 @@ EOD;
|
||||
$mergedCellAndRowStyle = $this->styleMerger->merge($cell->getStyle(), $rowStyle);
|
||||
$cell->setStyle($mergedCellAndRowStyle);
|
||||
|
||||
$newCellStyle = $this->styleManager->applyExtraStylesIfNeeded($cell) ?: $mergedCellAndRowStyle;
|
||||
$managedStyle = $this->styleManager->applyExtraStylesIfNeeded($cell);
|
||||
|
||||
if ($managedStyle->isUpdated()) {
|
||||
$newCellStyle = $managedStyle->getStyle();
|
||||
} else {
|
||||
$newCellStyle = $mergedCellAndRowStyle;
|
||||
}
|
||||
|
||||
$registeredStyle = $this->styleManager->registerStyle($newCellStyle);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user