PluginProbe
MaxButtons – Create buttons / 6.28
MaxButtons – Create buttons v6.28
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
maxbuttons / assets / libraries / scssphp / src / Util.php

Util.php in MaxButtons – Create buttons 6.28, at assets/libraries/scssphp/src/Util.php

56 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * SCSSPHP
4 *
5 * @copyright 2012-2015 Leaf Corcoran
6 *
7 * @license http://opensource.org/licenses/MIT MIT
8 *
9 * @link http://leafo.github.io/scssphp
10 */
11
12 namespace Leafo\ScssPhp;
13
14 use Leafo\ScssPhp\Base\Range;
15
16 /**
17 * SCSS utilties
18 *
19 * @author Anthon Pang <anthon.pang@gmail.com>
20 */
21 class Util
22 {
23 /**
24 * Asserts that `value` falls within `range` (inclusive), leaving
25 * room for slight floating-point errors.
26 *
27 * @param string $name The name of the value. Used in the error message.
28 * @param Range $range Range of values.
29 * @param array $value The value to check.
30 * @param string $unit The unit of the value. Used in error reporting.
31 *
32 * @return mixed `value` adjusted to fall within range, if it was outside by a floating-point margin.
33 *
34 * @throws \Exception
35 */
36 public static function checkRange($name, Range $range, $value, $unit = '')
37 {
38 $val = $value[1];
39 $grace = new Range(-0.00001, 0.00001);
40
41 if ($range->includes($val)) {
42 return $val;
43 }
44
45 if ($grace->includes($val - $range->first)) {
46 return $range->first;
47 }
48
49 if ($grace->includes($val - $range->last)) {
50 return $range->last;
51 }
52
53 throw new \Exception("$name {$val} must be between {$range->first} and {$range->last}$unit");
54 }
55 }
56