Skip to content

Commit 3977e2a

Browse files
committed
Add Style
1 parent 5c94de3 commit 3977e2a

34 files changed

+330
-92
lines changed

src/PhpSpreadsheet/Reader/Gnumeric/Styles.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ private function readStyles(SimpleXMLElement $styleRegion, int $maxRow, int $max
114114
$styleArray['numberFormat']['formatCode'] = $formatCode;
115115
$styleArray = $this->readStyle($styleArray, $styleAttributes, $style);
116116
}
117-
$this->spreadsheet->getActiveSheet()->getStyle($cellRange)->applyFromArray($styleArray);
117+
/** @var mixed[][] $styleArray */
118+
$this->spreadsheet
119+
->getActiveSheet()
120+
->getStyle($cellRange)
121+
->applyFromArray($styleArray);
118122
}
119123
}
120124
}

src/PhpSpreadsheet/Reader/Html.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,10 @@ private function processDomElementDataFormat(Worksheet $sheet, int $row, string
640640
private function processDomElementThTd(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray): void
641641
{
642642
while (isset($this->rowspan[$column . $row])) {
643-
++$column; //* @phpstan-ignore-line
643+
$temp = (string) $column;
644+
++$temp;
645+
$column = (string) $temp;
644646
}
645-
//* @phpstan-ignore-next-line
646647
$this->processDomElement($child, $sheet, $row, $column, $cellContent); // ++$column above confuses Phpstan
647648

648649
// apply inline style

src/PhpSpreadsheet/Reader/Xlsx/Chart.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,26 +1201,36 @@ private function parseFont(SimpleXMLElement $titleDetailPart): ?Font
12011201
if ($fontArray['size'] !== null && $fontArray['size'] >= 100) {
12021202
$fontArray['size'] /= 100.0;
12031203
}
1204-
$fontArray['bold'] = self::getAttributeBoolean($titleDetailPart->pPr->defRPr, 'b');
1205-
$fontArray['italic'] = self::getAttributeBoolean($titleDetailPart->pPr->defRPr, 'i');
1204+
if ($fontArray['size'] !== null) {
1205+
$fontArray['size'] = (int) ($fontArray['size']);
1206+
}
1207+
$fontArray['bold'] = (bool) self::getAttributeBoolean($titleDetailPart->pPr->defRPr, 'b');
1208+
$fontArray['italic'] = (bool) self::getAttributeBoolean($titleDetailPart->pPr->defRPr, 'i');
12061209
$fontArray['underscore'] = self::getAttributeString($titleDetailPart->pPr->defRPr, 'u');
1207-
$fontArray['strikethrough'] = self::getAttributeString($titleDetailPart->pPr->defRPr, 'strike');
1208-
$fontArray['cap'] = self::getAttributeString($titleDetailPart->pPr->defRPr, 'cap');
1210+
$strikethrough = self::getAttributeString($titleDetailPart->pPr->defRPr, 'strike');
1211+
if ($strikethrough !== null) {
1212+
if ($strikethrough == 'noStrike') {
1213+
$fontArray['strikethrough'] = false;
1214+
} else {
1215+
$fontArray['strikethrough'] = true;
1216+
}
1217+
}
1218+
$fontArray['cap'] = (string) self::getAttributeString($titleDetailPart->pPr->defRPr, 'cap');
12091219

12101220
if (isset($titleDetailPart->pPr->defRPr->latin)) {
1211-
$fontArray['latin'] = self::getAttributeString($titleDetailPart->pPr->defRPr->latin, 'typeface');
1221+
$fontArray['latin'] = (string) self::getAttributeString($titleDetailPart->pPr->defRPr->latin, 'typeface');
12121222
}
12131223
if (isset($titleDetailPart->pPr->defRPr->ea)) {
1214-
$fontArray['eastAsian'] = self::getAttributeString($titleDetailPart->pPr->defRPr->ea, 'typeface');
1224+
$fontArray['eastAsian'] = (string) self::getAttributeString($titleDetailPart->pPr->defRPr->ea, 'typeface');
12151225
}
12161226
if (isset($titleDetailPart->pPr->defRPr->cs)) {
1217-
$fontArray['complexScript'] = self::getAttributeString($titleDetailPart->pPr->defRPr->cs, 'typeface');
1227+
$fontArray['complexScript'] = (string) self::getAttributeString($titleDetailPart->pPr->defRPr->cs, 'typeface');
12181228
}
12191229
if (isset($titleDetailPart->pPr->defRPr->solidFill)) {
12201230
$fontArray['chartColor'] = new ChartColor($this->readColor($titleDetailPart->pPr->defRPr->solidFill));
12211231
}
12221232
$font = new Font();
1223-
$font->setSize(null, true);
1233+
//$font->setSize(null, true);
12241234
$font->applyFromArray($fontArray);
12251235

12261236
return $font;

src/PhpSpreadsheet/Reader/Xlsx/ColumnAndRowAttributes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ private function readColumnAttributes(SimpleXMLElement $worksheetCols, bool $rea
144144
$endColumn = Coordinate::stringFromColumnIndex((int) $column['max']);
145145
++$endColumn;
146146
for ($columnAddress = $startColumn; $columnAddress !== $endColumn; ++$columnAddress) {
147+
/** @var string $columnAddress */
147148
$columnAttributes[$columnAddress] = $this->readColumnRangeAttributes($column, $readDataOnly);
148149

149150
if ((int) ($column['max']) == 16384) {

src/PhpSpreadsheet/Reader/Xlsx/Styles.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Styles extends BaseParserClass
2323
*/
2424
private ?Theme $theme = null;
2525

26-
/** @var mixed[] */
26+
/** @var string[] */
2727
private array $workbookPalette = [];
2828

2929
/** @var mixed[] */
@@ -41,7 +41,7 @@ public function setNamespace(string $namespace): void
4141
$this->namespace = $namespace;
4242
}
4343

44-
/** @param mixed[] $palette */
44+
/** @param string[] $palette */
4545
public function setWorkbookPalette(array $palette): void
4646
{
4747
$this->workbookPalette = $palette;

src/PhpSpreadsheet/Style/Alignment.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ public function getSharedComponent(): self
168168

169169
/**
170170
* Build style array from subcomponents.
171+
*
172+
* @param mixed[] $array
173+
*
174+
* @return array{alignment: mixed[]}
171175
*/
172176
public function getStyleArray(array $array): array
173177
{
@@ -188,7 +192,7 @@ public function getStyleArray(array $array): array
188192
* );
189193
* </code>
190194
*
191-
* @param array $styleArray Array containing style information
195+
* @param mixed[] $styleArray Array containing style information
192196
*
193197
* @return $this
194198
*/
@@ -198,6 +202,7 @@ public function applyFromArray(array $styleArray): static
198202
$this->getActiveSheet()->getStyle($this->getSelectedCells())
199203
->applyFromArray($this->getStyleArray($styleArray));
200204
} else {
205+
/** @var array{horizontal?: string, vertical?: string, justifyLastLine?: bool, textRotation?: int, wrapText?: bool, shrinkToFit?: bool, readOrder?: int, indent?: int} $styleArray */
201206
if (isset($styleArray['horizontal'])) {
202207
$this->setHorizontal($styleArray['horizontal']);
203208
}
@@ -523,6 +528,7 @@ public function getHashCode(): string
523528
);
524529
}
525530

531+
/** @return mixed[] */
526532
protected function exportArray1(): array
527533
{
528534
$exportedArray = [];

src/PhpSpreadsheet/Style/Border.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ public function getSharedComponent(): self
8383

8484
/**
8585
* Build style array from subcomponents.
86+
*
87+
* @param mixed[] $array
88+
*
89+
* @return mixed[]
8690
*/
8791
public function getStyleArray(array $array): array
8892
{
@@ -106,7 +110,7 @@ public function getStyleArray(array $array): array
106110
* );
107111
* </code>
108112
*
109-
* @param array $styleArray Array containing style information
113+
* @param mixed[] $styleArray Array containing style information
110114
*
111115
* @return $this
112116
*/
@@ -115,11 +119,13 @@ public function applyFromArray(array $styleArray): static
115119
if ($this->isSupervisor) {
116120
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray));
117121
} else {
122+
/** @var array{borderStyle?: string, color?: array{rgb?: string, argb?: string}} $styleArray */
118123
if (isset($styleArray['borderStyle'])) {
119124
$this->setBorderStyle($styleArray['borderStyle']);
120125
}
121126
if (isset($styleArray['color'])) {
122-
$this->getColor()->applyFromArray($styleArray['color']);
127+
$this->getColor()
128+
->applyFromArray($styleArray['color']);
123129
}
124130
}
125131

@@ -210,6 +216,7 @@ public function getHashCode(): string
210216
);
211217
}
212218

219+
/** @return mixed[] */
213220
protected function exportArray1(): array
214221
{
215222
$exportedArray = [];

src/PhpSpreadsheet/Style/Borders.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ public function getSharedComponent(): self
124124

125125
/**
126126
* Build style array from subcomponents.
127+
*
128+
* @param mixed[] $array
129+
*
130+
* @return array{borders: mixed[]}
127131
*/
128132
public function getStyleArray(array $array): array
129133
{
@@ -165,7 +169,7 @@ public function getStyleArray(array $array): array
165169
* );
166170
* </code>
167171
*
168-
* @param array $styleArray Array containing style information
172+
* @param mixed[] $styleArray Array containing style information
169173
*
170174
* @return $this
171175
*/
@@ -174,6 +178,7 @@ public function applyFromArray(array $styleArray): static
174178
if ($this->isSupervisor) {
175179
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray));
176180
} else {
181+
/** @var array{left?: float[], right?: float[], top?: float[], bottom?: float[], diagonal?: mixed[], diagonalDirection?: int, allBorders?: mixed[][]} $styleArray */
177182
if (isset($styleArray['left'])) {
178183
$this->getLeft()->applyFromArray($styleArray['left']);
179184
}
@@ -356,6 +361,7 @@ public function getHashCode(): string
356361
);
357362
}
358363

364+
/** @return mixed[][] */
359365
protected function exportArray1(): array
360366
{
361367
$exportedArray = [];
@@ -365,6 +371,7 @@ protected function exportArray1(): array
365371
$this->exportArray2($exportedArray, 'left', $this->getLeft());
366372
$this->exportArray2($exportedArray, 'right', $this->getRight());
367373
$this->exportArray2($exportedArray, 'top', $this->getTop());
374+
/** @var mixed[][] $exportedArray */
368375

369376
return $exportedArray;
370377
}

src/PhpSpreadsheet/Style/Color.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ public function getSharedComponent(): self
156156

157157
/**
158158
* Build style array from subcomponents.
159+
*
160+
* @param mixed[] $array
161+
*
162+
* @return mixed[]
159163
*/
160164
public function getStyleArray(array $array): array
161165
{
@@ -172,7 +176,7 @@ public function getStyleArray(array $array): array
172176
* $spreadsheet->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray(['rgb' => '808080']);
173177
* </code>
174178
*
175-
* @param array $styleArray Array containing style information
179+
* @param array{rgb?: string, argb?: string} $styleArray Array containing style information
176180
*
177181
* @return $this
178182
*/
@@ -365,6 +369,7 @@ public static function changeBrightness(string $hexColourValue, float $adjustPer
365369
* @param int $colorIndex Index entry point into the colour array
366370
* @param bool $background Flag to indicate whether default background or foreground colour
367371
* should be returned if the indexed colour doesn't exist
372+
* @param null|string[] $palette
368373
*/
369374
public static function indexedColor(int $colorIndex, bool $background = false, ?array $palette = null): self
370375
{
@@ -401,6 +406,7 @@ public function getHashCode(): string
401406
);
402407
}
403408

409+
/** @return mixed[] */
404410
protected function exportArray1(): array
405411
{
406412
$exportedArray = [];

src/PhpSpreadsheet/Style/ConditionalFormatting/CellMatcher.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ protected function wrapCellValue(): float|int|string
138138
return $this->wrapValue($this->cell->getCalculatedValue());
139139
}
140140

141+
/** @param string[] $matches */
141142
protected function conditionCellAdjustment(array $matches): float|int|string
142143
{
143144
$column = $matches[6];
@@ -150,7 +151,7 @@ protected function conditionCellAdjustment(array $matches): float|int|string
150151
}
151152

152153
if (!str_contains($row, '$')) {
153-
$row += $this->cellRow - $this->referenceRow;
154+
$row = (int) $row + $this->cellRow - $this->referenceRow;
154155
}
155156

156157
if (!empty($matches[4])) {
@@ -194,6 +195,11 @@ protected function cellConditionCheck(string $condition): string
194195
return implode(Calculation::FORMULA_STRING_QUOTE, $splitCondition);
195196
}
196197

198+
/**
199+
* @param mixed[] $conditions
200+
*
201+
* @return mixed[]
202+
*/
197203
protected function adjustConditionsForCellReferences(array $conditions): array
198204
{
199205
return array_map(
@@ -210,7 +216,11 @@ protected function processOperatorComparison(Conditional $conditional): bool
210216

211217
$operator = self::COMPARISON_OPERATORS[$conditional->getOperatorType()];
212218
$conditions = $this->adjustConditionsForCellReferences($conditional->getConditions());
213-
$expression = sprintf('%s%s%s', (string) $this->wrapCellValue(), $operator, (string) array_pop($conditions));
219+
/** @var float|int|string */
220+
$temp1 = $this->wrapCellValue();
221+
/** @var scalar */
222+
$temp2 = array_pop($conditions);
223+
$expression = sprintf('%s%s%s', (string) $temp1, $operator, (string) $temp2);
214224

215225
return $this->evaluateExpression($expression);
216226
}
@@ -234,7 +244,7 @@ protected function processRangeOperator(Conditional $conditional): bool
234244
(string) $this->wrapCellValue(),
235245
self::COMPARISON_RANGE_OPERATORS[$conditional->getOperatorType()]
236246
),
237-
...$conditions
247+
...$conditions //* @phpstan-ignore-line
238248
);
239249

240250
return $this->evaluateExpression($expression);
@@ -257,11 +267,14 @@ protected function processDuplicatesComparison(Conditional $conditional): bool
257267
protected function processExpression(Conditional $conditional): bool
258268
{
259269
$conditions = $this->adjustConditionsForCellReferences($conditional->getConditions());
270+
/** @var string */
260271
$expression = array_pop($conditions);
272+
/** @var float|int|string */
273+
$temp = $this->wrapCellValue();
261274

262275
$expression = (string) preg_replace(
263276
'/\b' . $this->referenceCell . '\b/i',
264-
(string) $this->wrapCellValue(),
277+
(string) $temp,
265278
$expression
266279
);
267280

0 commit comments

Comments
 (0)