|
7 | 7 | class Size extends PrimitiveValue |
8 | 8 | { |
9 | 9 |
|
10 | | - // vh/vw/vm(ax)/vmin/rem are absolute insofar as they don’t scale to the immediate parent (only the viewport) |
11 | | - const ABSOLUTE_SIZE_UNITS = 'px/cm/mm/mozmm/in/pt/pc/vh/vw/vmin/vmax/rem'; |
12 | | - const RELATIVE_SIZE_UNITS = '%/em/ex/ch/fr'; |
13 | | - const NON_SIZE_UNITS = 'deg/grad/rad/s/ms/turns/Hz/kHz'; |
| 10 | + /** |
| 11 | + * vh/vw/vm(ax)/vmin/rem are absolute insofar as they don’t scale to the immediate parent (only the viewport) |
| 12 | + * |
| 13 | + * @var array<int, string> |
| 14 | + */ |
| 15 | + const ABSOLUTE_SIZE_UNITS = ['px', 'cm', 'mm', 'mozmm', 'in', 'pt', 'pc', 'vh', 'vw', 'vmin', 'vmax', 'rem']; |
14 | 16 |
|
| 17 | + /** |
| 18 | + * @var array<int, string> |
| 19 | + */ |
| 20 | + const RELATIVE_SIZE_UNITS = ['%', 'em', 'ex', 'ch', 'fr']; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var array<int, string> |
| 24 | + */ |
| 25 | + const NON_SIZE_UNITS = ['deg', 'grad', 'rad', 's', 'ms', 'turns', 'Hz', 'kHz']; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var array<int, array<string, string>>|null |
| 29 | + */ |
15 | 30 | private static $SIZE_UNITS = null; |
16 | 31 |
|
17 | 32 | private $fSize; |
@@ -56,14 +71,14 @@ public static function parse(ParserState $oParserState, $bIsColorComponent = fal |
56 | 71 | return new Size((float)$sSize, $sUnit, $bIsColorComponent, $oParserState->currentLine()); |
57 | 72 | } |
58 | 73 |
|
| 74 | + /** |
| 75 | + * @return array<int, array<string, string>> |
| 76 | + */ |
59 | 77 | private static function getSizeUnits() |
60 | 78 | { |
61 | | - if (self::$SIZE_UNITS === null) { |
| 79 | + if (!is_array(self::$SIZE_UNITS)) { |
62 | 80 | self::$SIZE_UNITS = []; |
63 | | - foreach ( |
64 | | - explode('/', Size::ABSOLUTE_SIZE_UNITS . '/' . Size::RELATIVE_SIZE_UNITS . '/' . Size::NON_SIZE_UNITS) |
65 | | - as $val |
66 | | - ) { |
| 81 | + foreach (array_merge(self::ABSOLUTE_SIZE_UNITS, self::RELATIVE_SIZE_UNITS, self::NON_SIZE_UNITS) as $val) { |
67 | 82 | $iSize = strlen($val); |
68 | 83 | if (!isset(self::$SIZE_UNITS[$iSize])) { |
69 | 84 | self::$SIZE_UNITS[$iSize] = []; |
@@ -109,15 +124,15 @@ public function isColorComponent() |
109 | 124 | */ |
110 | 125 | public function isSize() |
111 | 126 | { |
112 | | - if (in_array($this->sUnit, explode('/', self::NON_SIZE_UNITS))) { |
| 127 | + if (in_array($this->sUnit, self::NON_SIZE_UNITS, true)) { |
113 | 128 | return false; |
114 | 129 | } |
115 | 130 | return !$this->isColorComponent(); |
116 | 131 | } |
117 | 132 |
|
118 | 133 | public function isRelative() |
119 | 134 | { |
120 | | - if (in_array($this->sUnit, explode('/', self::RELATIVE_SIZE_UNITS))) { |
| 135 | + if (in_array($this->sUnit, self::RELATIVE_SIZE_UNITS, true)) { |
121 | 136 | return true; |
122 | 137 | } |
123 | 138 | if ($this->sUnit === null && $this->fSize != 0) { |
|
0 commit comments