Skip to content

Commit a917176

Browse files
committed
Try to Appease Scrutinizer
I usually ignore complexity warnings, but let's see if I can fix this one.
1 parent 197dd4d commit a917176

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

src/PhpSpreadsheet/Reader/Html.php

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,31 +1044,7 @@ private function insertImage(Worksheet $sheet, string $column, int $row, array $
10441044
if (!isset($attributes['src'])) {
10451045
return;
10461046
}
1047-
$styleArray = [];
1048-
if (isset($attributes['style'])) {
1049-
$styles = explode(';', $attributes['style']);
1050-
foreach ($styles as $style) {
1051-
$value = explode(':', $style);
1052-
if (count($value) === 2) {
1053-
$arrayKey = trim($value[0]);
1054-
$arrayValue = trim($value[1]);
1055-
if ($arrayKey === 'width') {
1056-
if (substr($arrayValue, -2) === 'px') {
1057-
$arrayValue = (string) (((float) substr($arrayValue, 0, -2)));
1058-
} else {
1059-
$arrayValue = (new CssDimension($arrayValue))->width();
1060-
}
1061-
} elseif ($arrayKey === 'height') {
1062-
if (substr($arrayValue, -2) === 'px') {
1063-
$arrayValue = substr($arrayValue, 0, -2);
1064-
} else {
1065-
$arrayValue = (new CssDimension($arrayValue))->height();
1066-
}
1067-
}
1068-
$styleArray[$arrayKey] = $arrayValue;
1069-
}
1070-
}
1071-
}
1047+
$styleArray = self::getStyleArray($attributes);
10721048

10731049
$src = $attributes['src'];
10741050
if (substr($src, 0, 5) !== 'data:') {
@@ -1116,6 +1092,37 @@ private function insertImage(Worksheet $sheet, string $column, int $row, array $
11161092
}
11171093
}
11181094

1095+
private static function getStyleArray(array $attributes): array
1096+
{
1097+
$styleArray = [];
1098+
if (isset($attributes['style'])) {
1099+
$styles = explode(';', $attributes['style']);
1100+
foreach ($styles as $style) {
1101+
$value = explode(':', $style);
1102+
if (count($value) === 2) {
1103+
$arrayKey = trim($value[0]);
1104+
$arrayValue = trim($value[1]);
1105+
if ($arrayKey === 'width') {
1106+
if (substr($arrayValue, -2) === 'px') {
1107+
$arrayValue = (string) (((float) substr($arrayValue, 0, -2)));
1108+
} else {
1109+
$arrayValue = (new CssDimension($arrayValue))->width();
1110+
}
1111+
} elseif ($arrayKey === 'height') {
1112+
if (substr($arrayValue, -2) === 'px') {
1113+
$arrayValue = substr($arrayValue, 0, -2);
1114+
} else {
1115+
$arrayValue = (new CssDimension($arrayValue))->height();
1116+
}
1117+
}
1118+
$styleArray[$arrayKey] = $arrayValue;
1119+
}
1120+
}
1121+
}
1122+
1123+
return $styleArray;
1124+
}
1125+
11191126
private const BORDER_MAPPINGS = [
11201127
'dash-dot' => Border::BORDER_DASHDOT,
11211128
'dash-dot-dot' => Border::BORDER_DASHDOTDOT,

0 commit comments

Comments
 (0)