@@ -62,6 +62,26 @@ class SubSet extends AbstractSet
6262 */
6363 private $ set ;
6464
65+ /**
66+ * Get the underlying map as a SubMap
67+ *
68+ * @throws RuntimeException If the underlying map is not a SubMap
69+ *
70+ * @return SubMap The underlying sub map
71+ *
72+ * @since 1.0.0
73+ */
74+ private function getSubMap ()
75+ {
76+ $ map = $ this ->getMap ();
77+
78+ if (!$ map instanceof SubMap) {
79+ throw new \RuntimeException ('Unexpected map type ' );
80+ }
81+
82+ return $ map ;
83+ }
84+
6585 /**
6686 * Magic get method
6787 *
@@ -73,15 +93,17 @@ class SubSet extends AbstractSet
7393 */
7494 public function __get ($ property )
7595 {
96+ $ map = $ this ->getSubMap ();
97+
7698 switch ($ property ) {
7799 case 'from ' :
78- return $ this -> getMap () ->fromKey ;
100+ return $ map ->fromKey ;
79101 case 'to ' :
80- return $ this -> getMap () ->toKey ;
102+ return $ map ->toKey ;
81103 case 'fromInclusive ' :
82- return $ this -> getMap () ->fromInclusive ;
104+ return $ map ->fromInclusive ;
83105 case 'toInclusive ' :
84- return $ this -> getMap () ->toInclusive ;
106+ return $ map ->toInclusive ;
85107 case 'set ' :
86108 return $ this ->set ;
87109 default :
@@ -103,18 +125,20 @@ public function __get($property)
103125 */
104126 public function __set ($ property , $ value )
105127 {
128+ $ map = $ this ->getSubMap ();
129+
106130 switch ($ property ) {
107131 case 'from ' :
108- $ this -> getMap () ->fromKey = $ value ;
132+ $ map ->fromKey = $ value ;
109133 break ;
110134 case 'to ' :
111- $ this -> getMap () ->toKey = $ value ;
135+ $ map ->toKey = $ value ;
112136 break ;
113137 case 'fromInclusive ' :
114- $ this -> getMap () ->fromInclusive = $ value ;
138+ $ map ->fromInclusive = $ value ;
115139 break ;
116140 case 'toInclusive ' :
117- $ this -> getMap () ->toInclusive = $ value ;
141+ $ map ->toInclusive = $ value ;
118142 break ;
119143 default :
120144 throw new \RuntimeException ('Undefined property ' );
@@ -134,18 +158,20 @@ public function __set($property, $value)
134158 */
135159 public function __unset ($ property )
136160 {
161+ $ map = $ this ->getSubMap ();
162+
137163 switch ($ property ) {
138164 case 'from ' :
139- unset($ this -> getMap () ->fromKey );
165+ unset($ map ->fromKey );
140166 break ;
141167 case 'to ' :
142- unset($ this -> getMap () ->toKey );
168+ unset($ map ->toKey );
143169 break ;
144170 case 'fromInclusive ' :
145- unset($ this -> getMap () ->fromInclusive );
171+ unset($ map ->fromInclusive );
146172 break ;
147173 case 'toInclusive ' :
148- unset($ this -> getMap () ->toInclusive );
174+ unset($ map ->toInclusive );
149175 break ;
150176 default :
151177 throw new \RuntimeException ('Undefined property ' );
@@ -163,15 +189,17 @@ public function __unset($property)
163189 */
164190 public function __isset ($ property )
165191 {
192+ $ map = $ this ->getSubMap ();
193+
166194 switch ($ property ) {
167195 case 'from ' :
168- return isset ($ this -> getMap () ->fromKey );
196+ return isset ($ map ->fromKey );
169197 case 'to ' :
170- return isset ($ this -> getMap () ->toKey );
198+ return isset ($ map ->toKey );
171199 case 'fromInclusive ' :
172- return isset ($ this -> getMap () ->fromInclusive );
200+ return isset ($ map ->fromInclusive );
173201 case 'toInclusive ' :
174- return isset ($ this -> getMap () ->toInclusive );
202+ return isset ($ map ->toInclusive );
175203 default :
176204 return false ;
177205 }
0 commit comments