GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 3b8b00...906caa )
by Vincent
07:26 queued 27s
created

Stash::clearTransients()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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 24 and the first side effect is on line 9.

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
namespace Undefined\Stash;
3
4
use TimberMenu;
5
use TimberSite;
6
use Twig_Extension_StringLoader;
7
8
if (!class_exists('Timber')) {
9
    add_action('admin_notices', function () {
10
        echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . esc_url(admin_url('plugins.php#timber')) . '">' . esc_url(admin_url('plugins.php')) . '</a></p></div>';
11
    });
12
13
    return;
14
}
15
16
/* Include global functions */
17
include_once 'inc/functions/dd.php';
18
include_once 'inc/functions/advancedCustomSearch.php';
19
20
/* Include classes */
21
include_once 'inc/classes/ImageHelper.php';
22
include_once 'inc/classes/TransientHelper.php';
23
24
class Stash extends TimberSite
25
{
26
    protected $transientHelper;
27
28
    function __construct()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
29
    {
30
        $this->transientHelper = new TransientHelper();
31
32
        add_theme_support('post-formats');
33
        add_theme_support('post-thumbnails');
34
        add_theme_support('menus');
35
36
        add_filter('timber_context', [$this, 'addToContext']);
37
        add_filter('get_twig', [$this, 'addToTwig']);
38
        add_filter('body_class', [$this, 'addPageClass']);
39
40
        add_action('init', [$this, 'registerPostTypes']);
41
        add_action('init', [$this, 'registerTaxonomies']);
42
        add_action('init', [$this, 'removeEmojiSupport']);
43
        add_action('init', [$this, 'acfSearch']);
44
45
        add_action('wp_enqueue_scripts', [$this, 'themeAssets']);
46
47
        add_action('post_updated', [$this, 'clearTransients']);
48
        add_action('save_post', [$this, 'clearTransients']);
49
        add_action('add_attachment', [$this, 'clearTransients']);
50
51
        parent::__construct();
52
    }
53
54
    /**
55
     * Clear all transients after post create/update or media upload
56
     */
57
    function clearTransients()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
58
    {
59
        $this->transientHelper->deleteAll();
60
    }
61
62
    /**
63
     * Load all files from the inc/post-types/ folder
64
     */
65
    function registerPostTypes()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
66
    {
67
        foreach (glob(__DIR__ . "/inc/post-types/*.php") as $filename) {
68
            include_once $filename;
69
        }
70
    }
71
72
    /**
73
     * Check if ACF is installed, if so enable search
74
     */
75
    function acfSearch()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
76
    {
77
        if (!class_exists('acf')) {
78
            add_filter('posts_search', 'advanced_custom_search', 500, 2);
79
        }
80
    }
81
82
    function registerTaxonomies()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
83
    {
84
        //this is where you can register custom taxonomies
85
86
    }
87
88
    /**
89
     * Remove Emoji support from wordpress
90
     */
91
    function removeEmojiSupport()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
92
    {
93
        remove_action('wp_head', 'print_emoji_detection_script', 7);
94
        remove_action('wp_print_styles', 'print_emoji_styles');
95
    }
96
97
    /**
98
     * Add things to the context for every twig template
99
     * @param $context
100
     * @return mixed
101
     */
102
    function addToContext($context)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
103
    {
104
        $context['menu'] = new TimberMenu();
105
        $context['site'] = $this;
106
107
        $context['is_home'] = is_front_page() ? "true" : "false";
108
        $context['home_url'] = get_home_url();
109
110
        if (function_exists("pll_current_language")) {
111
            $context['current_lang'] = pll_current_language();
112
        }
113
114
        return $context;
115
    }
116
117
    /**
118
     * This is where you can add your own functions to twig
119
     * @param $twig
120
     * @return mixed
121
     */
122
    function addToTwig($twig)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
123
    {
124
        $twig->addExtension(new Twig_Extension_StringLoader());
125
        $twig->addGlobal('image', new ImageHelper());
126
127
        return $twig;
128
    }
129
130
    /**
131
     * Enqueue assets if files exist
132
     */
133
    function themeAssets()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
134
    {
135
        $vendorJsExists = file_exists(get_template_directory() . '/dist/js/vendor.js');
136
        $mainJsExists = file_exists(get_template_directory() . '/dist/js/main.js');
137
        $mainJsDependencies = [];
138
139
        $mainCssExists = file_exists(get_template_directory() . '/dist/css/main.css');
140
        $vendorCssExists = file_exists(get_template_directory() . '/dist/css/vendor.css');
141
        $mainCssDependencies = [];
142
143
        if (!is_admin()) {
144
            wp_deregister_script('jquery');
145
        }
146
147
         if ($vendorJsExists) {
148
            wp_enqueue_script('stashVendorJs', get_template_directory_uri() . '/dist/js/vendor.js', [], filemtime(get_stylesheet_directory() . '/dist/js/vendor.js'), true);
149
            array_push($mainJsDependencies, 'stashVendorJs');
150
        }
151
152
        if ($mainJsExists) {
153
            wp_enqueue_script('stashMainJs', get_template_directory_uri() . '/dist/js/main.js', $mainJsDependencies, filemtime(get_stylesheet_directory() . '/dist/js/main.js'), true);
154
        }
155
156 View Code Duplication
        if ($vendorCssExists) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
157
            wp_enqueue_style('stashVendorCss', get_template_directory_uri() . '/dist/css/vendor.css', [], filemtime(get_stylesheet_directory() . '/dist/css/vendor.css'));
158
            array_push($mainCssDependencies, 'stashVendorCss');
159
        }
160
161 View Code Duplication
        if ($mainCssExists) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
162
            wp_enqueue_style('stashMainCss', get_template_directory_uri() . '/dist/css/main.css', $mainCssDependencies, filemtime(get_stylesheet_directory() . '/dist/css/main.css'));
163
        }
164
    }
165
166
    /**
167
     * Add the object slug name as class to the body classes
168
     *
169
     * @param $classes
170
     * @return array
171
     */
172
    function addPageClass($classes)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
173
    {
174
        if (!is_archive() && !is_home()) {
175
            global $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
176
            $classes[] = get_post($post)->post_name;
177
        }
178
179
        return $classes;
180
    }
181
}
182
183
new Stash();
184