| @@ -1,5 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * BooleanParameter.php | |
| 4 | + * | |
| 5 | + * The BooleanParameter class file. | |
| 6 | + * | |
| 7 | + * PHP versions 5 | |
| 8 | + * | |
| 9 | + * @author Alexander Schneider <alexanderschneider85@gmail.com> | |
| 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 | + */ | |
| 2 | 15 | |
| 3 | 16 | declare(strict_types=1); |
| 4 | 17 | |
| 5 | 18 | namespace UserAccessManager\Config; |
| @@ -5,11 +18,18 @@ | ||
| 5 | 18 | namespace UserAccessManager\Config; |
| 6 | 19 | |
| 7 | 20 | use Exception; |
| 8 | 21 | |
| 22 | +/** | |
| 23 | + * Class BooleanConfigParameter | |
| 24 | + * @package UserAccessManager\Config | |
| 25 | + */ | |
| 9 | 26 | class BooleanConfigParameter extends ConfigParameter |
| 10 | 27 | { |
| 11 | 28 | /** |
| 29 | + * BooleanConfigParameter constructor. | |
| 30 | + * @param string $id | |
| 31 | + * @param bool $defaultValue | |
| 12 | 32 | * @throws Exception |
| 13 | 33 | */ |
| 14 | 34 | public function __construct(string $id, $defaultValue = false) |
| 15 | 35 | { |
| @@ -15,13 +35,18 @@ | ||
| 15 | 35 | { |
| 16 | 36 | parent::__construct($id, $defaultValue); |
| 17 | 37 | } |
| 18 | 38 | |
| 19 | - private function valueToBoolConverter(mixed $value): mixed | |
| 39 | + /** | |
| 40 | + * Legacy converter for legacy values. | |
| 41 | + * @param mixed $value | |
| 42 | + * @return bool|string | |
| 43 | + */ | |
| 44 | + private function stringToBoolConverter($value) | |
| 20 | 45 | { |
| 21 | - if (in_array($value, [1, '1', 'true'])) { | |
| 46 | + if ($value === 'true') { | |
| 22 | 47 | $value = true; |
| 23 | - } elseif (in_array($value, [0, '0', 'false'])) { | |
| 48 | + } elseif ($value === 'false') { | |
| 24 | 49 | $value = false; |
| 25 | 50 | } |
| 26 | 51 | |
| 27 | 52 | return $value; |
| @@ -26,15 +51,24 @@ | ||
| 26 | 51 | |
| 27 | 52 | return $value; |
| 28 | 53 | } |
| 29 | 54 | |
| 30 | - public function setValue(mixed $value): void | |
| 55 | + /** | |
| 56 | + * Legacy wrapper for old config values. | |
| 57 | + * @param mixed $value | |
| 58 | + */ | |
| 59 | + public function setValue($value) | |
| 31 | 60 | { |
| 32 | - $value = (bool) $this->valueToBoolConverter($value); | |
| 61 | + $value = (bool) $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 | + * @param mixed $value | |
| 68 | + * @return bool | |
| 69 | + */ | |
| 70 | + public function isValidValue($value): bool | |
| 37 | 71 | { |
| 38 | 72 | return is_bool($value) === true; |
| 39 | 73 | } |
| 40 | 74 | } |