2525 * $rule = new Currency();
2626 * // Validates: USD, EUR, JPY, GBP, etc.
2727 *
28- * @example Custom codes only :
28+ * @example Custom codes with defaults (default behavior) :
2929 * $rule = new Currency(['BTC', 'ETH', 'XRP']);
30- * // Validates: BTC, ETH, XRP only
30+ * // Validates: BTC, ETH, XRP, USD, EUR, JPY, etc.
3131 *
32- * @example Custom codes with ISO codes :
32+ * @example Custom codes only (override defaults) :
3333 * $rule = new Currency(['BTC', 'ETH'], true);
34- * // Validates: BTC, ETH, USD, EUR, JPY, etc.
34+ * // Validates: BTC, ETH only ( USD, EUR, etc. will fail)
3535 *
3636 * @example String configuration:
37- * $rule = Currency::fromString('BTC,ETH,XRP|include_defaults ');
38- * // Validates: BTC, ETH, XRP, USD, EUR, JPY, etc.
37+ * $rule = Currency::fromString('BTC,ETH,XRP|override_defaults ');
38+ * // Validates: BTC, ETH, XRP only ( USD, EUR, etc. will fail)
3939 *
4040 * @since 1.0.0
4141 */
@@ -49,43 +49,43 @@ class Currency implements ValidationRule, ValidatesOnFrontEnd
4949 /**
5050 * Creates a new Currency validation rule.
5151 *
52- * @unreleased Added $includeDefaultCurrencyCodes parameter for enhanced flexibility.
52+ * @unreleased Added $overrideDefaultCurrencyCodes parameter for enhanced flexibility.
5353 *
5454 * This rule validates that a value is a valid 3-letter currency code (case-insensitive).
5555 * By default, it uses the complete list of ISO 4217 currency codes plus some commonly
5656 * used non-ISO codes like GGP, IMP, JEP, and TVD.
5757 *
5858 * @param array|null $currencyCodes Optional array of custom currency codes to validate against.
5959 * If null or empty, uses default ISO 4217 codes.
60- * @param bool $includeDefaultCurrencyCodes Whether to merge custom codes with default ISO codes .
61- * Only applies when $currencyCodes is provided and not empty.
62- * Default: false (use only custom codes).
60+ * @param bool $overrideDefaultCurrencyCodes Whether to use ONLY custom codes (excluding defaults) .
61+ * Only applies when $currencyCodes is provided and not empty.
62+ * Default: false (merge custom codes with defaults ).
6363 *
6464 * @example
6565 * // Use default ISO 4217 codes only
6666 * $rule = new Currency();
6767 * // Validates: USD, EUR, JPY, GBP, etc.
6868 *
6969 * @example
70- * // Use only custom currency codes
70+ * // Use custom codes merged with default ISO codes (default behavior)
7171 * $rule = new Currency(['BTC', 'ETH', 'XRP']);
72- * // Validates: BTC, ETH, XRP only (ISO codes will fail)
72+ * // Validates: BTC, ETH, XRP, USD, EUR, JPY, GBP, etc.
7373 *
7474 * @example
75- * // Use custom codes AND default ISO codes
75+ * // Use ONLY custom codes (override/exclude defaults)
7676 * $rule = new Currency(['BTC', 'ETH', 'XRP'], true);
77- * // Validates: BTC, ETH, XRP, USD, EUR, JPY, GBP, etc.
77+ * // Validates: BTC, ETH, XRP only (ISO codes will fail)
7878 *
7979 * @since 1.0.0
8080 */
81- public function __construct (?array $ currencyCodes = null , bool $ includeDefaultCurrencyCodes = false )
81+ public function __construct (?array $ currencyCodes = null , bool $ overrideDefaultCurrencyCodes = false )
8282 {
8383 if (empty ($ currencyCodes )) {
8484 $ this ->currencyCodes = self ::defaultCurrencyCodes ();
85- } elseif ($ includeDefaultCurrencyCodes ) {
86- $ this ->currencyCodes = array_merge (self ::defaultCurrencyCodes (), $ currencyCodes );
87- } else {
85+ } elseif ($ overrideDefaultCurrencyCodes ) {
8886 $ this ->currencyCodes = $ currencyCodes ;
87+ } else {
88+ $ this ->currencyCodes = array_merge (self ::defaultCurrencyCodes (), $ currencyCodes );
8989 }
9090 }
9191
@@ -104,17 +104,17 @@ public static function id(): string
104104 *
105105 * @inheritDoc
106106 *
107- * @unreleased Enhanced to support include_defaults syntax for merging custom codes with ISO codes .
107+ * @unreleased Enhanced to support override_defaults syntax for controlling default code inclusion .
108108 *
109109 * The options string can contain:
110110 * - Empty/null: Uses default ISO 4217 currency codes
111- * - Comma-separated codes: Uses only the specified custom codes
112- * - Codes with "|include_defaults ": Uses custom codes plus default ISO codes
111+ * - Comma-separated codes: Uses custom codes merged with default ISO codes
112+ * - Codes with "|override_defaults ": Uses ONLY custom codes (excludes defaults)
113113 *
114114 * @param string|null $options Configuration string in one of these formats:
115115 * - null or empty: Use default ISO codes
116- * - "BTC,ETH,XRP": Use only custom codes
117- * - "BTC,ETH,XRP|include_defaults ": Use custom + ISO codes
116+ * - "BTC,ETH,XRP": Use custom + default ISO codes
117+ * - "BTC,ETH,XRP|override_defaults ": Use only custom codes
118118 *
119119 * @return ValidationRule A configured Currency validation rule instance.
120120 *
@@ -125,19 +125,19 @@ public static function id(): string
125125 * // Validates: USD, EUR, JPY, GBP, etc.
126126 *
127127 * @example
128- * // Use only custom cryptocurrency codes
128+ * // Use custom codes merged with default ISO codes (default behavior)
129129 * $rule = Currency::fromString('BTC,ETH,XRP,ADA');
130- * // Validates: BTC, ETH, XRP, ADA only (ISO codes will fail)
130+ * // Validates: BTC, ETH, XRP, ADA, USD, EUR, JPY, GBP, etc.
131131 *
132132 * @example
133- * // Use custom codes plus all default ISO codes
134- * $rule = Currency::fromString('BTC,ETH,XRP|include_defaults ');
135- * // Validates: BTC, ETH, XRP, USD, EUR, JPY, GBP, etc.
133+ * // Use ONLY custom codes (override/exclude defaults)
134+ * $rule = Currency::fromString('BTC,ETH,XRP|override_defaults ');
135+ * // Validates: BTC, ETH, XRP only (ISO codes will fail)
136136 *
137137 * @example
138- * // Single custom code with defaults
139- * $rule = Currency::fromString('GOLD|include_defaults ');
140- * // Validates: GOLD, USD, EUR, JPY, GBP, etc.
138+ * // Single custom code, excluding defaults
139+ * $rule = Currency::fromString('GOLD|override_defaults ');
140+ * // Validates: GOLD only ( USD, EUR, etc. will fail)
141141 *
142142 * @since 1.0.0
143143 */
@@ -149,7 +149,7 @@ public static function fromString(string $options = null): ValidationRule
149149
150150 $ parts = explode ('| ' , $ options , 2 );
151151 $ currencyCodes = explode (', ' , $ parts [0 ]);
152- $ includeDefaults = isset ($ parts [1 ]) && strtolower (trim ($ parts [1 ])) === 'include_defaults ' ;
152+ $ includeDefaults = isset ($ parts [1 ]) && strtolower (trim ($ parts [1 ])) === 'override_defaults ' ;
153153
154154 return new static ($ currencyCodes , $ includeDefaults );
155155 }
0 commit comments