From e8c6d831047d4bba69b2e5c05b1e271141f2f171 Mon Sep 17 00:00:00 2001 From: Alexander Rakushin Date: Wed, 10 Jul 2019 20:52:27 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81ode=20formatting=20(CS=20Fixer)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Spout/Common/Entity/Style/Style.php | 3 +-- src/Spout/Writer/Common/Creator/Style/StyleBuilder.php | 4 +++- src/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php | 9 ++------- tests/Spout/Writer/XLSX/WriterWithStyleTest.php | 4 ---- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Spout/Common/Entity/Style/Style.php b/src/Spout/Common/Entity/Style/Style.php index ab9ec8e..0b5c0d7 100644 --- a/src/Spout/Common/Entity/Style/Style.php +++ b/src/Spout/Common/Entity/Style/Style.php @@ -72,7 +72,7 @@ class Style private $hasSetBackgroundColor = false; /** @var string Format */ - private $format = null; + private $format; /** @var bool */ private $hasSetFormat = false; @@ -412,7 +412,6 @@ class Style } /** - * * @return bool Whether format should be applied */ public function shouldApplyFormat() diff --git a/src/Spout/Writer/Common/Creator/Style/StyleBuilder.php b/src/Spout/Writer/Common/Creator/Style/StyleBuilder.php index ffe4814..65792eb 100644 --- a/src/Spout/Writer/Common/Creator/Style/StyleBuilder.php +++ b/src/Spout/Writer/Common/Creator/Style/StyleBuilder.php @@ -147,16 +147,18 @@ class StyleBuilder return $this; } + /** * Sets a format * - * @api * @param string $format Format * @return StyleBuilder + * @api */ public function setFormat($format) { $this->style->setFormat($format); + return $this; } diff --git a/src/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php b/src/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php index ae47cd7..585dd58 100644 --- a/src/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php +++ b/src/Spout/Writer/XLSX/Manager/Style/StyleRegistry.php @@ -15,7 +15,6 @@ class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry * @var array Mapping between built-in format and the associated numFmtId */ protected static $builtinNumFormatToIdMapping = [ - 'General' => 0, '0' => 1, '0.00' => 2, @@ -65,7 +64,6 @@ class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry 't# ??/??' => 70, ]; - /** * @var array */ @@ -123,7 +121,7 @@ class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry { $registeredStyle = parent::registerStyle($style); $this->registerFill($registeredStyle); - $this->registerFormat($registeredStyle);; + $this->registerFormat($registeredStyle); $this->registerBorder($registeredStyle); return $registeredStyle; @@ -149,6 +147,7 @@ class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry $this->styleIdToFormatsMappingTable[$styleId] = $registeredFormatId; } else { $this->registeredFormats[$format] = $styleId; + if (isset(self::$builtinNumFormatToIdMapping[$format])) { $id = self::$builtinNumFormatToIdMapping[$format]; } else { @@ -156,7 +155,6 @@ class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry } $this->styleIdToFormatsMappingTable[$styleId] = $id; } - } else { // The formatId maps a style to a format declaration // When there is no format definition - we default to 0 ( General ) @@ -258,7 +256,6 @@ class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry null; } - /** * @return array */ @@ -275,7 +272,6 @@ class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry return $this->registeredBorders; } - /** * @return array */ @@ -283,5 +279,4 @@ class StyleRegistry extends \Box\Spout\Writer\Common\Manager\Style\StyleRegistry { return $this->registeredFormats; } - } diff --git a/tests/Spout/Writer/XLSX/WriterWithStyleTest.php b/tests/Spout/Writer/XLSX/WriterWithStyleTest.php index a724e2b..83d2555 100644 --- a/tests/Spout/Writer/XLSX/WriterWithStyleTest.php +++ b/tests/Spout/Writer/XLSX/WriterWithStyleTest.php @@ -225,7 +225,6 @@ class WriterWithStyleTest extends TestCase ->setFormat('0.000') ->build(); - $dataRows = [ $this->createStyledRowFromValues([1.123456789], $style), $this->createStyledRowFromValues([12.1], $style2), @@ -233,7 +232,6 @@ class WriterWithStyleTest extends TestCase $this->writeToXLSXFile($dataRows, $fileName); - $formatsDomElement = $this->getXmlSectionFromStylesXmlFile($fileName, 'numFmts'); $this->assertEquals( 1, @@ -241,13 +239,11 @@ class WriterWithStyleTest extends TestCase 'There should be 2 formats, including the 1 default ones' ); - $cellXfsDomElement = $this->getXmlSectionFromStylesXmlFile($fileName, 'cellXfs'); foreach ([2, 164] as $index => $expected) { $xfElement = $cellXfsDomElement->getElementsByTagName('xf')->item($index + 1); $this->assertEquals($expected, $xfElement->getAttribute('numFmtId')); - } }