-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathInvalidValue.php
108 lines (96 loc) · 3.11 KB
/
InvalidValue.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Exception;
use LogicException;
defined( 'ABSPATH' ) || exit;
/**
* Class InvalidValue
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Exception
*/
class InvalidValue extends LogicException implements GoogleListingsAndAdsException {
/**
* Create a new instance of the exception when a value is not a positive integer.
*
* @param string $method The method that requires a positive integer.
*
* @return static
*/
public static function negative_integer( string $method ) {
return new static( sprintf( 'The method "%s" requires a positive integer value.', $method ) );
}
/**
* Create a new instance of the exception when a value is not a string.
*
* @param string $key The name of the value.
*
* @return static
*/
public static function not_string( string $key ) {
return new static( sprintf( 'The value of %s must be of type string.', $key ) );
}
/**
* Create a new instance of the exception when a value is not a string.
*
* @param string $key The name of the value.
*
* @return static
*/
public static function not_integer( string $key ): InvalidValue {
return new static( sprintf( 'The value of %s must be of type integer.', $key ) );
}
/**
* Create a new instance of the exception when a value is not an instance of a given class.
*
* @param string $class_name The name of the class that the value must be an instance of.
* @param string $key The name of the value.
*
* @return static
*/
public static function not_instance_of( string $class_name, string $key ) {
return new static( sprintf( 'The value of %s must be an instance of %s.', $key, $class_name ) );
}
/**
* Create a new instance of the exception when a value is empty.
*
* @param string $key The name of the value.
*
* @return static
*
* @since 1.2.0
*/
public static function is_empty( string $key ): InvalidValue {
return new static( sprintf( 'The value of %s can not be empty.', $key ) );
}
/**
* Create a new instance of the exception when a value is not from a predefined list of allowed values.
*
* @param mixed $key The name of the value.
* @param array $allowed_values The list of allowed values.
*
* @return static
*/
public static function not_in_allowed_list( $key, array $allowed_values ): InvalidValue {
return new static( sprintf( 'The value of %s must be either of [%s].', $key, implode( ', ', $allowed_values ) ) );
}
/**
* Create a new instance of the exception when a value isn't a valid coupon ID.
*
* @param mixed $value The provided coupon ID that isn't valid.
*
* @return static
*/
public static function not_valid_coupon_id( $value ): InvalidValue {
return new static( sprintf( 'Invalid coupon ID: %s', $value ) );
}
/**
* Create a new instance of the exception when a value isn't a valid product ID.
*
* @param mixed $value The provided product ID that isn't valid.
*
* @return static
*/
public static function not_valid_product_id( $value ): InvalidValue {
return new static( sprintf( 'Invalid product ID: %s', $value ) );
}
}