Passed
Push — master ( 68f720...5e727b )
by Paul
10:53
created

MainController::logOnce()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Controllers;
4
5
use GeminiLabs\SiteReviews\Commands\RegisterPostType;
6
use GeminiLabs\SiteReviews\Commands\RegisterShortcodes;
7
use GeminiLabs\SiteReviews\Commands\RegisterTaxonomy;
8
use GeminiLabs\SiteReviews\Commands\RegisterWidgets;
9
use GeminiLabs\SiteReviews\Database\Query;
10
use GeminiLabs\SiteReviews\Helpers\Arr;
11
use GeminiLabs\SiteReviews\Install;
12
13
class MainController extends Controller
14
{
15
    /**
16
     * switch_to_blog() was run before this hook was triggered.
17
     * @param array $tables
18
     * @return array
19
     * @see http://developer.wordpress.org/reference/functions/wp_uninitialize_site/
20
     * @filter wpmu_drop_tables
21
     */
22
    public function filterDropTables($tables)
23
    {
24
        $customTables = [ // order is intentional
25
            glsr()->prefix.'ratings' => glsr(Query::class)->table('ratings'),
26
            glsr()->prefix.'assigned_posts' => glsr(Query::class)->table('assigned_posts'),
27
            glsr()->prefix.'assigned_terms' => glsr(Query::class)->table('assigned_terms'),
28
            glsr()->prefix.'assigned_users' => glsr(Query::class)->table('assigned_users'),
29
        ];
30
        foreach ($customTables as $key => $table) {
31
            $tables = Arr::prepend($tables, $table, $key); // Custom tables have foreign indexes so they must be removed first!
32
        }
33
        return $tables;
34
    }
35
36
    /**
37
     * @return void
38
     * @action init
39
     */
40
    public function initDefaults()
41
    {
42
        // This cannot be done before plugins_loaded as it uses the gettext functions
43
        glsr()->storeDefaults();
44
    }
45
46
    /**
47
     * @param \WP_Site $site
0 ignored issues
show
Bug introduced by
The type WP_Site was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
48
     * @return void
49
     * @action wp_insert_site
50
     */
51
    public function installOnNewSite($site)
52
    {
53
        if (is_plugin_active_for_network(plugin_basename(glsr()->file))) {
0 ignored issues
show
Bug introduced by
The function plugin_basename was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        if (is_plugin_active_for_network(/** @scrutinizer ignore-call */ plugin_basename(glsr()->file))) {
Loading history...
Bug introduced by
The function is_plugin_active_for_network was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        if (/** @scrutinizer ignore-call */ is_plugin_active_for_network(plugin_basename(glsr()->file))) {
Loading history...
54
            glsr(Install::class)->runOnSite($site->blog_id);
55
        }
56
    }
57
58
    /**
59
     * @return void
60
     * @action admin_footer
61
     * @action wp_footer
62
     */
63
    public function logOnce()
64
    {
65
        glsr_log()->logOnce();
66
    }
67
68
    /**
69
     * @return void
70
     * @action plugins_loaded
71
     */
72
    public function registerAddons()
73
    {
74
        glsr()->action('addon/register', glsr());
75
    }
76
77
    /**
78
     * @return void
79
     * @action plugins_loaded
80
     */
81
    public function registerLanguages()
82
    {
83
        load_plugin_textdomain(glsr()->id, false,
0 ignored issues
show
Bug introduced by
The function load_plugin_textdomain was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
        /** @scrutinizer ignore-call */ 
84
        load_plugin_textdomain(glsr()->id, false,
Loading history...
84
            trailingslashit(plugin_basename(glsr()->path()).'/'.glsr()->languages)
0 ignored issues
show
Bug introduced by
The function plugin_basename was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
            trailingslashit(/** @scrutinizer ignore-call */ plugin_basename(glsr()->path()).'/'.glsr()->languages)
Loading history...
Bug introduced by
The function trailingslashit was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
            /** @scrutinizer ignore-call */ 
85
            trailingslashit(plugin_basename(glsr()->path()).'/'.glsr()->languages)
Loading history...
85
        );
86
    }
87
88
    /**
89
     * @return void
90
     * @action init
91
     */
92
    public function registerPostType()
93
    {
94
        $this->execute(new RegisterPostType());
95
    }
96
97
    /**
98
     * @return void
99
     * @action plugins_loaded
100
     */
101
    public function registerReviewTypes()
102
    {
103
        $types = glsr()->filterArray('addon/types', []);
104
        $types = wp_parse_args($types, [
0 ignored issues
show
Bug introduced by
The function wp_parse_args was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

104
        $types = /** @scrutinizer ignore-call */ wp_parse_args($types, [
Loading history...
105
            'local' => _x('Local Review', 'admin-text', 'site-reviews'),
0 ignored issues
show
Bug introduced by
The function _x was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
            'local' => /** @scrutinizer ignore-call */ _x('Local Review', 'admin-text', 'site-reviews'),
Loading history...
106
        ]);
107
        glsr()->store('review_types', $types);
108
    }
109
110
    /**
111
     * @return void
112
     * @action init
113
     */
114
    public function registerShortcodes()
115
    {
116
        $this->execute(new RegisterShortcodes([
117
            'site_reviews',
118
            'site_reviews_form',
119
            'site_reviews_summary',
120
        ]));
121
    }
122
123
    /**
124
     * @return void
125
     * @action init
126
     */
127
    public function registerTaxonomy()
128
    {
129
        $this->execute(new RegisterTaxonomy([
130
            'hierarchical' => true,
131
            'meta_box_cb' => [glsr(MetaboxController::class), 'renderTaxonomyMetabox'],
132
            'public' => false,
133
            'rest_controller_class' => RestCategoryController::class,
134
            'show_admin_column' => true,
135
            'show_in_rest' => true,
136
            'show_ui' => true,
137
        ]));
138
    }
139
140
    /**
141
     * @return void
142
     * @action widgets_init
143
     */
144
    public function registerWidgets()
145
    {
146
        $this->execute(new RegisterWidgets([
147
            'site-reviews' => [
148
                'description' => _x('Site Reviews: Display your recent reviews.', 'admin-text', 'site-reviews'),
0 ignored issues
show
Bug introduced by
The function _x was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

148
                'description' => /** @scrutinizer ignore-call */ _x('Site Reviews: Display your recent reviews.', 'admin-text', 'site-reviews'),
Loading history...
149
                'name' => _x('Recent Reviews', 'admin-text', 'site-reviews'),
150
            ],
151
            'site-reviews-form' => [
152
                'description' => _x('Site Reviews: Display a form to submit reviews.', 'admin-text', 'site-reviews'),
153
                'name' => _x('Submit a Review', 'admin-text', 'site-reviews'),
154
            ],
155
            'site-reviews-summary' => [
156
                'description' => _x('Site Reviews: Display a summary of your reviews.', 'admin-text', 'site-reviews'),
157
                'name' => _x('Summary of Reviews', 'admin-text', 'site-reviews'),
158
            ],
159
        ]));
160
    }
161
}
162