PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 3.1.4
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v3.1.4
3.1.4 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 All 93 releases
← All changes | base/support/optional.php +21 -26 1.5.13.1.4 View file →
@@ -1,13 +1,16 @@
1 1 <?php
2 2
3 3 namespace UltimateStoreKit\Base\Support;
4 4
5 +if (! defined('ABSPATH')) {
6 + exit; // Exit if accessed directly
7 +}
8 +
5 9 use ArrayAccess;
6 10 use ArrayObject;
7 11
8 -class Optional implements ArrayAccess
9 -{
12 +class Optional implements ArrayAccess {
10 13 /**
11 14 * The underlying object.
12 15 *
13 16 * @var mixed
@@ -19,10 +22,9 @@
19 22 *
20 23 * @param mixed $value
21 24 * @return void
22 25 */
23 - public function __construct($value)
24 - {
26 + public function __construct($value) {
25 27 $this->value = $value;
26 28 }
27 29
28 30 /**
@@ -30,10 +32,9 @@
30 32 *
31 33 * @param string $key
32 34 * @return mixed
33 35 */
34 - public function __get($key)
35 - {
36 + public function __get($key) {
36 37 if (is_object($this->value)) {
37 38 return isset($this->value->{$key}) ? $this->value->{$key} : null;
38 39 }
39 40 }
@@ -43,10 +44,9 @@
43 44 *
44 45 * @param mixed $name
45 46 * @return bool
46 47 */
47 - public function __isset($name)
48 - {
48 + public function __isset($name) {
49 49 if (is_object($this->value)) {
50 50 return isset($this->value->{$name});
51 51 }
52 52
@@ -62,20 +62,18 @@
62 62 *
63 63 * @param mixed $key
64 64 * @return bool
65 65 */
66 - public function offsetExists($key)
67 - {
66 + #[\ReturnTypeWillChange]
67 + public function offsetExists($key): bool {
68 68 return $this->accessible($this->value) && $this->exists($this->value, $key);
69 69 }
70 70
71 - protected function accessible($value)
72 - {
71 + protected function accessible($value) {
73 72 return is_array($value) || $value instanceof ArrayAccess;
74 73 }
75 74
76 - protected function exists($array, $key)
77 - {
75 + protected function exists($array, $key) {
78 76 if ($array instanceof ArrayAccess) {
79 77 return $array->offsetExists($key);
80 78 }
81 79
@@ -87,16 +85,16 @@
87 85 *
88 86 * @param mixed $key
89 87 * @return mixed
90 88 */
91 - public function offsetGet($key)
92 - {
89 + #[\ReturnTypeWillChange]
90 + public function offsetGet($key) {
93 91 return $this->get($this->value, $key);
94 92 }
95 93
96 - protected function get($array, $key, $default = null)
97 - {
98 - if (! $this->accessible($array)) {
94 +
95 + protected function get($array, $key, $default = null) {
96 + if (!$this->accessible($array)) {
99 97 return $this->value($default);
100 98 }
101 99
102 100 if (is_null($key)) {
@@ -121,11 +119,10 @@
121 119
122 120 return $array;
123 121 }
124 122
125 - protected function value($value)
126 - {
127 - return $value instanceof Closure ? $value() : $value;
123 + protected function value($value) {
124 + return $value instanceof \Closure ? $value() : $value;
128 125 }
129 126
130 127 /**
131 128 * Set the item at a given offset.
@@ -133,10 +130,9 @@
133 130 * @param mixed $key
134 131 * @param mixed $value
135 132 * @return void
136 133 */
137 - public function offsetSet($key, $value): void
138 - {
134 + public function offsetSet($key, $value): void {
139 135 if ($this->accessible($this->value)) {
140 136 $this->value[$key] = $value;
141 137 }
142 138 }
@@ -146,10 +142,9 @@
146 142 *
147 143 * @param string $key
148 144 * @return void
149 145 */
150 - public function offsetUnset($key): void
151 - {
146 + public function offsetUnset($key): void {
152 147 if ($this->accessible($this->value)) {
153 148 unset($this->value[$key]);
154 149 }
155 150 }