| Conditions | 16 |
| Paths | 528 |
| Total Lines | 114 |
| Code Lines | 67 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 43 | function data_layer(): array |
||
| 44 | { |
||
| 45 | $dataLayer = []; |
||
| 46 | |||
| 47 | if (is_multisite()) { |
||
| 48 | $dataLayer['network'] = [ |
||
| 49 | 'id' => get_main_site_id(), |
||
| 50 | 'url' => get_site_url(get_main_site_id()), |
||
| 51 | ]; |
||
| 52 | } |
||
| 53 | |||
| 54 | $dataLayer['site'] = [ |
||
| 55 | 'id' => is_multisite() ? get_current_blog_id() : 0, |
||
| 56 | 'url' => home_url(), |
||
| 57 | ]; |
||
| 58 | |||
| 59 | $dataLayer['context'] = [ |
||
| 60 | 'is_home' => is_home(), |
||
| 61 | 'is_front_page' => is_front_page(), |
||
| 62 | 'is_post_type_archive' => is_post_type_archive(), |
||
| 63 | 'is_tax' => is_tax(), |
||
| 64 | 'is_author' => is_author(), |
||
| 65 | 'is_date' => is_date(), |
||
| 66 | 'is_search' => is_search(), |
||
| 67 | 'is_singular' => is_singular(), |
||
| 68 | 'is_404' => is_404(), |
||
| 69 | ]; |
||
| 70 | |||
| 71 | if (is_archive()) { |
||
| 72 | if (is_date()) { |
||
| 73 | $dataLayer['date'] = get_the_date(); |
||
| 74 | } |
||
| 75 | |||
| 76 | if (is_search()) { |
||
| 77 | $dataLayer['search'] = get_search_query(); |
||
| 78 | } |
||
| 79 | |||
| 80 | if (is_post_type_archive()) { |
||
| 81 | $dataLayer['post_type'] = get_post_type(); |
||
| 82 | } |
||
| 83 | |||
| 84 | if (is_tag() || is_category() || is_tax()) { |
||
| 85 | $term = get_queried_object(); |
||
| 86 | |||
| 87 | $dataLayer[$term->taxonomy] = [ |
||
| 88 | 'id' => $term->term_id, |
||
| 89 | 'slug' => $term->slug, |
||
| 90 | 'name' => $term->name, |
||
| 91 | ]; |
||
| 92 | } |
||
| 93 | |||
| 94 | if (is_author()) { |
||
| 95 | $user = get_queried_object(); |
||
| 96 | |||
| 97 | $dataLayer['author'] = [ |
||
| 98 | 'id' => $user->ID, |
||
| 99 | 'slug' => $user->user_nicename, |
||
| 100 | 'name' => $user->display_name, |
||
| 101 | ]; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | if (is_singular()) { |
||
| 106 | $dataLayer[get_post_type()] = [ |
||
| 107 | 'id' => get_the_ID(), |
||
| 108 | 'slug' => get_post_field('post_name'), |
||
| 109 | 'title' => get_the_title(), |
||
| 110 | 'template' => get_page_template_slug(), |
||
| 111 | 'comments' => (int)get_comments_number(), |
||
| 112 | 'published_at' => get_the_date('c'), |
||
| 113 | 'modified_at' => get_the_modified_date('c'), |
||
| 114 | ]; |
||
| 115 | |||
| 116 | $dataLayer[get_post_type()]['author'] = [ |
||
| 117 | 'id' => get_the_author_meta('ID'), |
||
| 118 | 'slug' => get_the_author_meta('user_nicename'), |
||
| 119 | 'name' => get_the_author_meta('display_name'), |
||
| 120 | ]; |
||
| 121 | |||
| 122 | $taxonomies = get_object_taxonomies(get_post_type(), 'objects'); |
||
| 123 | $taxonomies = array_filter($taxonomies, function (WP_Taxonomy $taxonomy) { |
||
| 124 | return $taxonomy->public; |
||
| 125 | }); |
||
| 126 | |||
| 127 | // TODO: ugly :( |
||
| 128 | foreach ($taxonomies as $taxonomy) { |
||
| 129 | $terms = get_the_terms(get_the_ID(), $taxonomy->name); |
||
| 130 | if (!$terms || is_wp_error($terms)) { |
||
| 131 | continue; |
||
| 132 | } |
||
| 133 | |||
| 134 | $dataLayer[get_post_type()][$taxonomy->name] = array_column($terms, 'slug'); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | if (is_user_logged_in()) { |
||
| 139 | $user = wp_get_current_user(); |
||
| 140 | |||
| 141 | $dataLayer['user'] = [ |
||
| 142 | 'id' => $user->ID, |
||
| 143 | 'slug' => $user->user_nicename, |
||
| 144 | 'name' => $user->display_name, |
||
| 145 | 'capabilities' => array_keys($user->caps), |
||
| 146 | ]; |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Control the data layer. |
||
| 151 | * |
||
| 152 | * @param array $dataLayer |
||
| 153 | */ |
||
| 154 | $dataLayer = apply_filters('helick_gtm_data_layer', $dataLayer); |
||
| 155 | |||
| 156 | return (array)$dataLayer; |
||
| 157 | } |
||
| 158 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths