1212namespace chillerlan \Settings ;
1313
1414use chillerlan \Settings \Attributes \ThrowOnInvalidProperty ;
15- use InvalidArgumentException , JsonException , ReflectionException , ReflectionObject ,
15+ use InvalidArgumentException , JsonException , PropertyHookType , ReflectionException , ReflectionObject ,
1616 ReflectionProperty , ReflectionAttribute , RuntimeException ;
1717use function is_object , json_decode , json_encode , json_last_error_msg ,
1818 method_exists , property_exists , serialize , sprintf , unserialize ;
19- use const JSON_THROW_ON_ERROR , PHP_VERSION_ID ;
19+ use const JSON_THROW_ON_ERROR ;
2020
2121abstract class SettingsContainerAbstract implements SettingsContainerInterface{
2222
23- protected const SET_PREFIX = 'set_ ' ;
24- protected const GET_PREFIX = 'get_ ' ;
23+ protected const string SET_PREFIX = 'set_ ' ;
24+ protected const string GET_PREFIX = 'get_ ' ;
2525
2626 /**
2727 * SettingsContainerAbstract constructor.
@@ -42,7 +42,7 @@ public function __construct(iterable|null $properties = null){
4242 * (remember pre-php5 classname constructors? yeah, basically this.)
4343 */
4444 protected function construct ():void {
45- $ traits = ( new ReflectionObject ($ this ) )->getTraits ();
45+ $ traits = new ReflectionObject ($ this )->getTraits ();
4646
4747 foreach ($ traits as $ trait ){
4848 $ method = $ trait ->getShortName ();
@@ -109,44 +109,34 @@ public function __toString():string{
109109 }
110110
111111 /**
112- * @internal Checks if a property is private
112+ * Checks if a property is private
113113 */
114114 final protected function isPrivate (string $ property ):bool {
115- return ( new ReflectionProperty ($ this , $ property) )->isPrivate ();
115+ return new ReflectionProperty ($ this , $ property )->isPrivate ();
116116 }
117117
118118 /**
119- * @internal Checks if a property has a "set" hook
119+ * Checks if a property has a "set" hook
120120 */
121121 final protected function hasSetHook (string $ property ):bool {
122-
123- if (PHP_VERSION_ID < 80400 ){
124- return false ;
125- }
126- /** @phan-suppress-next-line PhanUndeclaredMethod, PhanUndeclaredClassConstant */
127- return (new ReflectionProperty ($ this , $ property ))->hasHook (\PropertyHookType::Set);
122+ return new ReflectionProperty ($ this , $ property )->hasHook (PropertyHookType::Set);
128123 }
129124
130125 /**
131- * @internal Checks if a property has a "get" hook
126+ * Checks if a property has a "get" hook
132127 */
133128 final protected function hasGetHook (string $ property ):bool {
134-
135- if (PHP_VERSION_ID < 80400 ){
136- return false ;
137- }
138- /** @phan-suppress-next-line PhanUndeclaredMethod, PhanUndeclaredClassConstant */
139- return (new ReflectionProperty ($ this , $ property ))->hasHook (\PropertyHookType::Get);
129+ return new ReflectionProperty ($ this , $ property )->hasHook (PropertyHookType::Get);
140130 }
141131
142132 /**
143- * @internal Checks for the attribute "ThrowOnInvalidProperty", used in the magic get/set
133+ * Checks for the attribute "ThrowOnInvalidProperty", used in the magic get/set
144134 *
145135 * @see \chillerlan\Settings\Attributes\ThrowOnInvalidProperty
146136 */
147137 final protected function throwOnInvalidProperty ():bool {
148138
149- $ attributes = ( new ReflectionObject ($ this ) )
139+ $ attributes = new ReflectionObject ($ this )
150140 ->getAttributes (ThrowOnInvalidProperty::class, ReflectionAttribute::IS_INSTANCEOF )
151141 ;
152142
@@ -161,7 +151,7 @@ final protected function throwOnInvalidProperty():bool{
161151
162152 public function toArray ():array {
163153
164- $ properties = ( new ReflectionObject ($ this ) )
154+ $ properties = new ReflectionObject ($ this )
165155 ->getProperties (~(ReflectionProperty::IS_STATIC | ReflectionProperty::IS_READONLY | ReflectionProperty::IS_PRIVATE ))
166156 ;
167157
@@ -240,10 +230,8 @@ public function unserialize(string $data):void{
240230 $ data = [];
241231
242232 foreach ($ properties as $ reflectionProperty ){
243- $ data [$ reflectionProperty ->name ] = (PHP_VERSION_ID < 80400 )
244- ? $ reflectionProperty ->getValue ($ obj )
245- /** @phan-suppress-next-line PhanUndeclaredMethod */
246- : $ reflectionProperty ->getRawValue ($ obj );
233+ // bypass existing property hooks
234+ $ data [$ reflectionProperty ->name ] = $ reflectionProperty ->getRawValue ($ obj );
247235 }
248236
249237 $ this ->__unserialize ($ data );
@@ -257,18 +245,15 @@ public function unserialize(string $data):void{
257245 */
258246 public function __serialize ():array {
259247
260- $ properties = ( new ReflectionObject ($ this ) )
248+ $ properties = new ReflectionObject ($ this )
261249 ->getProperties (~(ReflectionProperty::IS_STATIC | ReflectionProperty::IS_READONLY ))
262250 ;
263251
264252 $ data = [];
265253
266254 foreach ($ properties as $ reflectionProperty ){
267- // bypass existing property hooks for PHP >= 8.4
268- $ data [$ reflectionProperty ->name ] = (PHP_VERSION_ID < 80400 )
269- ? $ reflectionProperty ->getValue ($ this )
270- /** @phan-suppress-next-line PhanUndeclaredMethod */
271- : $ reflectionProperty ->getRawValue ($ this );
255+ // bypass existing property hooks
256+ $ data [$ reflectionProperty ->name ] = $ reflectionProperty ->getRawValue ($ this );
272257 }
273258
274259 return $ data ;
@@ -291,11 +276,8 @@ public function __unserialize(array $data):void{
291276 continue ; // @codeCoverageIgnore
292277 }
293278
294- (PHP_VERSION_ID < 80400 )
295- ? $ reflectionProperty ->setValue ($ this , $ value )
296- /** @phan-suppress-next-line PhanUndeclaredMethod */
297- : $ reflectionProperty ->setRawValue ($ this , $ value );
298-
279+ // bypass existing property hooks
280+ $ reflectionProperty ->setRawValue ($ this , $ value );
299281 }
300282 // @codeCoverageIgnoreStart
301283 catch (ReflectionException ){
0 commit comments