Conditions | 7 |
Paths | 5 |
Total Lines | 23 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 5 |
CRAP Score | 22.9226 |
Changes | 0 |
1 | <?php |
||
16 | 3 | public function normalizeId($postId) |
|
17 | { |
||
18 | 3 | if ('parent_id' == $postId) { |
|
19 | $postId = wp_get_post_parent_id(intval(get_the_ID())); |
||
20 | } |
||
21 | 3 | elseif ('post_id' == $postId) { |
|
22 | $postId = get_the_ID(); |
||
23 | } |
||
24 | 3 | elseif (!is_numeric($postId) && is_string($postId)) { |
|
25 | $parts = explode(':', $postId); |
||
26 | $type = Arr::get($parts, 0); |
||
27 | $slug = Arr::get($parts, 1); |
||
28 | if (!empty($slug) && !empty($type)) { |
||
29 | $args = [ |
||
30 | 'fields' => 'ids', |
||
31 | 'post_name__in' => [$slug], |
||
32 | 'post_type' => $type, |
||
33 | 'posts_per_page' => 1, |
||
34 | ]; |
||
35 | $postId = Arr::get(get_posts($args), 0); |
||
36 | } |
||
37 | } |
||
38 | 3 | return Helper::getPostId($postId); |
|
39 | } |
||
54 |