| Total Complexity | 5 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Coverage | 94.12% |
| Changes | 3 | ||
| Bugs | 2 | Features | 0 |
| 1 | <?php |
||
| 5 | class SanitizeUserName extends StringSanitizer |
||
| 6 | { |
||
| 7 | 26 | public function run(): string |
|
| 8 | { |
||
| 9 | 26 | $value = $this->sanitizeDisplayName($this->value()); |
|
| 10 | 26 | if (defined('WP_IMPORTING')) { |
|
| 11 | return $value; |
||
| 12 | } |
||
| 13 | 26 | if (!empty($value)) { |
|
| 14 | 22 | return $value; |
|
| 15 | } |
||
| 16 | 9 | $user = wp_get_current_user(); |
|
| 17 | 9 | if (!$user->exists()) { |
|
| 18 | 9 | return $value; |
|
| 19 | } |
||
| 20 | 2 | return $this->sanitizeDisplayName($user->display_name); |
|
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * \p{L} = any kind of letter from any language. |
||
| 25 | * \p{M} = any character intended to be combined with another character (e.g. accents, umlauts, enclosing boxes, etc.). |
||
| 26 | * \p{N} = any kind of numeric character in any script. |
||
| 27 | * \p{Pf} = any kind of closing quote. |
||
| 28 | * @see https://www.regular-expressions.info/unicode.html |
||
| 29 | */ |
||
| 30 | 26 | protected function sanitizeDisplayName(string $value): string |
|
| 38 | } |
||
| 39 | } |
||
| 40 |