| 1 |
<?php |
| 2 |
/** |
| 3 |
* WCPOS sync read surface. |
| 4 |
* |
| 5 |
* @package WCPOS\WooCommercePOS\Sync |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WCPOS\WooCommercePOS\Sync; |
| 9 |
|
| 10 |
use WP_REST_Request; |
| 11 |
|
| 12 |
// phpcs:disable Squiz.Commenting, Generic.Commenting -- Ported lab documentation is preserved verbatim. |
| 13 |
|
| 14 |
/** |
| 15 |
* Shared clamped-int request-param reader (previously duplicated verbatim in |
| 16 |
* the changes and integrity controllers): absent/blank falls back to the |
| 17 |
* default, everything is clamped into [$min, $max]. |
| 18 |
*/ |
| 19 |
trait Request_Int_Param { |
| 20 |
private function int_param( WP_REST_Request $request, string $key, int $default, int $min, int $max ): int { |
| 21 |
$raw = $request->get_param( $key ); |
| 22 |
$value = ( null === $raw || '' === $raw ) ? $default : (int) $raw; |
| 23 |
|
| 24 |
return max( $min, min( $max, $value ) ); |
| 25 |
} |
| 26 |
} |
| 27 |
|