Passed
Push — master ( f31715...0e6aca )
by Amit
02:30
created

enqueue-scripts.php ➔ podium_scripts()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 64
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 31
nc 4
nop 0
dl 0
loc 64
rs 8.6346
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 23 and the first side effect is on line 88.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * WordPress.com-specific functions and definitions.
4
 *
5
 * This file is centrally included from `wp-content/mu-plugins/wpcom-theme-compat.php`.
6
 *
7
 * @package podium
8
 */
9
10
// function podium_scripts()
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
11
// {
12
13
//     wp_enqueue_style('podium-style', get_stylesheet_directory_uri() . '/dist/styles/main.css', false, null);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
14
//     wp_enqueue_script('podium-scripts', get_stylesheet_directory_uri() . '/dist/scripts/main.js', ['jquery'], null, true);
15
16
//     if (is_singular() && comments_open() && get_option('thread_comments')) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
17
18
//         wp_enqueue_script('comment-reply');
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
19
20
//     }
21
22
// }
23
function podium_scripts()
24
{
25
26
    if (WP_ENV === 'production') {
27
        wp_enqueue_style(
28
            'podium-style',
29
            get_stylesheet_directory_uri() . '/dist/styles/main.min.css',
30
            false,
31
            null
32
        );
33
        wp_enqueue_script(
34
            'podium-scripts',
35
            get_stylesheet_directory_uri() . '/dist/scripts/main.min.js',
36
            null,
37
            null,
38
            true
39
        );
40
    } else {
41
        wp_enqueue_style(
42
            'podium-style',
43
            get_stylesheet_directory_uri() . '/dist/styles/main.css',
44
            false,
45
            null
46
        );
47
        wp_enqueue_script(
48
            'podium-scripts',
49
            get_stylesheet_directory_uri() . '/dist/scripts/main.js',
50
            null,
51
            null,
52
            true
53
        );
54
    }
55
56
// Add resources for individual page templates
57
    // if (is_page_template('page-contact.php')) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
58
59
    //     wp_enqueue_script(
60
    //         'contact-page-script',
61
    //         get_stylesheet_directory_uri() . '/dist/scripts/contact-page.js',
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
62
    //         ['jquery'],
63
    //         false,
64
    //         true
65
    //     );
66
    //     wp_enqueue_script(
67
    //         'google-recapcha-script',
68
    //         '//www.google.com/recaptcha/api.js?hl='.pll_current_language(),
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
69
    //         ['contact-page-script'],
70
    //         false,
71
    //         true
72
    //     );
73
74
    // }
75
76
    //remove emoji scripts
77
    remove_action('wp_head', 'print_emoji_detection_script', 7);
78
    remove_action('admin_print_scripts', 'print_emoji_detection_script');
79
    remove_action('wp_print_styles', 'print_emoji_styles');
80
    remove_action('admin_print_styles', 'print_emoji_styles');
81
82
    if (is_singular() && comments_open() && get_option('thread_comments')) {
83
        wp_enqueue_script('comment-reply');
84
    }
85
86
}
87
88
add_action('wp_enqueue_scripts', 'podium_scripts');
89
90
// Defer scripts
91
/**
92
 * @param  $tag
93
 * @param  $handle
94
 * @return mixed
95
 */
96
function podium_add_defer_attribute($tag, $handle)
97
{
98
99
    // add script handles to the array below
100
    $scripts_to_defer = [
101
        'podium-scripts'
102
        //  'more-js-handled'
103
    ];
104
105
    foreach ($scripts_to_defer as $defer_script) {
106
107
        if ($defer_script === $handle) {
108
109
            return str_replace(' src', ' defer="defer" src', $tag);
110
111
        }
112
113
    }
114
115
    return $tag;
116
}
117
118
add_filter('script_loader_tag', 'podium_add_defer_attribute', 10, 2);
119
120
// Async scripts
121
/**
122
 * @param  $tag
123
 * @param  $handle
124
 * @return mixed
125
 */
126
function podium_add_async_attribute($tag, $handle)
127
{
128
    // add script handles to the array below
129
    $scripts_to_async = [
130
131
//  'my-js-handle',
132
        //  'more-js-handled'
133
    ];
134
135
    foreach ($scripts_to_async as $async_script) {
136
137
        if ($async_script === $handle) {
138
139
            return str_replace(' src', ' async="async" src', $tag);
140
141
        }
142
143
    }
144
145
    return $tag;
146
}
147
148
// add_filter('script_loader_tag', 'podium_add_async_attribute', 10, 2);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
149