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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user