| Total Complexity | 9 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Coverage | 95.65% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class SanitizeUserEmail extends StringSanitizer |
||
| 8 | { |
||
| 9 | public array $args; |
||
| 10 | public $value; |
||
| 11 | public array $values; |
||
| 12 | |||
| 13 | 27 | public function __construct($value, array $args = [], array $values = []) |
|
| 14 | { |
||
| 15 | 27 | $args = array_pad($args, 2, ''); // minimum of 2 args |
|
| 16 | 27 | $this->args = $args; |
|
| 17 | 27 | $this->value = $this->userValue($value); |
|
| 18 | 27 | $this->values = $values; |
|
| 19 | } |
||
| 20 | |||
| 21 | 27 | public function run(): string |
|
| 22 | { |
||
| 23 | 27 | $value = $this->sanitizeValue($this->value()); // allow any valid email value |
|
| 24 | 27 | if (defined('WP_IMPORTING')) { |
|
| 25 | return $value; |
||
| 26 | } |
||
| 27 | 27 | if (!empty($value)) { |
|
| 28 | 19 | return $value; |
|
| 29 | } |
||
| 30 | 14 | $fallback = Cast::toString($this->args[0]); // try the fallback value |
|
| 31 | 14 | if ('current_user' === $fallback) { |
|
| 32 | 2 | $fallback = $this->userValue(wp_get_current_user()); |
|
| 33 | } |
||
| 34 | 14 | return $this->sanitizeValue($fallback); |
|
| 35 | } |
||
| 36 | |||
| 37 | 27 | protected function sanitizeValue(string $value): string |
|
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param mixed $user |
||
| 44 | */ |
||
| 45 | 27 | protected function userValue($user): string |
|
| 54 | } |
||
| 55 | } |
||
| 56 |