| 1 |
<?php |
| 2 |
/** |
| 3 |
* WCPOS sync meta entry adapter. |
| 4 |
* |
| 5 |
* @package WCPOS\WooCommercePOS\Sync |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WCPOS\WooCommercePOS\Sync; |
| 9 |
|
| 10 |
/** |
| 11 |
* Reads array and object forms of WooCommerce meta entries. |
| 12 |
*/ |
| 13 |
final class Meta_Entry { |
| 14 |
/** |
| 15 |
* Read a meta entry key. |
| 16 |
* |
| 17 |
* Returns the raw key without coercion. A malformed entry can carry a |
| 18 |
* non-scalar key (an array, from a client that sent the wrong shape), and |
| 19 |
* callers are responsible for their own tolerance — Pos_Order_Audit gates |
| 20 |
* on is_scalar(), the comparison sites use strict === against a string. |
| 21 |
* Declaring ?string here would fatal before those guards could run. |
| 22 |
* |
| 23 |
* @param mixed $entry WooCommerce meta entry. |
| 24 |
* @return mixed |
| 25 |
*/ |
| 26 |
public static function key( $entry ) { |
| 27 |
return \is_array( $entry ) ? ( $entry['key'] ?? null ) : ( \is_object( $entry ) ? ( $entry->key ?? null ) : null ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Read a meta entry value. |
| 32 |
* |
| 33 |
* @param mixed $entry WooCommerce meta entry. |
| 34 |
* @return mixed |
| 35 |
*/ |
| 36 |
public static function value( $entry ) { |
| 37 |
return \is_array( $entry ) ? ( $entry['value'] ?? null ) : ( \is_object( $entry ) ? ( $entry->value ?? null ) : null ); |
| 38 |
} |
| 39 |
} |
| 40 |
|