Skip to content

Commit fbf0724

Browse files
committed
Better way of expressing multiple units
Also will make it easier to extend this check
1 parent a80739f commit fbf0724

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -385,32 +385,20 @@ private function parseNumericValue($bForColor = false) {
385385
}
386386
}
387387
$fSize = floatval($sSize);
388+
388389
$sUnit = null;
389-
if ($this->comes('%')) {
390-
$sUnit = $this->consume('%');
391-
} else if ($this->comes('em')) {
392-
$sUnit = $this->consume('em');
393-
} else if ($this->comes('ex')) {
394-
$sUnit = $this->consume('ex');
395-
} else if ($this->comes('px')) {
396-
$sUnit = $this->consume('px');
397-
} else if ($this->comes('deg')) {
398-
$sUnit = $this->consume('deg');
399-
} else if ($this->comes('s')) {
400-
$sUnit = $this->consume('s');
401-
} else if ($this->comes('cm')) {
402-
$sUnit = $this->consume('cm');
403-
} else if ($this->comes('pt')) {
404-
$sUnit = $this->consume('pt');
405-
} else if ($this->comes('in')) {
406-
$sUnit = $this->consume('in');
407-
} else if ($this->comes('pc')) {
408-
$sUnit = $this->consume('pc');
409-
} else if ($this->comes('cm')) {
410-
$sUnit = $this->consume('cm');
411-
} else if ($this->comes('mm')) {
412-
$sUnit = $this->consume('mm');
390+
$units = array(
391+
'%', 'em', 'ex', 'px', 'deg', 's', 'cm', 'pt', 'in', 'pc', 'cm',
392+
'mm'
393+
);
394+
395+
foreach ($units as $val) {
396+
if ($this->comes($val)) {
397+
$sUnit = $this->consume($val);
398+
break;
399+
}
413400
}
401+
414402
return new Size($fSize, $sUnit, $bForColor);
415403
}
416404

0 commit comments

Comments
 (0)