mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-13 11:36:24 +00:00
Try to Appease Scrutinizer
I usually ignore complexity warnings, but let's see if I can fix this one.
This commit is contained in:
@@ -1044,31 +1044,7 @@ class Html extends BaseReader
|
||||
if (!isset($attributes['src'])) {
|
||||
return;
|
||||
}
|
||||
$styleArray = [];
|
||||
if (isset($attributes['style'])) {
|
||||
$styles = explode(';', $attributes['style']);
|
||||
foreach ($styles as $style) {
|
||||
$value = explode(':', $style);
|
||||
if (count($value) === 2) {
|
||||
$arrayKey = trim($value[0]);
|
||||
$arrayValue = trim($value[1]);
|
||||
if ($arrayKey === 'width') {
|
||||
if (substr($arrayValue, -2) === 'px') {
|
||||
$arrayValue = (string) (((float) substr($arrayValue, 0, -2)));
|
||||
} else {
|
||||
$arrayValue = (new CssDimension($arrayValue))->width();
|
||||
}
|
||||
} elseif ($arrayKey === 'height') {
|
||||
if (substr($arrayValue, -2) === 'px') {
|
||||
$arrayValue = substr($arrayValue, 0, -2);
|
||||
} else {
|
||||
$arrayValue = (new CssDimension($arrayValue))->height();
|
||||
}
|
||||
}
|
||||
$styleArray[$arrayKey] = $arrayValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
$styleArray = self::getStyleArray($attributes);
|
||||
|
||||
$src = $attributes['src'];
|
||||
if (substr($src, 0, 5) !== 'data:') {
|
||||
@@ -1116,6 +1092,37 @@ class Html extends BaseReader
|
||||
}
|
||||
}
|
||||
|
||||
private static function getStyleArray(array $attributes): array
|
||||
{
|
||||
$styleArray = [];
|
||||
if (isset($attributes['style'])) {
|
||||
$styles = explode(';', $attributes['style']);
|
||||
foreach ($styles as $style) {
|
||||
$value = explode(':', $style);
|
||||
if (count($value) === 2) {
|
||||
$arrayKey = trim($value[0]);
|
||||
$arrayValue = trim($value[1]);
|
||||
if ($arrayKey === 'width') {
|
||||
if (substr($arrayValue, -2) === 'px') {
|
||||
$arrayValue = (string) (((float) substr($arrayValue, 0, -2)));
|
||||
} else {
|
||||
$arrayValue = (new CssDimension($arrayValue))->width();
|
||||
}
|
||||
} elseif ($arrayKey === 'height') {
|
||||
if (substr($arrayValue, -2) === 'px') {
|
||||
$arrayValue = substr($arrayValue, 0, -2);
|
||||
} else {
|
||||
$arrayValue = (new CssDimension($arrayValue))->height();
|
||||
}
|
||||
}
|
||||
$styleArray[$arrayKey] = $arrayValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $styleArray;
|
||||
}
|
||||
|
||||
private const BORDER_MAPPINGS = [
|
||||
'dash-dot' => Border::BORDER_DASHDOT,
|
||||
'dash-dot-dot' => Border::BORDER_DASHDOTDOT,
|
||||
|
||||
Reference in New Issue
Block a user