class-any-of-schema.php
1 year ago
class-array-schema.php
1 year ago
class-boolean-schema.php
1 year ago
class-integer-schema.php
1 year ago
class-null-schema.php
1 year ago
class-number-schema.php
1 year ago
class-object-schema.php
1 year ago
class-one-of-schema.php
1 year ago
class-string-schema.php
1 year ago
class-integer-schema.php
76 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This file is part of the WooCommerce Email Editor package |
| 4 | * |
| 5 | * @package Automattic\WooCommerce\EmailEditor |
| 6 | */ |
| 7 | |
| 8 | declare( strict_types = 1 ); |
| 9 | namespace Automattic\WooCommerce\EmailEditor\Validator\Schema; |
| 10 | |
| 11 | use Automattic\WooCommerce\EmailEditor\Validator\Schema; |
| 12 | |
| 13 | /** |
| 14 | * Represents a schema for an integer. |
| 15 | * See: https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#numbers |
| 16 | */ |
| 17 | class Integer_Schema extends Schema { |
| 18 | /** |
| 19 | * Schema definition. |
| 20 | * |
| 21 | * @var array |
| 22 | */ |
| 23 | protected $schema = array( |
| 24 | 'type' => 'integer', |
| 25 | ); |
| 26 | |
| 27 | /** |
| 28 | * Sets the minimum value of the integer. |
| 29 | * |
| 30 | * @param int $value Minimum value of the integer. |
| 31 | */ |
| 32 | public function minimum( int $value ): self { |
| 33 | return $this->update_schema_property( 'minimum', $value ) |
| 34 | ->unset_schema_property( 'exclusiveMinimum' ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Sets the exclusiveMinimum property to true. |
| 39 | * |
| 40 | * @param int $value Minimum value of the integer. |
| 41 | */ |
| 42 | public function exclusiveMinimum( int $value ): self { |
| 43 | return $this->update_schema_property( 'minimum', $value ) |
| 44 | ->update_schema_property( 'exclusiveMinimum', true ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Sets the maximum value of the integer. |
| 49 | * |
| 50 | * @param int $value Maximum value of the integer. |
| 51 | */ |
| 52 | public function maximum( int $value ): self { |
| 53 | return $this->update_schema_property( 'maximum', $value ) |
| 54 | ->unset_schema_property( 'exclusiveMaximum' ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Sets the exclusiveMaximum property to true. |
| 59 | * |
| 60 | * @param int $value Maximum value of the integer. |
| 61 | */ |
| 62 | public function exclusiveMaximum( int $value ): self { |
| 63 | return $this->update_schema_property( 'maximum', $value ) |
| 64 | ->update_schema_property( 'exclusiveMaximum', true ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Sets the multipleOf property. |
| 69 | * |
| 70 | * @param int $value Multiple of the integer. |
| 71 | */ |
| 72 | public function multipleOf( int $value ): self { |
| 73 | return $this->update_schema_property( 'multipleOf', $value ); |
| 74 | } |
| 75 | } |
| 76 |