Try to Appease Scrutinizer

I usually ignore complexity warnings, but let's see if I can fix this one.
This commit is contained in:
oleibman
2024-08-15 19:54:59 -07:00
parent 197dd4d881
commit a9171767f7
+32 -25
View File
@@ -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,