diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b6c9deeb..3927d672 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1110,156 +1110,6 @@ parameters: count: 2 path: src/PhpSpreadsheet/DefinedName.php - - - message: "#^Cannot call method setBold\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Cannot call method setColor\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Cannot call method setItalic\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Cannot call method setName\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Cannot call method setSize\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Cannot call method setStrikethrough\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Cannot call method setSubscript\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Cannot call method setSuperscript\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Cannot call method setUnderline\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:startFontTag\\(\\) has parameter \\$tag with no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:\\$bold has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:\\$color has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:\\$colourMap has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:\\$endTagCallbacks has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:\\$face has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:\\$italic has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:\\$size has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:\\$stack has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:\\$startTagCallbacks has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:\\$strikethrough has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:\\$stringData has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:\\$subscript has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:\\$superscript has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Html\\:\\:\\$underline has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Html.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Sample\\:\\:getSamples\\(\\) should return array\\\\> but returns array\\\\>\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Sample.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Helper\\\\Sample\\:\\:log\\(\\) has parameter \\$message with no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Sample.php - - - - message: "#^Parameter \\#1 \\$directory of class RecursiveDirectoryIterator constructor expects string, string\\|false given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Sample.php - - - - message: "#^Parameter \\#1 \\$filename of function unlink expects string, string\\|false given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Sample.php - - - - message: "#^Parameter \\#1 \\$path of function pathinfo expects string, array\\|string given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Sample.php - - - - message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, string\\|false given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Helper/Sample.php - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\IOFactory\\:\\:createReader\\(\\) should return PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\IReader but returns object\\.$#" count: 1 @@ -1619,47 +1469,12 @@ parameters: message: "#^Unreachable statement \\- code above always terminates\\.$#" count: 8 path: src/PhpSpreadsheet/Reader/Xls.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\Color\\\\BIFF5\\:\\:\\$map has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Reader/Xls/Color/BIFF5.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\Color\\\\BIFF8\\:\\:\\$map has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\Color\\\\BuiltIn\\:\\:\\$map has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Reader/Xls/Color/BuiltIn.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\ErrorCode\\:\\:\\$map has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Reader/Xls/ErrorCode.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\RC4\\:\\:\\$i has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Reader/Xls/RC4.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\RC4\\:\\:\\$j has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Reader/Xls/RC4.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\RC4\\:\\:\\$s has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Reader/Xls/RC4.php - + - message: "#^Cannot access property \\$r on SimpleXMLElement\\|null\\.$#" count: 2 path: src/PhpSpreadsheet/Reader/Xlsx.php - + - message: "#^Parameter \\#1 \\$haystack of function strpos expects string, string\\|false given\\.$#" count: 1 @@ -2145,11 +1960,6 @@ parameters: count: 1 path: src/PhpSpreadsheet/Shared/OLERead.php - - - message: "#^Static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\TimeZone\\:\\:validateTimeZone\\(\\) is unused\\.$#" - count: 1 - path: src/PhpSpreadsheet/Shared/TimeZone.php - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:calculateGoodnessOfFit\\(\\) has parameter \\$const with no type specified\\.$#" count: 1 diff --git a/samples/Calculations/Financial/FV.php b/samples/Calculations/Financial/FV.php index 31ddb630..40b3366f 100644 --- a/samples/Calculations/Financial/FV.php +++ b/samples/Calculations/Financial/FV.php @@ -32,5 +32,5 @@ $worksheet->getStyle('B8:C8')->getNumberFormat()->setFormatCode('$#,##0.00'); $helper->log($worksheet->getCell('B8')->getValue()); $helper->log('FV() Result is ' . $worksheet->getCell('B8')->getFormattedValue()); -$helper->log($worksheet->getCell('C6')->getValue()); +$helper->log($worksheet->getCell('C8')->getValue()); $helper->log('FV() Result is ' . $worksheet->getCell('C8')->getFormattedValue()); diff --git a/src/PhpSpreadsheet/Helper/Html.php b/src/PhpSpreadsheet/Helper/Html.php index 632efebc..b8ed386a 100644 --- a/src/PhpSpreadsheet/Helper/Html.php +++ b/src/PhpSpreadsheet/Helper/Html.php @@ -12,7 +12,7 @@ use PhpOffice\PhpSpreadsheet\Style\Font; class Html { - protected static $colourMap = [ + private const COLOUR_MAP = [ 'aliceblue' => 'f0f8ff', 'antiquewhite' => 'faebd7', 'antiquewhite1' => 'ffefdb', @@ -532,25 +532,34 @@ class Html 'yellowgreen' => '9acd32', ]; - protected $face; + /** @var ?string */ + private $face; - protected $size; + /** @var ?string */ + private $size; - protected $color; + /** @var ?string */ + private $color; - protected $bold = false; + /** @var bool */ + private $bold = false; - protected $italic = false; + /** @var bool */ + private $italic = false; - protected $underline = false; + /** @var bool */ + private $underline = false; - protected $superscript = false; + /** @var bool */ + private $superscript = false; - protected $subscript = false; + /** @var bool */ + private $subscript = false; - protected $strikethrough = false; + /** @var bool */ + private $strikethrough = false; - protected $startTagCallbacks = [ + private const START_TAG_CALLBACKS = [ 'font' => 'startFontTag', 'b' => 'startBoldTag', 'strong' => 'startBoldTag', @@ -563,7 +572,7 @@ class Html 'sub' => 'startSubscriptTag', ]; - protected $endTagCallbacks = [ + private const END_TAG_CALLBACKS = [ 'font' => 'endFontTag', 'b' => 'endBoldTag', 'strong' => 'endBoldTag', @@ -584,16 +593,18 @@ class Html 'h6' => 'breakTag', ]; - protected $stack = []; + /** @var array */ + private $stack = []; - protected $stringData = ''; + /** @var string */ + private $stringData = ''; /** * @var RichText */ - protected $richTextObject; + private $richTextObject; - protected function initialise(): void + private function initialise(): void { $this->face = $this->size = $this->color = null; $this->bold = $this->italic = $this->underline = $this->superscript = $this->subscript = $this->strikethrough = false; @@ -633,7 +644,7 @@ class Html return $this->richTextObject; } - protected function cleanWhitespace(): void + private function cleanWhitespace(): void { foreach ($this->richTextObject->getRichTextElements() as $key => $element) { $text = $element->getText(); @@ -647,7 +658,7 @@ class Html } } - protected function buildTextRun(): void + private function buildTextRun(): void { $text = $this->stringData; if (trim($text) === '') { @@ -655,37 +666,40 @@ class Html } $richtextRun = $this->richTextObject->createTextRun($this->stringData); - if ($this->face) { - $richtextRun->getFont()->setName($this->face); - } - if ($this->size) { - $richtextRun->getFont()->setSize($this->size); - } - if ($this->color) { - $richtextRun->getFont()->setColor(new Color('ff' . $this->color)); - } - if ($this->bold) { - $richtextRun->getFont()->setBold(true); - } - if ($this->italic) { - $richtextRun->getFont()->setItalic(true); - } - if ($this->underline) { - $richtextRun->getFont()->setUnderline(Font::UNDERLINE_SINGLE); - } - if ($this->superscript) { - $richtextRun->getFont()->setSuperscript(true); - } - if ($this->subscript) { - $richtextRun->getFont()->setSubscript(true); - } - if ($this->strikethrough) { - $richtextRun->getFont()->setStrikethrough(true); + $font = $richtextRun->getFont(); + if ($font !== null) { + if ($this->face) { + $font->setName($this->face); + } + if ($this->size) { + $font->setSize($this->size); + } + if ($this->color) { + $font->setColor(new Color('ff' . $this->color)); + } + if ($this->bold) { + $font->setBold(true); + } + if ($this->italic) { + $font->setItalic(true); + } + if ($this->underline) { + $font->setUnderline(Font::UNDERLINE_SINGLE); + } + if ($this->superscript) { + $font->setSuperscript(true); + } + if ($this->subscript) { + $font->setSubscript(true); + } + if ($this->strikethrough) { + $font->setStrikethrough(true); + } } $this->stringData = ''; } - protected function rgbToColour(string $rgbValue): string + private function rgbToColour(string $rgbValue): string { preg_match_all('/\d+/', $rgbValue, $values); foreach ($values[0] as &$value) { @@ -697,100 +711,103 @@ class Html public static function colourNameLookup(string $colorName): string { - return self::$colourMap[$colorName] ?? ''; + return self::COLOUR_MAP[$colorName] ?? ''; } - protected function startFontTag($tag): void + private function startFontTag(DOMElement $tag): void { - foreach ($tag->attributes as $attribute) { - $attributeName = strtolower($attribute->name); - $attributeValue = $attribute->value; + $attrs = $tag->attributes; + if ($attrs !== null) { + foreach ($attrs as $attribute) { + $attributeName = strtolower($attribute->name); + $attributeValue = $attribute->value; - if ($attributeName == 'color') { - if (preg_match('/rgb\s*\(/', $attributeValue)) { - $this->$attributeName = $this->rgbToColour($attributeValue); - } elseif (strpos(trim($attributeValue), '#') === 0) { - $this->$attributeName = ltrim($attributeValue, '#'); + if ($attributeName == 'color') { + if (preg_match('/rgb\s*\(/', $attributeValue)) { + $this->$attributeName = $this->rgbToColour($attributeValue); + } elseif (strpos(trim($attributeValue), '#') === 0) { + $this->$attributeName = ltrim($attributeValue, '#'); + } else { + $this->$attributeName = static::colourNameLookup($attributeValue); + } } else { - $this->$attributeName = static::colourNameLookup($attributeValue); + $this->$attributeName = $attributeValue; } - } else { - $this->$attributeName = $attributeValue; } } } - protected function endFontTag(): void + private function endFontTag(): void { $this->face = $this->size = $this->color = null; } - protected function startBoldTag(): void + private function startBoldTag(): void { $this->bold = true; } - protected function endBoldTag(): void + private function endBoldTag(): void { $this->bold = false; } - protected function startItalicTag(): void + private function startItalicTag(): void { $this->italic = true; } - protected function endItalicTag(): void + private function endItalicTag(): void { $this->italic = false; } - protected function startUnderlineTag(): void + private function startUnderlineTag(): void { $this->underline = true; } - protected function endUnderlineTag(): void + private function endUnderlineTag(): void { $this->underline = false; } - protected function startSubscriptTag(): void + private function startSubscriptTag(): void { $this->subscript = true; } - protected function endSubscriptTag(): void + private function endSubscriptTag(): void { $this->subscript = false; } - protected function startSuperscriptTag(): void + private function startSuperscriptTag(): void { $this->superscript = true; } - protected function endSuperscriptTag(): void + private function endSuperscriptTag(): void { $this->superscript = false; } - protected function startStrikethruTag(): void + private function startStrikethruTag(): void { $this->strikethrough = true; } - protected function endStrikethruTag(): void + private function endStrikethruTag(): void { $this->strikethrough = false; } - protected function breakTag(): void + private function breakTag(): void { $this->stringData .= "\n"; } - protected function parseTextNode(DOMText $textNode): void + private function parseTextNode(DOMText $textNode): void { $domText = (string) preg_replace( '/\s+/u', @@ -804,7 +821,7 @@ class Html /** * @param string $callbackTag */ - protected function handleCallback(DOMElement $element, $callbackTag, array $callbacks): void + private function handleCallback(DOMElement $element, $callbackTag, array $callbacks): void { if (isset($callbacks[$callbackTag])) { $elementHandler = $callbacks[$callbackTag]; @@ -815,20 +832,20 @@ class Html } } - protected function parseElementNode(DOMElement $element): void + private function parseElementNode(DOMElement $element): void { $callbackTag = strtolower($element->nodeName); $this->stack[] = $callbackTag; - $this->handleCallback($element, $callbackTag, $this->startTagCallbacks); + $this->handleCallback($element, $callbackTag, self::START_TAG_CALLBACKS); $this->parseElements($element); array_pop($this->stack); - $this->handleCallback($element, $callbackTag, $this->endTagCallbacks); + $this->handleCallback($element, $callbackTag, self::END_TAG_CALLBACKS); } - protected function parseElements(DOMNode $element): void + private function parseElements(DOMNode $element): void { foreach ($element->childNodes as $child) { if ($child instanceof DOMText) { diff --git a/src/PhpSpreadsheet/Helper/Sample.php b/src/PhpSpreadsheet/Helper/Sample.php index 0ac0c796..a0063bd3 100644 --- a/src/PhpSpreadsheet/Helper/Sample.php +++ b/src/PhpSpreadsheet/Helper/Sample.php @@ -77,6 +77,11 @@ class Sample { // Populate samples $baseDir = realpath(__DIR__ . '/../../../samples'); + if ($baseDir === false) { + // @codeCoverageIgnoreStart + throw new RuntimeException('realpath returned false'); + // @codeCoverageIgnoreEnd + } $directory = new RecursiveDirectoryIterator($baseDir); $iterator = new RecursiveIteratorIterator($directory); $regex = new RegexIterator($iterator, '/^.+\.php$/', RecursiveRegexIterator::GET_MATCH); @@ -84,6 +89,11 @@ class Sample $files = []; foreach ($regex as $file) { $file = str_replace(str_replace('\\', '/', $baseDir) . '/', '', str_replace('\\', '/', $file[0])); + if (is_array($file)) { + // @codeCoverageIgnoreStart + throw new RuntimeException('str_replace returned array'); + // @codeCoverageIgnoreEnd + } $info = pathinfo($file); $category = str_replace('_', ' ', $info['dirname'] ?? ''); $name = str_replace('_', ' ', (string) preg_replace('/(|\.php)/', '', $info['filename'])); @@ -172,12 +182,17 @@ class Sample public function getTemporaryFilename($extension = 'xlsx') { $temporaryFilename = tempnam($this->getTemporaryFolder(), 'phpspreadsheet-'); + if ($temporaryFilename === false) { + // @codeCoverageIgnoreStart + throw new RuntimeException('tempnam returned false'); + // @codeCoverageIgnoreEnd + } unlink($temporaryFilename); return $temporaryFilename . '.' . $extension; } - public function log($message): void + public function log(string $message): void { $eol = $this->isCli() ? PHP_EOL : '
'; echo date('H:i:s ') . $message . $eol; diff --git a/src/PhpSpreadsheet/Reader/Xls/Color/BIFF5.php b/src/PhpSpreadsheet/Reader/Xls/Color/BIFF5.php index 743d9387..15d0b733 100644 --- a/src/PhpSpreadsheet/Reader/Xls/Color/BIFF5.php +++ b/src/PhpSpreadsheet/Reader/Xls/Color/BIFF5.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Reader\Xls\Color; class BIFF5 { - protected static $map = [ + private const BIFF5_COLOR_MAP = [ 0x08 => '000000', 0x09 => 'FFFFFF', 0x0A => 'FF0000', @@ -72,10 +72,6 @@ class BIFF5 */ public static function lookup($color) { - if (isset(self::$map[$color])) { - return ['rgb' => self::$map[$color]]; - } - - return ['rgb' => '000000']; + return ['rgb' => self::BIFF5_COLOR_MAP[$color] ?? '000000']; } } diff --git a/src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php b/src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php index 5c109fb0..019ec79e 100644 --- a/src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php +++ b/src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Reader\Xls\Color; class BIFF8 { - protected static $map = [ + private const BIFF8_COLOR_MAP = [ 0x08 => '000000', 0x09 => 'FFFFFF', 0x0A => 'FF0000', @@ -72,10 +72,6 @@ class BIFF8 */ public static function lookup($color) { - if (isset(self::$map[$color])) { - return ['rgb' => self::$map[$color]]; - } - - return ['rgb' => '000000']; + return ['rgb' => self::BIFF8_COLOR_MAP[$color] ?? '000000']; } } diff --git a/src/PhpSpreadsheet/Reader/Xls/Color/BuiltIn.php b/src/PhpSpreadsheet/Reader/Xls/Color/BuiltIn.php index 90d50e33..b6a96af8 100644 --- a/src/PhpSpreadsheet/Reader/Xls/Color/BuiltIn.php +++ b/src/PhpSpreadsheet/Reader/Xls/Color/BuiltIn.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Reader\Xls\Color; class BuiltIn { - protected static $map = [ + private const BUILTIN_COLOR_MAP = [ 0x00 => '000000', 0x01 => 'FFFFFF', 0x02 => 'FF0000', @@ -26,10 +26,6 @@ class BuiltIn */ public static function lookup($color) { - if (isset(self::$map[$color])) { - return ['rgb' => self::$map[$color]]; - } - - return ['rgb' => '000000']; + return ['rgb' => self::BUILTIN_COLOR_MAP[$color] ?? '000000']; } } diff --git a/src/PhpSpreadsheet/Reader/Xls/ErrorCode.php b/src/PhpSpreadsheet/Reader/Xls/ErrorCode.php index 7daf7230..0b79366b 100644 --- a/src/PhpSpreadsheet/Reader/Xls/ErrorCode.php +++ b/src/PhpSpreadsheet/Reader/Xls/ErrorCode.php @@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Reader\Xls; class ErrorCode { - protected static $map = [ + private const ERROR_CODE_MAP = [ 0x00 => '#NULL!', 0x07 => '#DIV/0!', 0x0F => '#VALUE!', @@ -23,10 +23,6 @@ class ErrorCode */ public static function lookup($code) { - if (isset(self::$map[$code])) { - return self::$map[$code]; - } - - return false; + return self::ERROR_CODE_MAP[$code] ?? false; } } diff --git a/src/PhpSpreadsheet/Reader/Xls/RC4.php b/src/PhpSpreadsheet/Reader/Xls/RC4.php index 691aca7c..b7c7c900 100644 --- a/src/PhpSpreadsheet/Reader/Xls/RC4.php +++ b/src/PhpSpreadsheet/Reader/Xls/RC4.php @@ -4,11 +4,13 @@ namespace PhpOffice\PhpSpreadsheet\Reader\Xls; class RC4 { - // Context - protected $s = []; + /** @var int[] */ + protected $s = []; // Context + /** @var int */ protected $i = 0; + /** @var int */ protected $j = 0; /** diff --git a/src/PhpSpreadsheet/Shared/TimeZone.php b/src/PhpSpreadsheet/Shared/TimeZone.php index 734c076d..324e3424 100644 --- a/src/PhpSpreadsheet/Shared/TimeZone.php +++ b/src/PhpSpreadsheet/Shared/TimeZone.php @@ -35,7 +35,7 @@ class TimeZone */ public static function setTimeZone(string $timezoneName): bool { - if (self::validateTimezone($timezoneName)) { + if (self::validateTimeZone($timezoneName)) { self::$timezone = $timezoneName; return true; @@ -67,7 +67,7 @@ class TimeZone { $timezoneName = $timezoneName ?? self::$timezone; $dtobj = Date::dateTimeFromTimestamp("$timestamp"); - if (!self::validateTimezone($timezoneName)) { + if (!self::validateTimeZone($timezoneName)) { throw new PhpSpreadsheetException("Invalid timezone $timezoneName"); } $dtobj->setTimeZone(new DateTimeZone($timezoneName)); diff --git a/tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php b/tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php index cabac403..ad395ace 100644 --- a/tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php @@ -80,6 +80,7 @@ class HtmlTest extends TestCase Blue background Unknown fore/background + Unknown fore/background '; $filename = HtmlHelper::createHtml($html); @@ -93,6 +94,10 @@ class HtmlTest extends TestCase self::assertEquals('000000', $style->getFont()->getColor()->getRGB()); self::assertEquals('000000', $style->getFill()->getEndColor()->getRGB()); self::assertEquals('FFFFFF', $style->getFill()->getstartColor()->getRGB()); + $style = $firstSheet->getCell('C1')->getStyle(); + self::assertEquals('f0f8ff', $style->getFont()->getColor()->getRGB()); + self::assertEquals('eedfcc', $style->getFill()->getEndColor()->getRGB()); + self::assertEquals('eedfcc', $style->getFill()->getstartColor()->getRGB()); } public function testCanApplyInlineFontStyles(): void diff --git a/tests/PhpSpreadsheetTests/Reader/Xls/ColorMapTest.php b/tests/PhpSpreadsheetTests/Reader/Xls/ColorMapTest.php new file mode 100644 index 00000000..977b852b --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xls/ColorMapTest.php @@ -0,0 +1,34 @@ + [0x00, '000000', '000000', '000000'], + 'non-default builtin' => [0x02, '000000', '000000', 'FF0000'], + 'system window text color' => [0x40, '000000', '000000', '000000'], + 'system window background color' => [0x41, '000000', '000000', 'FFFFFF'], + 'same biff5/8' => [0x09, 'FFFFFF', 'FFFFFF', '000000'], + 'different biff5/8' => [0x29, '69FFFF', 'CCFFFF', '000000'], + + ]; + } +} diff --git a/tests/PhpSpreadsheetTests/Reader/Xls/ErrorCodeMapTest.php b/tests/PhpSpreadsheetTests/Reader/Xls/ErrorCodeMapTest.php new file mode 100644 index 00000000..e857d84f --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xls/ErrorCodeMapTest.php @@ -0,0 +1,33 @@ +