PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.13
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.13
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / libraries / framework / Supports / Utils.php
kirki / libraries / framework / Supports Last commit date
Facades 3 weeks ago Traits 3 weeks ago Arr.php 3 weeks ago DataCaster.php 3 weeks ago Flex.php 3 weeks ago HigherOrderTapProxy.php 3 weeks ago MediaAttachment.php 3 weeks ago MessagesBag.php 3 weeks ago Str.php 3 weeks ago Url.php 3 weeks ago Utils.php 3 weeks ago
Utils.php
65 lines
1 <?php
2
3 /**
4 * Miscellaneous utility methods including UUID generation, growth percentage calculation, and float-to-int rounding.
5 * Wraps wp_generate_uuid4 and provides safe numeric helpers for reporting features.
6 * Stateless static helpers with no container dependencies.
7 *
8 * @package Framework
9 * @subpackage Supports
10 * @since 1.0.0
11 */
12 namespace Kirki\Framework\Supports;
13
14 \defined('ABSPATH') || exit;
15 class Utils
16 {
17 /**
18 * Calculates the percentage growth from the previous to the current value.
19 *
20 * @param mixed $current The current value.
21 * @param mixed $previous The previous value.
22 * @param int $precision The number of decimal places to round to. Defaults to 2.
23 *
24 * @return float The percentage growth.
25 *
26 * @since 1.0.0
27 */
28 public static function calculate_growth_in_percent($current, $previous, $precision = 2)
29 {
30 if (!\is_numeric($current) || !\is_numeric($previous)) {
31 return 0.0;
32 }
33 $current = \ctype_digit((string) $current) ? (int) $current : (float) $current;
34 $previous = \ctype_digit((string) $previous) ? (int) $previous : (float) $previous;
35 if ($previous === 0 || $previous === 0.0) {
36 return $current > 0 ? 100 : 0;
37 }
38 return \round(($current - $previous) / $previous * 100, $precision);
39 }
40 /**
41 * Generates a UUID.
42 *
43 * @return string The UUID.
44 *
45 * @since 1.0.0
46 */
47 public static function uuid()
48 {
49 return wp_generate_uuid4();
50 }
51 /**
52 * Converts a float to an integer by rounding up.
53 *
54 * @param float $value The float value to convert.
55 *
56 * @return int The rounded integer value.
57 *
58 * @since 1.0.0
59 */
60 public static function to_int($value)
61 {
62 return (int) \round($value, 0, \PHP_ROUND_HALF_UP);
63 }
64 }
65