PluginProbe
User Access Manager / 2.1.11
User Access Manager v2.1.11
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/Config/BooleanConfigParameter.php +49 -13 2.3.16 → 2.1.11 View file →
@@ -1,27 +1,51 @@
1 1 <?php
2 -
3 -declare(strict_types=1);
4 -
2 +/**
3 + * BooleanParameter.php
4 + *
5 + * The BooleanParameter class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <[email protected]>
10 + * @copyright 2008-2017 Alexander Schneider
11 + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 + * @version SVN: $id$
13 + * @link http://wordpress.org/extend/plugins/user-access-manager/
14 + */
5 15 namespace UserAccessManager\Config;
6 16
7 -use Exception;
8 -
17 +/**
18 + * Class BooleanConfigParameter
19 + * @package UserAccessManager\Config
20 + */
9 21 class BooleanConfigParameter extends ConfigParameter
10 22 {
11 23 /**
12 - * @throws Exception
24 + * BooleanConfigParameter constructor.
25 + *
26 + * @param string $id
27 + * @param bool $defaultValue
28 + *
29 + * @throws \Exception
13 30 */
14 - public function __construct(string $id, $defaultValue = false)
31 + public function __construct($id, $defaultValue = false)
15 32 {
16 33 parent::__construct($id, $defaultValue);
17 34 }
18 35
19 - private function valueToBoolConverter(mixed $value): mixed
36 + /**
37 + * Legacy converter for legacy values.
38 + *
39 + * @param $value
40 + *
41 + * @return bool
42 + */
43 + private function stringToBoolConverter($value)
20 44 {
21 - if (in_array($value, [1, '1', 'true'], true)) {
45 + if ($value === 'true') {
22 46 $value = true;
23 - } elseif (in_array($value, [0, '0', 'false'], true)) {
47 + } elseif ($value === 'false') {
24 48 $value = false;
25 49 }
26 50
27 51 return $value;
@@ -26,15 +50,27 @@
26 50
27 51 return $value;
28 52 }
29 53
30 - public function setValue(mixed $value): void
54 + /**
55 + * Legacy wrapper for old config values.
56 + *
57 + * @param mixed $value
58 + */
59 + public function setValue($value)
31 60 {
32 - $value = (bool) $this->valueToBoolConverter($value);
61 + $value = $this->stringToBoolConverter($value);
33 62 parent::setValue($value);
34 63 }
35 64
36 - public function isValidValue(mixed $value): bool
65 + /**
66 + * Checks if the given value is bool.
67 + *
68 + * @param mixed $value
69 + *
70 + * @return bool
71 + */
72 + public function isValidValue($value)
37 73 {
38 74 return is_bool($value) === true;
39 75 }
40 76 }