| Conditions | 9 |
| Paths | 9 |
| Total Lines | 22 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 9 |
| Changes | 0 | ||
| 1 | <?php |
||
| 36 | 20 | protected function userValue($value): int |
|
| 37 | { |
||
| 38 | 20 | if (empty($value)) { |
|
| 39 | 20 | return 0; |
|
| 40 | } |
||
| 41 | 19 | if ($value instanceof \WP_User) { |
|
| 42 | 18 | return $value->ID; |
|
| 43 | } |
||
| 44 | 2 | if ('user_id' === $value) { |
|
| 45 | 1 | if (!defined('WP_IMPORTING')) { |
|
| 46 | 1 | return get_current_user_id(); |
|
| 47 | } |
||
| 48 | 2 | } elseif (is_numeric($value)) { |
|
| 49 | 2 | if ($user = get_user_by('id', $value)) { |
|
| 50 | 2 | return $user->ID; |
|
| 51 | } |
||
| 52 | 1 | } elseif (is_string($value)) { |
|
| 53 | 1 | if ($user = get_user_by('login', sanitize_user($value, true))) { |
|
| 54 | 1 | return $user->ID; |
|
| 55 | } |
||
| 56 | } |
||
| 57 | 1 | return 0; |
|
| 58 | } |
||
| 60 |