Debian Codegraph @

classes/Settings/SettingInteger.php

raw symbols SCIP
1 <?php
2
3 /**
4 * dmarc-srg - A php parser, viewer and summary report generator for incoming DMARC reports.
5 * Copyright (C) 2021 Aleksey Andreev (liuch)
6 *
7 * Available at:
8 * https://github.com/liuch/dmarc-srg
9 *
10 * This program is free software: you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation, either version 3 of the License.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 * =========================
23 *
24 * This file contains implementation of the class SettingInteger
25 *
26 * @category API
27 * @package DmarcSrg
28 * @author Aleksey Andreev (liuch)
29 * @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3
30 */
31
32 namespace Liuch\DmarcSrg\Settings;
33
34 /**
35 * It's a class for accessing to settings item data
36 *
37 * This class contains the implementation of the setting for integer values.
38 */
39 class SettingInteger extends Setting
40 {
41 /**
42 * Returns the type of the setting
43 *
44 * @return int Type of the setting
45 */
46 public function type(): int
47 {
48 return Setting::TYPE_INTEGER;
49 }
50
51 /**
52 * Checks if the value is correct
53 *
54 * @return bool True if the value is correct or false otherwise
55 */
56 protected function checkValue(): bool
57 {
58 if (gettype($this->value) === 'integer') {
59 $sch = &SettingsList::$schema[$this->name];
60 if (!isset($sch['minimum']) || $this->value >= $sch['minimum']) {
61 if (!isset($sch['maximum']) || $this->value <= $sch['maximum']) {
62 return true;
63 }
64 }
65 }
66 return false;
67 }
68
69 /**
70 * Converts a string to the value
71 *
72 * @param string $s String for conversion
73 *
74 * @return void
75 */
76 protected function stringToValue(string $s): void
77 {
78 $this->value = intval($s);
79 }
80
81 /**
82 * Returns a string representation of the value
83 *
84 * @return string The string value
85 */
86 protected function valueToString(): string
87 {
88 return strval($this->value);
89 }
90
91 /**
92 * Returns an array with setting data
93 *
94 * @return array Setting data
95 */
96 public function toArray(): array
97 {
98 $res = parent::toArray();
99 $sch = &SettingsList::$schema[$this->name];
100 if (isset($sch['minimum'])) {
101 $res['minimum'] = $sch['minimum'];
102 }
103 if (isset($sch['maximum'])) {
104 $res['maximum'] = $sch['maximum'];
105 }
106 return $res;
107 }
108 }