PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
← All changes | classes/class-wp_option.php +23 -19 1.12 → 3.4 View file →
@@ -9,13 +9,16 @@
9 9 * @author Tobias Bäthge
10 10 * @since 1.0.0
11 11 */
12 12
13 +declare(strict_types=1);
14 +
13 15 // Prohibit direct script loading.
14 16 defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
15 17
16 18 /**
17 19 * TablePress WP Option Wrapper class
20 + *
18 21 * @package TablePress
19 22 * @subpackage Classes
20 23 * @author Tobias Bäthge
21 24 * @since 1.0.0
@@ -25,19 +28,18 @@
25 28 /**
26 29 * Name/Key of the Option (in its location in the database).
27 30 *
28 31 * @since 1.0.0
29 - * @var string
30 32 */
31 - protected $option_name;
33 + protected string $option_name;
32 34
33 35 /**
34 36 * Current value of the option.
35 37 *
36 38 * @since 1.0.0
37 - * @var array
39 + * @var mixed[]
38 40 */
39 - protected $option_value;
41 + protected array $option_value;
40 42
41 43 /**
42 44 * Initialize with Option Name.
43 45 *
@@ -42,11 +44,13 @@
42 44 * Initialize with Option Name.
43 45 *
44 46 * @since 1.0.0
45 47 *
46 - * @param array $params {
48 + * @param array{option_name: string, default_value: mixed[]} $params {
49 + * An array of Option parameters.
50 + *
47 51 * @type string $option_name Name of the Option.
48 - * @type array $default_value Default values for the Option.
52 + * @type array $default_value Default values for the Option, as an array.
49 53 * }
50 54 */
51 55 public function __construct( array $params ) {
52 56 $this->option_name = $params['option_name'];
@@ -66,9 +70,9 @@
66 70 *
67 71 * @param string $name Name of the option to check.
68 72 * @return bool Whether the option is set.
69 73 */
70 - public function is_set( $name ) {
74 + public function is_set( string $name ): bool {
71 75 return isset( $this->option_value[ $name ] );
72 76 }
73 77
74 78 /**
@@ -75,13 +79,13 @@
75 79 * Get a single Option, or get all Options.
76 80 *
77 81 * @since 1.0.0
78 82 *
79 - * @param string|bool $name Optional. Name of a single option to get, or false for all options.
80 - * @param mixed $default_value Optional. Default value to return, if a single option $name does not exist.
81 - * @return mixed|array Value of the retrieved option $name or $default_value if it does not exist, or all options.
83 + * @param string|false $name Optional. Name of a single option to get, or false for all options.
84 + * @param mixed $default_value Optional. Default value to return, if a single option $name does not exist.
85 + * @return mixed Value of the retrieved option $name or $default_value if it does not exist, or all options.
82 86 */
83 - public function get( $name = false, $default_value = null ) {
87 + public function get( /* string|false */ $name = false, /* string|int|float|bool|array|null */ $default_value = null ) /* : string|int|float|bool|array|null */ {
84 88 if ( false === $name ) {
85 89 return $this->option_value;
86 90 }
87 91
@@ -97,14 +101,14 @@
97 101 * Update Option.
98 102 *
99 103 * @since 1.0.0
100 104 *
101 - * @param array $new_options New options (name => value).
105 + * @param array<string, mixed> $new_options New options (name => value).
102 106 * @return bool True on success, false on failure.
103 107 */
104 - public function update( array $new_options ) {
108 + public function update( array $new_options ): bool {
105 109 $this->option_value = $new_options;
106 - return $this->_update_option( $this->option_name, wp_json_encode( $this->option_value, TABLEPRESS_JSON_OPTIONS ) );
110 + return $this->_update_option( $this->option_name, wp_json_encode( $this->option_value, TABLEPRESS_JSON_OPTIONS ) ); // @phpstan-ignore argument.type
107 111 }
108 112
109 113 /**
110 114 * Delete Option.
@@ -112,13 +116,13 @@
112 116 * @since 1.0.0
113 117 *
114 118 * @return bool True on success, false on failure.
115 119 */
116 - public function delete() {
120 + public function delete(): bool {
117 121 return $this->_delete_option( $this->option_name );
118 122 }
119 123
120 - /**
124 + /*
121 125 * Internal functions mapping - This needs to be re-defined by child classes.
122 126 */
123 127
124 128 /**
@@ -129,9 +133,9 @@
129 133 * @param string $option_name Name of the WP Option.
130 134 * @param mixed $default_value Default value of the WP Option.
131 135 * @return mixed Current value of the WP Option, or $default_value if it does not exist.
132 136 */
133 - protected function _get_option( $option_name, $default_value ) {
137 + protected function _get_option( string $option_name, /* string|int|float|bool|array|null */ $default_value ) /* : string|int|float|bool|array|null */ {
134 138 return get_option( $option_name, $default_value );
135 139 }
136 140
137 141 /**
@@ -142,9 +146,9 @@
142 146 * @param string $option_name Name of the WP Option.
143 147 * @param string $new_value New value of the WP Option.
144 148 * @return bool True on success, false on failure.
145 149 */
146 - protected function _update_option( $option_name, $new_value ) {
150 + protected function _update_option( string $option_name, string $new_value ): bool {
147 151 return update_option( $option_name, $new_value );
148 152 }
149 153
150 154 /**
@@ -154,9 +158,9 @@
154 158 *
155 159 * @param string $option_name Name of the WP Option.
156 160 * @return bool True on success, false on failure.
157 161 */
158 - protected function _delete_option( $option_name ) {
162 + protected function _delete_option( string $option_name ): bool {
159 163 return delete_option( $option_name );
160 164 }
161 165
162 166 } // class TablePress_WP_Option