PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.3.4
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.3.4
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / includes / Helpers / BooleanHelper.php

BooleanHelper.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.3.4, at includes/Helpers/BooleanHelper.php

67 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Boolean Helper Class
4 *
5 * @package EasyInvoice
6 * @author Your Name
7 * @copyright Copyright (c) 2023, Your Company
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.0.0
10 */
11
12 namespace EasyInvoice\Helpers;
13
14 /**
15 * Boolean Helper
16 *
17 * Handles boolean value conversions and checks.
18 *
19 * @since 1.0.0
20 */
21 class BooleanHelper {
22
23 /**
24 * Convert various boolean values to a consistent boolean
25 *
26 * @since 1.0.0
27 * @param mixed $value The value to convert to boolean
28 * @return bool
29 */
30 public static function toBoolean($value): bool {
31 if (is_bool($value)) {
32 return $value;
33 }
34
35 if (is_string($value)) {
36 return in_array(strtolower($value), ['true', '1', 'yes', 'on'], true);
37 }
38
39 if (is_numeric($value)) {
40 return (bool) $value;
41 }
42
43 return false;
44 }
45
46 /**
47 * Check if a value represents a true boolean
48 *
49 * @since 1.0.0
50 * @param mixed $value The value to check
51 * @return bool
52 */
53 public static function isTrue($value): bool {
54 return self::toBoolean($value);
55 }
56
57 /**
58 * Check if a value represents a false boolean
59 *
60 * @since 1.0.0
61 * @param mixed $value The value to check
62 * @return bool
63 */
64 public static function isFalse($value): bool {
65 return !self::toBoolean($value);
66 }
67 }