Phpstan Baseline Fixes 2022-09-21 (#3080)
* Phpstan Baseline Fixes 2022-09-21 Eliminate about 200 more lines from Phpstan baseline. For Helper/Sample and Helper/Html and others, many properties are declared as protected despite the fact that the classes do not extend any other class, and there are no classes which extend them. They are changed to private; this could be a breaking change in circumstances for which I cannot think of a use case (user extends class for some reason). * Slightly Botched Merge Commit Hope this fixes phpstan.
This commit is contained in:
parent
b8201a79c5
commit
35b42cc180
|
|
@ -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\\<array\\<string\\>\\> but returns array\\<string, array\\<string, array\\|string\\>\\>\\.$#"
|
||||
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
|
||||
|
|
@ -1620,41 +1470,6 @@ parameters:
|
|||
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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 : '<br />';
|
||||
echo date('H:i:s ') . $message . $eol;
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ class HtmlTest extends TestCase
|
|||
<tr>
|
||||
<td style="background-color: #0000FF;color: #FFFFFF">Blue background</td>
|
||||
<td style="background-color: unknown1;color: unknown2">Unknown fore/background</td>
|
||||
<td style="background-color: antiquewhite2;color: aliceblue">Unknown fore/background</td>
|
||||
</tr>
|
||||
</table>';
|
||||
$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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls\Color\BIFF5;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls\Color\BIFF8;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls\Color\BuiltIn;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ColorMapTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider colorMapProvider
|
||||
*/
|
||||
public function testColorMap(int $index, string $expectedBiff5, string $expectedBiff8, string $expectedBuiltin): void
|
||||
{
|
||||
self::assertSame($expectedBiff5, BIFF5::lookup($index)['rgb']);
|
||||
self::assertSame($expectedBiff8, BIFF8::lookup($index)['rgb']);
|
||||
self::assertSame($expectedBuiltin, BuiltIn::lookup($index)['rgb']);
|
||||
}
|
||||
|
||||
public function colorMapProvider(): array
|
||||
{
|
||||
return [
|
||||
'default builtin' => [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'],
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls\ErrorCode;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ErrorCodeMapTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param bool|string $expected
|
||||
*
|
||||
* @dataProvider errorCodeMapProvider
|
||||
*/
|
||||
public function testErrorCode($expected, int $index): void
|
||||
{
|
||||
self::assertSame($expected, ErrorCode::lookup($index));
|
||||
}
|
||||
|
||||
public function errorCodeMapProvider(): array
|
||||
{
|
||||
return [
|
||||
[false, 0x01],
|
||||
['#NULL!', 0x00],
|
||||
['#DIV/0!', 0x07],
|
||||
['#VALUE!', 0x0F],
|
||||
['#REF!', 0x17],
|
||||
['#NAME?', 0x1d],
|
||||
['#NUM!', 0x24],
|
||||
['#N/A', 0x2a],
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue