PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.5.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.5.1
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / src / DonationForms / Rules / Min.php

Min.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.5.1, at src/DonationForms/Rules/Min.php

49 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Give\DonationForms\Rules;
3
4
5 use Closure;
6 use Give\Vendors\StellarWP\Validation\Config;
7
8 use function is_numeric;
9
10 class Min extends \Give\Vendors\StellarWP\Validation\Rules\Min
11 {
12 /**
13 * @since 3.0.0
14 */
15 public function sanitize($value)
16 {
17 if (is_numeric($value)) {
18 if (strpos($value, '.') !== false) {
19 return (float)$value;
20 }
21
22 return (int)$value;
23 }
24
25 return $value;
26 }
27
28 /**
29 * @inheritDoc
30 *
31 * @since 3.0.0
32 **/
33 public function __invoke($value, Closure $fail, string $key, array $values)
34 {
35 $value = $this->sanitize($value);
36
37 if (is_numeric($value)) {
38 if ($value < $this->getSize()) {
39 $fail(sprintf(__('%s must be greater than or equal to %s', 'give'), '{field}', $this->getSize()));
40 }
41 } elseif (is_string($value)) {
42 if (mb_strlen($value) < $this->getSize()) {
43 $fail(sprintf(__('%s must be more than or equal to %d characters', 'give'), '{field}', $this->getSize()));
44 }
45 } else {
46 Config::throwValidationException("Field value must be a number or string");
47 }
48 }
49 }