Passed
Push — hotfix/fix-counts ( 4b43d1...cc9e05 )
by Paul
03:52
created
plugin/Database/QueryBuilder.php 1 patch
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -10,165 +10,165 @@
 block discarded – undo
10 10
 
11 11
 class QueryBuilder
12 12
 {
13
-    /**
14
-     * Build a WP_Query meta_query/tax_query.
15
-     * @return array
16
-     */
17
-    public function buildQuery(array $keys = [], array $values = [])
18
-    {
19
-        $queries = [];
20
-        foreach ($keys as $key) {
21
-            if (!array_key_exists($key, $values)) {
22
-                continue;
23
-            }
24
-            $methodName = glsr(Helper::class)->buildMethodName($key, __FUNCTION__);
25
-            if (!method_exists($this, $methodName)) {
26
-                continue;
27
-            }
28
-            $query = call_user_func([$this, $methodName], $values[$key]);
29
-            if (is_array($query)) {
30
-                $queries[] = $query;
31
-            }
32
-        }
33
-        return $queries;
34
-    }
13
+	/**
14
+	 * Build a WP_Query meta_query/tax_query.
15
+	 * @return array
16
+	 */
17
+	public function buildQuery(array $keys = [], array $values = [])
18
+	{
19
+		$queries = [];
20
+		foreach ($keys as $key) {
21
+			if (!array_key_exists($key, $values)) {
22
+				continue;
23
+			}
24
+			$methodName = glsr(Helper::class)->buildMethodName($key, __FUNCTION__);
25
+			if (!method_exists($this, $methodName)) {
26
+				continue;
27
+			}
28
+			$query = call_user_func([$this, $methodName], $values[$key]);
29
+			if (is_array($query)) {
30
+				$queries[] = $query;
31
+			}
32
+		}
33
+		return $queries;
34
+	}
35 35
 
36
-    /**
37
-     * @return string
38
-     */
39
-    public function buildSqlLines(array $values, array $conditions)
40
-    {
41
-        $string = '';
42
-        $values = array_filter($values);
43
-        foreach ($conditions as $key => $value) {
44
-            if (!isset($values[$key])) {
45
-                continue;
46
-            }
47
-            $values[$key] = implode(',', (array) $values[$key]);
48
-            $string .= false !== strpos($value, '%s')
49
-                ? sprintf($value, strval($values[$key]))
50
-                : $value;
51
-        }
52
-        return $string;
53
-    }
36
+	/**
37
+	 * @return string
38
+	 */
39
+	public function buildSqlLines(array $values, array $conditions)
40
+	{
41
+		$string = '';
42
+		$values = array_filter($values);
43
+		foreach ($conditions as $key => $value) {
44
+			if (!isset($values[$key])) {
45
+				continue;
46
+			}
47
+			$values[$key] = implode(',', (array) $values[$key]);
48
+			$string .= false !== strpos($value, '%s')
49
+				? sprintf($value, strval($values[$key]))
50
+				: $value;
51
+		}
52
+		return $string;
53
+	}
54 54
 
55
-    /**
56
-     * Build a SQL 'OR' string from an array.
57
-     * @param string|array $values
58
-     * @param string $sprintfFormat
59
-     * @return string
60
-     */
61
-    public function buildSqlOr($values, $sprintfFormat)
62
-    {
63
-        if (!is_array($values)) {
64
-            $values = explode(',', $values);
65
-        }
66
-        $values = array_filter(array_map('trim', (array) $values));
67
-        $values = array_map(function ($value) use ($sprintfFormat) {
68
-            return sprintf($sprintfFormat, $value);
69
-        }, $values);
70
-        return implode(' OR ', $values);
71
-    }
55
+	/**
56
+	 * Build a SQL 'OR' string from an array.
57
+	 * @param string|array $values
58
+	 * @param string $sprintfFormat
59
+	 * @return string
60
+	 */
61
+	public function buildSqlOr($values, $sprintfFormat)
62
+	{
63
+		if (!is_array($values)) {
64
+			$values = explode(',', $values);
65
+		}
66
+		$values = array_filter(array_map('trim', (array) $values));
67
+		$values = array_map(function ($value) use ($sprintfFormat) {
68
+			return sprintf($sprintfFormat, $value);
69
+		}, $values);
70
+		return implode(' OR ', $values);
71
+	}
72 72
 
73
-    /**
74
-     * Search SQL filter for matching against post title only.
75
-     * @see http://wordpress.stackexchange.com/a/11826/1685
76
-     * @param string $search
77
-     * @return string
78
-     * @filter posts_search
79
-     */
80
-    public function filterSearchByTitle($search, WP_Query $query)
81
-    {
82
-        if (empty($search) || empty($query->get('search_terms'))) {
83
-            return $search;
84
-        }
85
-        global $wpdb;
86
-        $n = empty($query->get('exact'))
87
-            ? '%'
88
-            : '';
89
-        $search = [];
90
-        foreach ((array) $query->get('search_terms') as $term) {
91
-            $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n);
92
-        }
93
-        if (!is_user_logged_in()) {
94
-            $search[] = "{$wpdb->posts}.post_password = ''";
95
-        }
96
-        return ' AND '.implode(' AND ', $search);
97
-    }
73
+	/**
74
+	 * Search SQL filter for matching against post title only.
75
+	 * @see http://wordpress.stackexchange.com/a/11826/1685
76
+	 * @param string $search
77
+	 * @return string
78
+	 * @filter posts_search
79
+	 */
80
+	public function filterSearchByTitle($search, WP_Query $query)
81
+	{
82
+		if (empty($search) || empty($query->get('search_terms'))) {
83
+			return $search;
84
+		}
85
+		global $wpdb;
86
+		$n = empty($query->get('exact'))
87
+			? '%'
88
+			: '';
89
+		$search = [];
90
+		foreach ((array) $query->get('search_terms') as $term) {
91
+			$search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n);
92
+		}
93
+		if (!is_user_logged_in()) {
94
+			$search[] = "{$wpdb->posts}.post_password = ''";
95
+		}
96
+		return ' AND '.implode(' AND ', $search);
97
+	}
98 98
 
99
-    /**
100
-     * Get the current page number from the global query.
101
-     * @param bool $isEnabled
102
-     * @return int
103
-     */
104
-    public function getPaged($isEnabled = true)
105
-    {
106
-        $pagedQuery = !is_front_page()
107
-            ? glsr()->constant('PAGED_QUERY_VAR')
108
-            : 'page';
109
-        return $isEnabled
110
-            ? max(1, intval(get_query_var($pagedQuery)))
111
-            : 1;
112
-    }
99
+	/**
100
+	 * Get the current page number from the global query.
101
+	 * @param bool $isEnabled
102
+	 * @return int
103
+	 */
104
+	public function getPaged($isEnabled = true)
105
+	{
106
+		$pagedQuery = !is_front_page()
107
+			? glsr()->constant('PAGED_QUERY_VAR')
108
+			: 'page';
109
+		return $isEnabled
110
+			? max(1, intval(get_query_var($pagedQuery)))
111
+			: 1;
112
+	}
113 113
 
114
-    /**
115
-     * @param string $value
116
-     * @return void|array
117
-     */
118
-    protected function buildQueryAssignedTo($value)
119
-    {
120
-        if (!empty($value)) {
121
-            $postIds = glsr(Helper::class)->convertStringToArray($value, 'is_numeric');
122
-            return [
123
-                'compare' => 'IN',
124
-                'key' => 'assigned_to',
125
-                'value' => glsr(Polylang::class)->getPostIds($postIds),
126
-            ];
127
-        }
128
-    }
114
+	/**
115
+	 * @param string $value
116
+	 * @return void|array
117
+	 */
118
+	protected function buildQueryAssignedTo($value)
119
+	{
120
+		if (!empty($value)) {
121
+			$postIds = glsr(Helper::class)->convertStringToArray($value, 'is_numeric');
122
+			return [
123
+				'compare' => 'IN',
124
+				'key' => 'assigned_to',
125
+				'value' => glsr(Polylang::class)->getPostIds($postIds),
126
+			];
127
+		}
128
+	}
129 129
 
130
-    /**
131
-     * @param array $value
132
-     * @return void|array
133
-     */
134
-    protected function buildQueryCategory($value)
135
-    {
136
-        if (!empty($value)) {
137
-            return [
138
-                'field' => 'term_id',
139
-                'taxonomy' => Application::TAXONOMY,
140
-                'terms' => $value,
141
-            ];
142
-        }
143
-    }
130
+	/**
131
+	 * @param array $value
132
+	 * @return void|array
133
+	 */
134
+	protected function buildQueryCategory($value)
135
+	{
136
+		if (!empty($value)) {
137
+			return [
138
+				'field' => 'term_id',
139
+				'taxonomy' => Application::TAXONOMY,
140
+				'terms' => $value,
141
+			];
142
+		}
143
+	}
144 144
 
145
-    /**
146
-     * @param string $value
147
-     * @return void|array
148
-     */
149
-    protected function buildQueryRating($value)
150
-    {
151
-        if (is_numeric($value)
152
-            && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) {
153
-            return [
154
-                'compare' => '>=',
155
-                'key' => 'rating',
156
-                'value' => $value,
157
-            ];
158
-        }
159
-    }
145
+	/**
146
+	 * @param string $value
147
+	 * @return void|array
148
+	 */
149
+	protected function buildQueryRating($value)
150
+	{
151
+		if (is_numeric($value)
152
+			&& in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) {
153
+			return [
154
+				'compare' => '>=',
155
+				'key' => 'rating',
156
+				'value' => $value,
157
+			];
158
+		}
159
+	}
160 160
 
161
-    /**
162
-     * @param string $value
163
-     * @return void|array
164
-     */
165
-    protected function buildQueryType($value)
166
-    {
167
-        if (!in_array($value, ['', 'all'])) {
168
-            return [
169
-                'key' => 'review_type',
170
-                'value' => $value,
171
-            ];
172
-        }
173
-    }
161
+	/**
162
+	 * @param string $value
163
+	 * @return void|array
164
+	 */
165
+	protected function buildQueryType($value)
166
+	{
167
+		if (!in_array($value, ['', 'all'])) {
168
+			return [
169
+				'key' => 'review_type',
170
+				'value' => $value,
171
+			];
172
+		}
173
+	}
174 174
 }
Please login to merge, or discard this patch.
plugin/Database/Cache.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -6,68 +6,68 @@
 block discarded – undo
6 6
 
7 7
 class Cache
8 8
 {
9
-    const EXPIRY_TIME = WEEK_IN_SECONDS;
9
+	const EXPIRY_TIME = WEEK_IN_SECONDS;
10 10
 
11
-    /**
12
-     * @return array
13
-     */
14
-    public function getCloudflareIps()
15
-    {
16
-        $ipAddresses = get_transient(Application::ID.'_cloudflare_ips');
17
-        if (false === $ipAddresses) {
18
-            $ipAddresses = array_fill_keys(['v4', 'v6'], []);
19
-            foreach (array_keys($ipAddresses) as $version) {
20
-                $url = 'https://www.cloudflare.com/ips-'.$version;
21
-                $response = wp_remote_get($url);
22
-                if (is_wp_error($response)) {
23
-                    glsr_log()->error($response->get_error_message());
24
-                    continue;
25
-                }
26
-                if ('200' != ($statusCode = wp_remote_retrieve_response_code($response))) {
27
-                    glsr_log()->error('Unable to connect to '.$url.' ['.$statusCode.']');
28
-                    continue;
29
-                }
30
-                $ipAddresses[$version] = array_filter(
31
-                    (array) preg_split('/\R/', wp_remote_retrieve_body($response))
32
-                );
33
-            }
34
-            set_transient(Application::ID.'_cloudflare_ips', $ipAddresses, static::EXPIRY_TIME);
35
-        }
36
-        return $ipAddresses;
37
-    }
11
+	/**
12
+	 * @return array
13
+	 */
14
+	public function getCloudflareIps()
15
+	{
16
+		$ipAddresses = get_transient(Application::ID.'_cloudflare_ips');
17
+		if (false === $ipAddresses) {
18
+			$ipAddresses = array_fill_keys(['v4', 'v6'], []);
19
+			foreach (array_keys($ipAddresses) as $version) {
20
+				$url = 'https://www.cloudflare.com/ips-'.$version;
21
+				$response = wp_remote_get($url);
22
+				if (is_wp_error($response)) {
23
+					glsr_log()->error($response->get_error_message());
24
+					continue;
25
+				}
26
+				if ('200' != ($statusCode = wp_remote_retrieve_response_code($response))) {
27
+					glsr_log()->error('Unable to connect to '.$url.' ['.$statusCode.']');
28
+					continue;
29
+				}
30
+				$ipAddresses[$version] = array_filter(
31
+					(array) preg_split('/\R/', wp_remote_retrieve_body($response))
32
+				);
33
+			}
34
+			set_transient(Application::ID.'_cloudflare_ips', $ipAddresses, static::EXPIRY_TIME);
35
+		}
36
+		return $ipAddresses;
37
+	}
38 38
 
39
-    /**
40
-     * @param string $metaKey
41
-     * @return array
42
-     */
43
-    public function getReviewCountsFor($metaKey)
44
-    {
45
-        $counts = wp_cache_get(Application::ID, $metaKey.'_count');
46
-        if (false === $counts) {
47
-            $counts = [];
48
-            $results = glsr(SqlQueries::class)->getReviewCountsFor($metaKey);
49
-            foreach ($results as $result) {
50
-                $counts[$result->name] = $result->num_posts;
51
-            }
52
-            wp_cache_set(Application::ID, $counts, $metaKey.'_count');
53
-        }
54
-        return $counts;
55
-    }
39
+	/**
40
+	 * @param string $metaKey
41
+	 * @return array
42
+	 */
43
+	public function getReviewCountsFor($metaKey)
44
+	{
45
+		$counts = wp_cache_get(Application::ID, $metaKey.'_count');
46
+		if (false === $counts) {
47
+			$counts = [];
48
+			$results = glsr(SqlQueries::class)->getReviewCountsFor($metaKey);
49
+			foreach ($results as $result) {
50
+				$counts[$result->name] = $result->num_posts;
51
+			}
52
+			wp_cache_set(Application::ID, $counts, $metaKey.'_count');
53
+		}
54
+		return $counts;
55
+	}
56 56
 
57
-    /**
58
-     * @return string
59
-     */
60
-    public function getRemotePostTest()
61
-    {
62
-        $test = get_transient(Application::ID.'_remote_post_test');
63
-        if (false === $test) {
64
-            $response = wp_remote_post('https://api.wordpress.org/stats/php/1.0/');
65
-            $test = !is_wp_error($response)
66
-                && in_array($response['response']['code'], range(200, 299))
67
-                ? 'Works'
68
-                : 'Does not work';
69
-            set_transient(Application::ID.'_remote_post_test', $test, static::EXPIRY_TIME);
70
-        }
71
-        return $test;
72
-    }
57
+	/**
58
+	 * @return string
59
+	 */
60
+	public function getRemotePostTest()
61
+	{
62
+		$test = get_transient(Application::ID.'_remote_post_test');
63
+		if (false === $test) {
64
+			$response = wp_remote_post('https://api.wordpress.org/stats/php/1.0/');
65
+			$test = !is_wp_error($response)
66
+				&& in_array($response['response']['code'], range(200, 299))
67
+				? 'Works'
68
+				: 'Does not work';
69
+			set_transient(Application::ID.'_remote_post_test', $test, static::EXPIRY_TIME);
70
+		}
71
+		return $test;
72
+	}
73 73
 }
Please login to merge, or discard this patch.
plugin/Database/DefaultsManager.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -6,60 +6,60 @@
 block discarded – undo
6 6
 
7 7
 class DefaultsManager
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    public function defaults()
13
-    {
14
-        $settings = $this->settings();
15
-        $defaults = array_combine(array_keys($settings), glsr_array_column($settings, 'default'));
16
-        return wp_parse_args($defaults, [
17
-            'version' => '',
18
-            'version_upgraded_from' => '',
19
-        ]);
20
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	public function defaults()
13
+	{
14
+		$settings = $this->settings();
15
+		$defaults = array_combine(array_keys($settings), glsr_array_column($settings, 'default'));
16
+		return wp_parse_args($defaults, [
17
+			'version' => '',
18
+			'version_upgraded_from' => '',
19
+		]);
20
+	}
21 21
 
22
-    /**
23
-     * @return array
24
-     */
25
-    public function get()
26
-    {
27
-        return glsr(Helper::class)->convertDotNotationArray($this->defaults());
28
-    }
22
+	/**
23
+	 * @return array
24
+	 */
25
+	public function get()
26
+	{
27
+		return glsr(Helper::class)->convertDotNotationArray($this->defaults());
28
+	}
29 29
 
30
-    /**
31
-     * @return array
32
-     */
33
-    public function set()
34
-    {
35
-        $settings = glsr(OptionManager::class)->all();
36
-        $currentSettings = glsr(Helper::class)->removeEmptyArrayValues($settings);
37
-        $defaultSettings = array_replace_recursive($this->get(), $currentSettings);
38
-        $updatedSettings = array_replace_recursive($settings, $defaultSettings);
39
-        update_option(OptionManager::databaseKey(), $updatedSettings);
40
-        return $defaultSettings;
41
-    }
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function set()
34
+	{
35
+		$settings = glsr(OptionManager::class)->all();
36
+		$currentSettings = glsr(Helper::class)->removeEmptyArrayValues($settings);
37
+		$defaultSettings = array_replace_recursive($this->get(), $currentSettings);
38
+		$updatedSettings = array_replace_recursive($settings, $defaultSettings);
39
+		update_option(OptionManager::databaseKey(), $updatedSettings);
40
+		return $defaultSettings;
41
+	}
42 42
 
43
-    /**
44
-     * @return array
45
-     */
46
-    public function settings()
47
-    {
48
-        $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings'));
49
-        return $this->normalize($settings);
50
-    }
43
+	/**
44
+	 * @return array
45
+	 */
46
+	public function settings()
47
+	{
48
+		$settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings'));
49
+		return $this->normalize($settings);
50
+	}
51 51
 
52
-    /**
53
-     * @return array
54
-     */
55
-    protected function normalize(array $settings)
56
-    {
57
-        array_walk($settings, function (&$setting) {
58
-            if (isset($setting['default'])) {
59
-                return;
60
-            }
61
-            $setting['default'] = '';
62
-        });
63
-        return $settings;
64
-    }
52
+	/**
53
+	 * @return array
54
+	 */
55
+	protected function normalize(array $settings)
56
+	{
57
+		array_walk($settings, function (&$setting) {
58
+			if (isset($setting['default'])) {
59
+				return;
60
+			}
61
+			$setting['default'] = '';
62
+		});
63
+		return $settings;
64
+	}
65 65
 }
Please login to merge, or discard this patch.
plugin/Database/CountsManager.php 1 patch
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -20,27 +20,27 @@  discard block
 block discarded – undo
20 20
 	 * @return array
21 21
 	 * @todo verify the additional type checks are needed
22 22
 	 */
23
-    public function buildCounts(array $args = [])
23
+	public function buildCounts(array $args = [])
24 24
 	{
25 25
 		$counts = [];
26
-        $query = $this->queryReviews($args);
27
-        while ($query) {
26
+		$query = $this->queryReviews($args);
27
+		while ($query) {
28 28
 			// glsr_log($query);
29
-            $types = array_keys(array_flip(glsr_array_column($query->reviews, 'type')));
30
-            $types = array_unique(array_merge(['local'], $types));
31
-            foreach ($types as $type) {
32
-                $type = $this->normalizeType($type);
33
-                if (isset($counts[$type])) {
34
-                    continue;
29
+			$types = array_keys(array_flip(glsr_array_column($query->reviews, 'type')));
30
+			$types = array_unique(array_merge(['local'], $types));
31
+			foreach ($types as $type) {
32
+				$type = $this->normalizeType($type);
33
+				if (isset($counts[$type])) {
34
+					continue;
35 35
 			}
36
-                $counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
37
-            }
38
-            foreach ($query->reviews as $review) {
39
-                $type = $this->normalizeType($review->type);
40
-                ++$counts[$type][$review->rating];
36
+				$counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
37
+			}
38
+			foreach ($query->reviews as $review) {
39
+				$type = $this->normalizeType($review->type);
40
+				++$counts[$type][$review->rating];
41 41
 			}
42 42
 			$query = $query->has_more
43
-                ? $this->queryReviews($args, end($query->reviews)->ID)
43
+				? $this->queryReviews($args, end($query->reviews)->ID)
44 44
 				: false;
45 45
 		}
46 46
 		return $counts;
@@ -50,18 +50,18 @@  discard block
 block discarded – undo
50 50
 	 * @param int $postId
51 51
 	 * @return array
52 52
 	 */
53
-    public function buildPostCounts($postId)
53
+	public function buildPostCounts($postId)
54 54
 	{
55
-        return $this->buildCounts(['post_ids' => [$postId]]);
55
+		return $this->buildCounts(['post_ids' => [$postId]]);
56 56
 	}
57 57
 
58 58
 	/**
59 59
 	 * @param int $termTaxonomyId
60 60
 	 * @return array
61 61
 	 */
62
-    public function buildTermCounts($termTaxonomyId)
62
+	public function buildTermCounts($termTaxonomyId)
63 63
 	{
64
-        return $this->buildCounts(['term_ids' => [$termTaxonomyId]]);
64
+		return $this->buildCounts(['term_ids' => [$termTaxonomyId]]);
65 65
 	}
66 66
 
67 67
 	/**
@@ -69,33 +69,33 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public function countAll()
71 71
 	{
72
-        $terms = glsr(Database::class)->getTerms(['fields' => 'all']);
73
-        foreach ($terms as $term) {
74
-            $this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id));
72
+		$terms = glsr(Database::class)->getTerms(['fields' => 'all']);
73
+		foreach ($terms as $term) {
74
+			$this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id));
75 75
 		}
76
-        $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
77
-        foreach ($postIds as $postId) {
78
-            $this->setPostCounts($postId, $this->buildPostCounts($postId));
76
+		$postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
77
+		foreach ($postIds as $postId) {
78
+			$this->setPostCounts($postId, $this->buildPostCounts($postId));
79 79
 		}
80
-        $this->setCounts($this->buildCounts());
80
+		$this->setCounts($this->buildCounts());
81 81
 	}
82 82
 
83 83
 	/**
84 84
 	 * @return void
85 85
 	 */
86
-    public function decrease(Review $review)
86
+	public function decrease(Review $review)
87 87
 	{
88
-        $this->decreaseCounts($review);
89
-        $this->decreasePostCounts($review);
90
-        $this->decreaseTermCounts($review);
88
+		$this->decreaseCounts($review);
89
+		$this->decreasePostCounts($review);
90
+		$this->decreaseTermCounts($review);
91 91
 	}
92 92
 
93 93
 	/**
94 94
 	 * @return void
95 95
 	 */
96
-    public function decreaseCounts(Review $review)
96
+	public function decreaseCounts(Review $review)
97 97
 	{
98
-        $this->setCounts($this->decreaseRating(
98
+		$this->setCounts($this->decreaseRating(
99 99
 			$this->getCounts(),
100 100
 			$review->review_type,
101 101
 			$review->rating
@@ -105,46 +105,46 @@  discard block
 block discarded – undo
105 105
 	/**
106 106
 	 * @return void
107 107
 	 */
108
-    public function decreasePostCounts(Review $review)
108
+	public function decreasePostCounts(Review $review)
109 109
 	{
110
-        if (empty($counts = $this->getPostCounts($review->assigned_to))) {
111
-            return;
112
-        }
113
-        $counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
114
-        $this->setPostCounts($review->assigned_to, $counts);
110
+		if (empty($counts = $this->getPostCounts($review->assigned_to))) {
111
+			return;
112
+		}
113
+		$counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
114
+		$this->setPostCounts($review->assigned_to, $counts);
115 115
 	}
116 116
 
117 117
 	/**
118 118
 	 * @return void
119 119
 	 */
120
-    public function decreaseTermCounts(Review $review)
120
+	public function decreaseTermCounts(Review $review)
121 121
 	{
122
-        foreach ($review->term_ids as $termId) {
123
-            if (empty($counts = $this->getTermCounts($termId))) {
124
-                continue;
125
-            }
126
-            $counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
127
-            $this->setTermCounts($termId, $counts);
122
+		foreach ($review->term_ids as $termId) {
123
+			if (empty($counts = $this->getTermCounts($termId))) {
124
+				continue;
125
+			}
126
+			$counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
127
+			$this->setTermCounts($termId, $counts);
128 128
 		}
129 129
 	}
130 130
 
131 131
 	/**
132 132
 	 * @return array
133 133
 	 */
134
-    public function flatten(array $reviewCounts, array $args = [])
134
+	public function flatten(array $reviewCounts, array $args = [])
135 135
 	{
136 136
 		$counts = [];
137
-        array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
138
-            $counts[$index] = $num + intval(glsr_get($counts, $index, 0));
137
+		array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
138
+			$counts[$index] = $num + intval(glsr_get($counts, $index, 0));
139 139
 		});
140
-        $args = wp_parse_args($args, [
141
-            'max' => glsr()->constant('MAX_RATING', Rating::class),
142
-            'min' => glsr()->constant('MIN_RATING', Rating::class),
140
+		$args = wp_parse_args($args, [
141
+			'max' => glsr()->constant('MAX_RATING', Rating::class),
142
+			'min' => glsr()->constant('MIN_RATING', Rating::class),
143 143
 		]);
144
-        foreach ($counts as $index => &$num) {
145
-            if ($index >= intval($args['min']) && $index <= intval($args['max'])) {
146
-                continue;
147
-            }
144
+		foreach ($counts as $index => &$num) {
145
+			if ($index >= intval($args['min']) && $index <= intval($args['max'])) {
146
+				continue;
147
+			}
148 148
 			$num = 0;
149 149
 		}
150 150
 		return $counts;
@@ -153,26 +153,26 @@  discard block
 block discarded – undo
153 153
 	/**
154 154
 	 * @return array
155 155
 	 */
156
-    public function get(array $args = [])
156
+	public function get(array $args = [])
157 157
 	{
158
-        $args = $this->normalizeArgs($args);
158
+		$args = $this->normalizeArgs($args);
159 159
 		$counts = [];
160
-        if ($this->isMixedCount($args)) {
161
-            $counts = [$this->buildCounts($args)]; // force query the database
162
-        } else {
163
-            foreach ($args['post_ids'] as $postId) {
164
-                $counts[] = $this->getPostCounts($postId);
160
+		if ($this->isMixedCount($args)) {
161
+			$counts = [$this->buildCounts($args)]; // force query the database
162
+		} else {
163
+			foreach ($args['post_ids'] as $postId) {
164
+				$counts[] = $this->getPostCounts($postId);
165 165
 		}
166
-            foreach ($args['term_ids'] as $termId) {
167
-                $counts[] = $this->getTermCounts($termId);
166
+			foreach ($args['term_ids'] as $termId) {
167
+				$counts[] = $this->getTermCounts($termId);
168 168
 			}
169
-            if (empty($counts)) {
169
+			if (empty($counts)) {
170 170
 				$counts[] = $this->getCounts();
171 171
 			}
172 172
 		}
173
-        return in_array($args['type'], ['', 'all'])
174
-            ? $this->normalize([$this->flatten($counts)])
175
-            : $this->normalize(glsr_array_column($counts, $args['type']));
173
+		return in_array($args['type'], ['', 'all'])
174
+			? $this->normalize([$this->flatten($counts)])
175
+			: $this->normalize(glsr_array_column($counts, $args['type']));
176 176
 	}
177 177
 
178 178
 	/**
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 	 */
181 181
 	public function getCounts()
182 182
 	{
183
-        $counts = glsr(OptionManager::class)->get('counts', []);
184
-        if (!is_array($counts)) {
185
-            glsr_log()->error('$counts is not an array')->debug($counts);
183
+		$counts = glsr(OptionManager::class)->get('counts', []);
184
+		if (!is_array($counts)) {
185
+			glsr_log()->error('$counts is not an array')->debug($counts);
186 186
 			return [];
187 187
 		}
188 188
 		return $counts;
@@ -192,105 +192,105 @@  discard block
 block discarded – undo
192 192
 	 * @param int $postId
193 193
 	 * @return array
194 194
 	 */
195
-    public function getPostCounts($postId)
195
+	public function getPostCounts($postId)
196 196
 	{
197
-        return array_filter((array) get_post_meta($postId, static::META_COUNT, true));
197
+		return array_filter((array) get_post_meta($postId, static::META_COUNT, true));
198 198
 	}
199 199
 
200 200
 	/**
201 201
 	 * @param int $termId
202 202
 	 * @return array
203 203
 	 */
204
-    public function getTermCounts($termId)
204
+	public function getTermCounts($termId)
205 205
 	{
206
-        return array_filter((array) get_term_meta($termId, static::META_COUNT, true));
206
+		return array_filter((array) get_term_meta($termId, static::META_COUNT, true));
207 207
 	}
208 208
 
209 209
 	/**
210 210
 	 * @return void
211 211
 	 */
212
-    public function increase(Review $review)
212
+	public function increase(Review $review)
213 213
 	{
214
-        $this->increaseCounts($review);
215
-        $this->increasePostCounts($review);
216
-        $this->increaseTermCounts($review);
214
+		$this->increaseCounts($review);
215
+		$this->increasePostCounts($review);
216
+		$this->increaseTermCounts($review);
217 217
 	}
218 218
 
219 219
 	/**
220 220
 	 * @return void
221 221
 	 */
222
-    public function increaseCounts(Review $review)
222
+	public function increaseCounts(Review $review)
223 223
 	{
224
-        if (empty($counts = $this->getCounts())) {
224
+		if (empty($counts = $this->getCounts())) {
225 225
 			$counts = $this->buildCounts();
226 226
 		}
227
-        $this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating));
227
+		$this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating));
228 228
 	}
229 229
 
230 230
 	/**
231 231
 	 * @return void
232 232
 	 */
233
-    public function increasePostCounts(Review $review)
233
+	public function increasePostCounts(Review $review)
234 234
 	{
235
-        if (!(get_post($review->assigned_to) instanceof WP_Post)) {
236
-            return;
237
-        }
238
-        $counts = $this->getPostCounts($review->assigned_to);
239
-        $counts = empty($counts)
240
-            ? $this->buildPostCounts($review->assigned_to)
241
-            : $this->increaseRating($counts, $review->review_type, $review->rating);
242
-        $this->setPostCounts($review->assigned_to, $counts);
235
+		if (!(get_post($review->assigned_to) instanceof WP_Post)) {
236
+			return;
237
+		}
238
+		$counts = $this->getPostCounts($review->assigned_to);
239
+		$counts = empty($counts)
240
+			? $this->buildPostCounts($review->assigned_to)
241
+			: $this->increaseRating($counts, $review->review_type, $review->rating);
242
+		$this->setPostCounts($review->assigned_to, $counts);
243 243
 	}
244 244
 
245 245
 	/**
246 246
 	 * @return void
247 247
 	 */
248
-    public function increaseTermCounts(Review $review)
248
+	public function increaseTermCounts(Review $review)
249 249
 	{
250
-        $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
251
-        foreach ($terms as $term) {
252
-            $counts = $this->getTermCounts($term['term_id']);
253
-            $counts = empty($counts)
254
-                ? $this->buildTermCounts($term['term_taxonomy_id'])
255
-                : $this->increaseRating($counts, $review->review_type, $review->rating);
256
-            $this->setTermCounts($term['term_id'], $counts);
250
+		$terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
251
+		foreach ($terms as $term) {
252
+			$counts = $this->getTermCounts($term['term_id']);
253
+			$counts = empty($counts)
254
+				? $this->buildTermCounts($term['term_taxonomy_id'])
255
+				: $this->increaseRating($counts, $review->review_type, $review->rating);
256
+			$this->setTermCounts($term['term_id'], $counts);
257 257
 		}
258 258
 	}
259 259
 
260 260
 	/**
261 261
 	 * @return void
262 262
 	 */
263
-    public function setCounts(array $reviewCounts)
263
+	public function setCounts(array $reviewCounts)
264 264
 	{
265
-        glsr(OptionManager::class)->set('counts', $reviewCounts);
265
+		glsr(OptionManager::class)->set('counts', $reviewCounts);
266 266
 	}
267 267
 
268 268
 	/**
269 269
 	 * @param int $postId
270 270
 	 * @return void
271 271
 	 */
272
-    public function setPostCounts($postId, array $reviewCounts)
272
+	public function setPostCounts($postId, array $reviewCounts)
273 273
 	{
274
-        $ratingCounts = $this->flatten($reviewCounts);
275
-        update_post_meta($postId, static::META_COUNT, $reviewCounts);
276
-        update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
277
-        update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
274
+		$ratingCounts = $this->flatten($reviewCounts);
275
+		update_post_meta($postId, static::META_COUNT, $reviewCounts);
276
+		update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
277
+		update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
278 278
 	}
279 279
 
280 280
 	/**
281 281
 	 * @param int $termId
282 282
 	 * @return void
283 283
 	 */
284
-    public function setTermCounts($termId, array $reviewCounts)
284
+	public function setTermCounts($termId, array $reviewCounts)
285 285
 	{
286
-        $term = get_term($termId, Application::TAXONOMY);
287
-        if (!isset($term->term_id)) {
288
-            return;
289
-        }
290
-        $ratingCounts = $this->flatten($reviewCounts);
291
-        update_term_meta($termId, static::META_COUNT, $reviewCounts);
292
-        update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
293
-        update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
286
+		$term = get_term($termId, Application::TAXONOMY);
287
+		if (!isset($term->term_id)) {
288
+			return;
289
+		}
290
+		$ratingCounts = $this->flatten($reviewCounts);
291
+		update_term_meta($termId, static::META_COUNT, $reviewCounts);
292
+		update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
293
+		update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
294 294
 	}
295 295
 
296 296
 	/**
@@ -298,10 +298,10 @@  discard block
 block discarded – undo
298 298
 	 * @param int $rating
299 299
 	 * @return array
300 300
 	 */
301
-    protected function decreaseRating(array $reviewCounts, $type, $rating)
301
+	protected function decreaseRating(array $reviewCounts, $type, $rating)
302 302
 	{
303
-        if (isset($reviewCounts[$type][$rating])) {
304
-            $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
303
+		if (isset($reviewCounts[$type][$rating])) {
304
+			$reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
305 305
 		}
306 306
 		return $reviewCounts;
307 307
 	}
@@ -311,43 +311,43 @@  discard block
 block discarded – undo
311 311
 	 * @param int $rating
312 312
 	 * @return array
313 313
 	 */
314
-    protected function increaseRating(array $reviewCounts, $type, $rating)
314
+	protected function increaseRating(array $reviewCounts, $type, $rating)
315 315
 	{
316
-        if (!array_key_exists($type, glsr()->reviewTypes)) {
316
+		if (!array_key_exists($type, glsr()->reviewTypes)) {
317 317
 			return $reviewCounts;
318 318
 		}
319
-        if (!array_key_exists($type, $reviewCounts)) {
319
+		if (!array_key_exists($type, $reviewCounts)) {
320 320
 			$reviewCounts[$type] = [];
321 321
 		}
322
-        $reviewCounts = $this->normalize($reviewCounts);
323
-        $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
322
+		$reviewCounts = $this->normalize($reviewCounts);
323
+		$reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
324 324
 		return $reviewCounts;
325 325
 	}
326 326
 
327 327
 	/**
328 328
 	 * @return bool
329 329
 	 */
330
-    protected function isMixedCount(array $args)
330
+	protected function isMixedCount(array $args)
331 331
 	{
332
-        return !empty($args['post_ids']) && !empty($args['term_ids']);
332
+		return !empty($args['post_ids']) && !empty($args['term_ids']);
333 333
 	}
334 334
 
335 335
 	/**
336 336
 	 * @return array
337 337
 	 */
338
-    protected function normalize(array $reviewCounts)
338
+	protected function normalize(array $reviewCounts)
339 339
 	{
340
-        if (empty($reviewCounts)) {
340
+		if (empty($reviewCounts)) {
341 341
 			$reviewCounts = [[]];
342 342
 		}
343
-        foreach ($reviewCounts as &$counts) {
344
-            foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) {
345
-                if (isset($counts[$index])) {
346
-                    continue;
347
-                }
343
+		foreach ($reviewCounts as &$counts) {
344
+			foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) {
345
+				if (isset($counts[$index])) {
346
+					continue;
347
+				}
348 348
 				$counts[$index] = 0;
349 349
 			}
350
-            ksort($counts);
350
+			ksort($counts);
351 351
 		}
352 352
 		return $reviewCounts;
353 353
 	}
@@ -355,15 +355,15 @@  discard block
 block discarded – undo
355 355
 	/**
356 356
 	 * @return array
357 357
 	 */
358
-    protected function normalizeArgs(array $args)
358
+	protected function normalizeArgs(array $args)
359 359
 	{
360
-        $args = wp_parse_args(array_filter($args), [
360
+		$args = wp_parse_args(array_filter($args), [
361 361
 			'post_ids' => [],
362 362
 			'term_ids' => [],
363 363
 			'type' => 'local',
364 364
 		]);
365
-        $args['post_ids'] = glsr(Polylang::class)->getPostIds($args['post_ids']);
366
-        $args['type'] = $this->normalizeType($args['type']);
365
+		$args['post_ids'] = glsr(Polylang::class)->getPostIds($args['post_ids']);
366
+		$args['type'] = $this->normalizeType($args['type']);
367 367
 		return $args;
368 368
 	}
369 369
 
@@ -371,9 +371,9 @@  discard block
 block discarded – undo
371 371
 	 * @param string $type
372 372
 	 * @return string
373 373
 	 */
374
-    protected function normalizeType($type)
374
+	protected function normalizeType($type)
375 375
 	{
376
-        return empty($type) || !is_string($type)
376
+		return empty($type) || !is_string($type)
377 377
 			? 'local'
378 378
 			: $type;
379 379
 	}
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
 	 * @param int $lastPostId
383 383
 	 * @return object
384 384
 	 */
385
-    protected function queryReviews(array $args = [], $lastPostId = 0)
385
+	protected function queryReviews(array $args = [], $lastPostId = 0)
386 386
 	{
387
-        $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
388
-        $hasMore = is_array($reviews)
389
-            ? count($reviews) == static::LIMIT
387
+		$reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
388
+		$hasMore = is_array($reviews)
389
+			? count($reviews) == static::LIMIT
390 390
 			: false;
391 391
 		return (object) [
392 392
 			'has_more' => $hasMore,
Please login to merge, or discard this patch.
plugin/Database/ReviewManager.php 1 patch
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -15,200 +15,200 @@
 block discarded – undo
15 15
 
16 16
 class ReviewManager
17 17
 {
18
-    /**
19
-     * @return false|Review
20
-     */
21
-    public function create(CreateReview $command)
22
-    {
23
-        $reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command);
24
-        $reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command);
25
-        $postValues = [
26
-            'comment_status' => 'closed',
27
-            'meta_input' => $reviewValues,
28
-            'ping_status' => 'closed',
29
-            'post_content' => $reviewValues['content'],
30
-            'post_date' => $reviewValues['date'],
31
-            'post_date_gmt' => get_gmt_from_date($reviewValues['date']),
32
-            'post_name' => $reviewValues['review_type'].'-'.$reviewValues['review_id'],
33
-            'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted),
34
-            'post_title' => $reviewValues['title'],
35
-            'post_type' => Application::POST_TYPE,
36
-        ];
37
-        $postId = wp_insert_post($postValues, true);
38
-        if (is_wp_error($postId)) {
39
-            glsr_log()->error($postId->get_error_message())->debug($postValues);
40
-            return false;
41
-        }
42
-        $this->setTerms($postId, $command->category);
43
-        $review = $this->single(get_post($postId));
44
-        do_action('site-reviews/review/created', $review, $command);
45
-        return $review;
46
-    }
18
+	/**
19
+	 * @return false|Review
20
+	 */
21
+	public function create(CreateReview $command)
22
+	{
23
+		$reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command);
24
+		$reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command);
25
+		$postValues = [
26
+			'comment_status' => 'closed',
27
+			'meta_input' => $reviewValues,
28
+			'ping_status' => 'closed',
29
+			'post_content' => $reviewValues['content'],
30
+			'post_date' => $reviewValues['date'],
31
+			'post_date_gmt' => get_gmt_from_date($reviewValues['date']),
32
+			'post_name' => $reviewValues['review_type'].'-'.$reviewValues['review_id'],
33
+			'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted),
34
+			'post_title' => $reviewValues['title'],
35
+			'post_type' => Application::POST_TYPE,
36
+		];
37
+		$postId = wp_insert_post($postValues, true);
38
+		if (is_wp_error($postId)) {
39
+			glsr_log()->error($postId->get_error_message())->debug($postValues);
40
+			return false;
41
+		}
42
+		$this->setTerms($postId, $command->category);
43
+		$review = $this->single(get_post($postId));
44
+		do_action('site-reviews/review/created', $review, $command);
45
+		return $review;
46
+	}
47 47
 
48
-    /**
49
-     * @param string $metaReviewId
50
-     * @return void
51
-     */
52
-    public function delete($metaReviewId)
53
-    {
54
-        if ($postId = $this->getPostId($metaReviewId)) {
55
-            wp_delete_post($postId, true);
56
-        }
57
-    }
48
+	/**
49
+	 * @param string $metaReviewId
50
+	 * @return void
51
+	 */
52
+	public function delete($metaReviewId)
53
+	{
54
+		if ($postId = $this->getPostId($metaReviewId)) {
55
+			wp_delete_post($postId, true);
56
+		}
57
+	}
58 58
 
59
-    /**
60
-     * @return object
61
-     */
62
-    public function get(array $args = [])
63
-    {
64
-        $args = glsr(ReviewsDefaults::class)->merge($args);
65
-        $metaQuery = glsr(QueryBuilder::class)->buildQuery(
66
-            ['assigned_to', 'type', 'rating'],
67
-            $args
68
-        );
69
-        $taxQuery = glsr(QueryBuilder::class)->buildQuery(
70
-            ['category'],
71
-            ['category' => $this->normalizeTermIds($args['category'])]
72
-        );
73
-        $paged = glsr(QueryBuilder::class)->getPaged(
74
-            wp_validate_boolean($args['pagination'])
75
-        );
76
-        $parameters = [
77
-            'meta_key' => 'pinned',
78
-            'meta_query' => $metaQuery,
79
-            'offset' => $args['offset'],
80
-            'order' => $args['order'],
81
-            'orderby' => 'meta_value '.$args['orderby'],
82
-            'paged' => glsr_get($args, 'paged', $paged),
83
-            'post__in' => $args['post__in'],
84
-            'post__not_in' => $args['post__not_in'],
85
-            'post_status' => 'publish',
86
-            'post_type' => Application::POST_TYPE,
87
-            'posts_per_page' => $args['count'],
88
-            'tax_query' => $taxQuery,
89
-        ];
90
-        $parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args);
91
-        $query = new WP_Query($parameters);
92
-        $results = array_map([$this, 'single'], $query->posts);
93
-        $reviews = new Reviews($results, $query->max_num_pages, $args);
94
-        return apply_filters('site-reviews/get/reviews', $reviews, $query);
95
-    }
59
+	/**
60
+	 * @return object
61
+	 */
62
+	public function get(array $args = [])
63
+	{
64
+		$args = glsr(ReviewsDefaults::class)->merge($args);
65
+		$metaQuery = glsr(QueryBuilder::class)->buildQuery(
66
+			['assigned_to', 'type', 'rating'],
67
+			$args
68
+		);
69
+		$taxQuery = glsr(QueryBuilder::class)->buildQuery(
70
+			['category'],
71
+			['category' => $this->normalizeTermIds($args['category'])]
72
+		);
73
+		$paged = glsr(QueryBuilder::class)->getPaged(
74
+			wp_validate_boolean($args['pagination'])
75
+		);
76
+		$parameters = [
77
+			'meta_key' => 'pinned',
78
+			'meta_query' => $metaQuery,
79
+			'offset' => $args['offset'],
80
+			'order' => $args['order'],
81
+			'orderby' => 'meta_value '.$args['orderby'],
82
+			'paged' => glsr_get($args, 'paged', $paged),
83
+			'post__in' => $args['post__in'],
84
+			'post__not_in' => $args['post__not_in'],
85
+			'post_status' => 'publish',
86
+			'post_type' => Application::POST_TYPE,
87
+			'posts_per_page' => $args['count'],
88
+			'tax_query' => $taxQuery,
89
+		];
90
+		$parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args);
91
+		$query = new WP_Query($parameters);
92
+		$results = array_map([$this, 'single'], $query->posts);
93
+		$reviews = new Reviews($results, $query->max_num_pages, $args);
94
+		return apply_filters('site-reviews/get/reviews', $reviews, $query);
95
+	}
96 96
 
97
-    /**
98
-     * @param string $metaReviewId
99
-     * @return int
100
-     */
101
-    public function getPostId($metaReviewId)
102
-    {
103
-        return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId);
104
-    }
97
+	/**
98
+	 * @param string $metaReviewId
99
+	 * @return int
100
+	 */
101
+	public function getPostId($metaReviewId)
102
+	{
103
+		return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId);
104
+	}
105 105
 
106
-    /**
107
-     * @return array
108
-     */
109
-    public function getRatingCounts(array $args = [])
110
-    {
111
-        $args = glsr(SiteReviewsSummaryDefaults::class)->filter($args);
112
-        $counts = glsr(CountsManager::class)->get([
113
-            'post_ids' => glsr(Helper::class)->convertStringToArray($args['assigned_to']),
114
-            'term_ids' => $this->normalizeTermIds($args['category']),
115
-            'type' => $args['type'],
116
-        ]);
117
-        return glsr(CountsManager::class)->flatten($counts, [
118
-            'min' => $args['rating'],
119
-        ]);
120
-    }
106
+	/**
107
+	 * @return array
108
+	 */
109
+	public function getRatingCounts(array $args = [])
110
+	{
111
+		$args = glsr(SiteReviewsSummaryDefaults::class)->filter($args);
112
+		$counts = glsr(CountsManager::class)->get([
113
+			'post_ids' => glsr(Helper::class)->convertStringToArray($args['assigned_to']),
114
+			'term_ids' => $this->normalizeTermIds($args['category']),
115
+			'type' => $args['type'],
116
+		]);
117
+		return glsr(CountsManager::class)->flatten($counts, [
118
+			'min' => $args['rating'],
119
+		]);
120
+	}
121 121
 
122
-    /**
123
-     * @param string $commaSeparatedTermIds
124
-     * @return array
125
-     */
126
-    public function normalizeTermIds($commaSeparatedTermIds)
127
-    {
128
-        $termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id');
129
-        return array_unique(array_map('intval', $termIds));
130
-    }
122
+	/**
123
+	 * @param string $commaSeparatedTermIds
124
+	 * @return array
125
+	 */
126
+	public function normalizeTermIds($commaSeparatedTermIds)
127
+	{
128
+		$termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id');
129
+		return array_unique(array_map('intval', $termIds));
130
+	}
131 131
 
132
-    /**
133
-     * @param string $commaSeparatedTermIds
134
-     * @return array
135
-     */
136
-    public function normalizeTerms($commaSeparatedTermIds)
137
-    {
138
-        $terms = [];
139
-        $termIds = glsr(Helper::class)->convertStringToArray($commaSeparatedTermIds);
140
-        foreach ($termIds as $termId) {
141
-            if (is_numeric($termId)) {
142
-                $termId = intval($termId);
143
-            }
144
-            $term = term_exists($termId, Application::TAXONOMY);
145
-            if (!isset($term['term_id'])) {
146
-                continue;
147
-            }
148
-            $terms[] = $term;
149
-        }
150
-        return $terms;
151
-    }
132
+	/**
133
+	 * @param string $commaSeparatedTermIds
134
+	 * @return array
135
+	 */
136
+	public function normalizeTerms($commaSeparatedTermIds)
137
+	{
138
+		$terms = [];
139
+		$termIds = glsr(Helper::class)->convertStringToArray($commaSeparatedTermIds);
140
+		foreach ($termIds as $termId) {
141
+			if (is_numeric($termId)) {
142
+				$termId = intval($termId);
143
+			}
144
+			$term = term_exists($termId, Application::TAXONOMY);
145
+			if (!isset($term['term_id'])) {
146
+				continue;
147
+			}
148
+			$terms[] = $term;
149
+		}
150
+		return $terms;
151
+	}
152 152
 
153
-    /**
154
-     * @param int $postId
155
-     * @return void
156
-     */
157
-    public function revert($postId)
158
-    {
159
-        if (Application::POST_TYPE != get_post_field('post_type', $postId)) {
160
-            return;
161
-        }
162
-        delete_post_meta($postId, '_edit_last');
163
-        $result = wp_update_post([
164
-            'ID' => $postId,
165
-            'post_content' => get_post_meta($postId, 'content', true),
166
-            'post_date' => get_post_meta($postId, 'date', true),
167
-            'post_title' => get_post_meta($postId, 'title', true),
168
-        ]);
169
-        if (is_wp_error($result)) {
170
-            glsr_log()->error($result->get_error_message());
171
-        }
172
-    }
153
+	/**
154
+	 * @param int $postId
155
+	 * @return void
156
+	 */
157
+	public function revert($postId)
158
+	{
159
+		if (Application::POST_TYPE != get_post_field('post_type', $postId)) {
160
+			return;
161
+		}
162
+		delete_post_meta($postId, '_edit_last');
163
+		$result = wp_update_post([
164
+			'ID' => $postId,
165
+			'post_content' => get_post_meta($postId, 'content', true),
166
+			'post_date' => get_post_meta($postId, 'date', true),
167
+			'post_title' => get_post_meta($postId, 'title', true),
168
+		]);
169
+		if (is_wp_error($result)) {
170
+			glsr_log()->error($result->get_error_message());
171
+		}
172
+	}
173 173
 
174
-    /**
175
-     * @return Review
176
-     */
177
-    public function single(WP_Post $post)
178
-    {
179
-        if (Application::POST_TYPE != $post->post_type) {
180
-            $post = new WP_Post((object) []);
181
-        }
182
-        $review = new Review($post);
183
-        return apply_filters('site-reviews/get/review', $review, $post);
184
-    }
174
+	/**
175
+	 * @return Review
176
+	 */
177
+	public function single(WP_Post $post)
178
+	{
179
+		if (Application::POST_TYPE != $post->post_type) {
180
+			$post = new WP_Post((object) []);
181
+		}
182
+		$review = new Review($post);
183
+		return apply_filters('site-reviews/get/review', $review, $post);
184
+	}
185 185
 
186
-    /**
187
-     * @param bool $isBlacklisted
188
-     * @return string
189
-     */
190
-    protected function getNewPostStatus(array $review, $isBlacklisted)
191
-    {
192
-        $requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval');
193
-        return 'local' == $review['review_type'] && ($requireApproval || $isBlacklisted)
194
-            ? 'pending'
195
-            : 'publish';
196
-    }
186
+	/**
187
+	 * @param bool $isBlacklisted
188
+	 * @return string
189
+	 */
190
+	protected function getNewPostStatus(array $review, $isBlacklisted)
191
+	{
192
+		$requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval');
193
+		return 'local' == $review['review_type'] && ($requireApproval || $isBlacklisted)
194
+			? 'pending'
195
+			: 'publish';
196
+	}
197 197
 
198
-    /**
199
-     * @param int $postId
200
-     * @param string $termIds
201
-     * @return void
202
-     */
203
-    protected function setTerms($postId, $termIds)
204
-    {
205
-        $termIds = $this->normalizeTermIds($termIds);
206
-        if (empty($termIds)) {
207
-            return;
208
-        }
209
-        $termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY);
210
-        if (is_wp_error($termTaxonomyIds)) {
211
-            glsr_log()->error($termTaxonomyIds->get_error_message());
212
-        }
213
-    }
198
+	/**
199
+	 * @param int $postId
200
+	 * @param string $termIds
201
+	 * @return void
202
+	 */
203
+	protected function setTerms($postId, $termIds)
204
+	{
205
+		$termIds = $this->normalizeTermIds($termIds);
206
+		if (empty($termIds)) {
207
+			return;
208
+		}
209
+		$termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY);
210
+		if (is_wp_error($termTaxonomyIds)) {
211
+			glsr_log()->error($termTaxonomyIds->get_error_message());
212
+		}
213
+	}
214 214
 }
Please login to merge, or discard this patch.
plugin/Database/OptionManager.php 1 patch
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -7,147 +7,147 @@
 block discarded – undo
7 7
 
8 8
 class OptionManager
9 9
 {
10
-    /**
11
-     * @var array
12
-     */
13
-    protected $options;
10
+	/**
11
+	 * @var array
12
+	 */
13
+	protected $options;
14 14
 
15
-    /**
16
-     * @return string
17
-     */
18
-    public static function databaseKey()
19
-    {
20
-        return glsr(Helper::class)->snakeCase(
21
-            Application::ID.'-v'.explode('.', glsr()->version)[0]
22
-        );
23
-    }
15
+	/**
16
+	 * @return string
17
+	 */
18
+	public static function databaseKey()
19
+	{
20
+		return glsr(Helper::class)->snakeCase(
21
+			Application::ID.'-v'.explode('.', glsr()->version)[0]
22
+		);
23
+	}
24 24
 
25
-    /**
26
-     * @return array
27
-     */
28
-    public function all()
29
-    {
30
-        if (empty($this->options)) {
31
-            $this->reset();
32
-        }
33
-        return $this->options;
34
-    }
25
+	/**
26
+	 * @return array
27
+	 */
28
+	public function all()
29
+	{
30
+		if (empty($this->options)) {
31
+			$this->reset();
32
+		}
33
+		return $this->options;
34
+	}
35 35
 
36
-    /**
37
-     * @param string $path
38
-     * @return bool
39
-     */
40
-    public function delete($path)
41
-    {
42
-        $keys = explode('.', $path);
43
-        $last = array_pop($keys);
44
-        $options = $this->all();
45
-        $pointer = &$options;
46
-        foreach ($keys as $key) {
47
-            if (!isset($pointer[$key]) || !is_array($pointer[$key])) {
48
-                continue;
49
-            }
50
-            $pointer = &$pointer[$key];
51
-        }
52
-        unset($pointer[$last]);
53
-        return $this->set($options);
54
-    }
36
+	/**
37
+	 * @param string $path
38
+	 * @return bool
39
+	 */
40
+	public function delete($path)
41
+	{
42
+		$keys = explode('.', $path);
43
+		$last = array_pop($keys);
44
+		$options = $this->all();
45
+		$pointer = &$options;
46
+		foreach ($keys as $key) {
47
+			if (!isset($pointer[$key]) || !is_array($pointer[$key])) {
48
+				continue;
49
+			}
50
+			$pointer = &$pointer[$key];
51
+		}
52
+		unset($pointer[$last]);
53
+		return $this->set($options);
54
+	}
55 55
 
56
-    /**
57
-     * @param string $path
58
-     * @param mixed $fallback
59
-     * @return mixed
60
-     */
61
-    public function get($path = '', $fallback = '')
62
-    {
63
-        return glsr(Helper::class)->dataGet($this->all(), $path, $fallback);
64
-    }
56
+	/**
57
+	 * @param string $path
58
+	 * @param mixed $fallback
59
+	 * @return mixed
60
+	 */
61
+	public function get($path = '', $fallback = '')
62
+	{
63
+		return glsr(Helper::class)->dataGet($this->all(), $path, $fallback);
64
+	}
65 65
 
66
-    /**
67
-     * @param string $path
68
-     * @return bool
69
-     */
70
-    public function getBool($path)
71
-    {
72
-        return 'yes' == $this->get($path)
73
-            ? true
74
-            : false;
75
-    }
66
+	/**
67
+	 * @param string $path
68
+	 * @return bool
69
+	 */
70
+	public function getBool($path)
71
+	{
72
+		return 'yes' == $this->get($path)
73
+			? true
74
+			: false;
75
+	}
76 76
 
77
-    /**
78
-     * @param string $path
79
-     * @param mixed $fallback
80
-     * @return mixed
81
-     */
82
-    public function getWP($path, $fallback = '')
83
-    {
84
-        $option = get_option($path, $fallback);
85
-        return empty($option)
86
-            ? $fallback
87
-            : $option;
88
-    }
77
+	/**
78
+	 * @param string $path
79
+	 * @param mixed $fallback
80
+	 * @return mixed
81
+	 */
82
+	public function getWP($path, $fallback = '')
83
+	{
84
+		$option = get_option($path, $fallback);
85
+		return empty($option)
86
+			? $fallback
87
+			: $option;
88
+	}
89 89
 
90
-    /**
91
-     * @return string
92
-     */
93
-    public function json()
94
-    {
95
-        return json_encode($this->all());
96
-    }
90
+	/**
91
+	 * @return string
92
+	 */
93
+	public function json()
94
+	{
95
+		return json_encode($this->all());
96
+	}
97 97
 
98
-    /**
99
-     * @return array
100
-     */
101
-    public function normalize(array $options = [])
102
-    {
103
-        $options = wp_parse_args(
104
-            glsr(Helper::class)->flattenArray($options),
105
-            glsr(DefaultsManager::class)->defaults()
106
-        );
107
-        array_walk($options, function (&$value) {
108
-            if (!is_string($value)) {
109
-                return;
110
-            }
111
-            $value = wp_kses($value, wp_kses_allowed_html('post'));
112
-        });
113
-        return glsr(Helper::class)->convertDotNotationArray($options);
114
-    }
98
+	/**
99
+	 * @return array
100
+	 */
101
+	public function normalize(array $options = [])
102
+	{
103
+		$options = wp_parse_args(
104
+			glsr(Helper::class)->flattenArray($options),
105
+			glsr(DefaultsManager::class)->defaults()
106
+		);
107
+		array_walk($options, function (&$value) {
108
+			if (!is_string($value)) {
109
+				return;
110
+			}
111
+			$value = wp_kses($value, wp_kses_allowed_html('post'));
112
+		});
113
+		return glsr(Helper::class)->convertDotNotationArray($options);
114
+	}
115 115
 
116
-    /**
117
-     * @return bool
118
-     */
119
-    public function isRecaptchaEnabled()
120
-    {
121
-        $integration = $this->get('settings.submissions.recaptcha.integration');
122
-        return 'all' == $integration || ('guest' == $integration && !is_user_logged_in());
123
-    }
116
+	/**
117
+	 * @return bool
118
+	 */
119
+	public function isRecaptchaEnabled()
120
+	{
121
+		$integration = $this->get('settings.submissions.recaptcha.integration');
122
+		return 'all' == $integration || ('guest' == $integration && !is_user_logged_in());
123
+	}
124 124
 
125
-    /**
126
-     * @return array
127
-     */
128
-    public function reset()
129
-    {
130
-        $options = get_option(static::databaseKey(), []);
131
-        if (!is_array($options) || empty($options)) {
132
-            delete_option(static::databaseKey());
133
-            $options = wp_parse_args(glsr()->defaults, ['settings' => []]);
134
-        }
135
-        $this->options = $options;
136
-    }
125
+	/**
126
+	 * @return array
127
+	 */
128
+	public function reset()
129
+	{
130
+		$options = get_option(static::databaseKey(), []);
131
+		if (!is_array($options) || empty($options)) {
132
+			delete_option(static::databaseKey());
133
+			$options = wp_parse_args(glsr()->defaults, ['settings' => []]);
134
+		}
135
+		$this->options = $options;
136
+	}
137 137
 
138
-    /**
139
-     * @param string|array $pathOrOptions
140
-     * @param mixed $value
141
-     * @return bool
142
-     */
143
-    public function set($pathOrOptions, $value = '')
144
-    {
145
-        if (is_string($pathOrOptions)) {
146
-            $pathOrOptions = glsr(Helper::class)->dataSet($this->all(), $pathOrOptions, $value);
147
-        }
148
-        if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) {
149
-            $this->reset();
150
-        }
151
-        return $result;
152
-    }
138
+	/**
139
+	 * @param string|array $pathOrOptions
140
+	 * @param mixed $value
141
+	 * @return bool
142
+	 */
143
+	public function set($pathOrOptions, $value = '')
144
+	{
145
+		if (is_string($pathOrOptions)) {
146
+			$pathOrOptions = glsr(Helper::class)->dataSet($this->all(), $pathOrOptions, $value);
147
+		}
148
+		if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) {
149
+			$this->reset();
150
+		}
151
+		return $result;
152
+	}
153 153
 }
Please login to merge, or discard this patch.
plugin/Reviews.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -9,65 +9,65 @@
 block discarded – undo
9 9
 
10 10
 class Reviews extends ArrayObject
11 11
 {
12
-    /**
13
-     * @var array
14
-     */
15
-    public $args;
12
+	/**
13
+	 * @var array
14
+	 */
15
+	public $args;
16 16
 
17
-    /**
18
-     * @var int
19
-     */
20
-    public $max_num_pages;
17
+	/**
18
+	 * @var int
19
+	 */
20
+	public $max_num_pages;
21 21
 
22
-    /**
23
-     * @var array
24
-     */
25
-    public $reviews;
22
+	/**
23
+	 * @var array
24
+	 */
25
+	public $reviews;
26 26
 
27
-    public function __construct(array $reviews, $maxPageCount, array $args)
28
-    {
29
-        $this->args = $args;
30
-        $this->max_num_pages = $maxPageCount;
31
-        $this->reviews = $reviews;
32
-        parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
33
-    }
27
+	public function __construct(array $reviews, $maxPageCount, array $args)
28
+	{
29
+		$this->args = $args;
30
+		$this->max_num_pages = $maxPageCount;
31
+		$this->reviews = $reviews;
32
+		parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
33
+	}
34 34
 
35
-    /**
36
-     * @return string
37
-     */
38
-    public function __toString()
39
-    {
40
-        return (string) $this->build();
41
-    }
35
+	/**
36
+	 * @return string
37
+	 */
38
+	public function __toString()
39
+	{
40
+		return (string) $this->build();
41
+	}
42 42
 
43
-    /**
44
-     * @return ReviewsHtml
45
-     */
46
-    public function build()
47
-    {
48
-        $args = glsr(SiteReviewsDefaults::class)->merge($this->args);
49
-        return glsr(SiteReviewsPartial::class)->build($args, $this);
50
-    }
43
+	/**
44
+	 * @return ReviewsHtml
45
+	 */
46
+	public function build()
47
+	{
48
+		$args = glsr(SiteReviewsDefaults::class)->merge($this->args);
49
+		return glsr(SiteReviewsPartial::class)->build($args, $this);
50
+	}
51 51
 
52
-    /**
53
-     * @param mixed $key
54
-     * @return mixed
55
-     */
56
-    public function offsetGet($key)
57
-    {
58
-        if (property_exists($this, $key)) {
59
-            return $this->{$key};
60
-        }
61
-        return array_key_exists($key, $this->reviews)
62
-            ? $this->reviews[$key]
63
-            : null;
64
-    }
52
+	/**
53
+	 * @param mixed $key
54
+	 * @return mixed
55
+	 */
56
+	public function offsetGet($key)
57
+	{
58
+		if (property_exists($this, $key)) {
59
+			return $this->{$key};
60
+		}
61
+		return array_key_exists($key, $this->reviews)
62
+			? $this->reviews[$key]
63
+			: null;
64
+	}
65 65
 
66
-    /**
67
-     * @return void
68
-     */
69
-    public function render()
70
-    {
71
-        echo $this->build();
72
-    }
66
+	/**
67
+	 * @return void
68
+	 */
69
+	public function render()
70
+	{
71
+		echo $this->build();
72
+	}
73 73
 }
Please login to merge, or discard this patch.
plugin/Filters.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -13,61 +13,61 @@
 block discarded – undo
13 13
 
14 14
 class Filters implements HooksContract
15 15
 {
16
-    protected $app;
17
-    protected $admin;
18
-    protected $basename;
19
-    protected $blocks;
20
-    protected $editor;
21
-    protected $listtable;
22
-    protected $main;
23
-    protected $public;
24
-    protected $translator;
16
+	protected $app;
17
+	protected $admin;
18
+	protected $basename;
19
+	protected $blocks;
20
+	protected $editor;
21
+	protected $listtable;
22
+	protected $main;
23
+	protected $public;
24
+	protected $translator;
25 25
 
26
-    public function __construct(Application $app)
27
-    {
28
-        $this->app = $app;
29
-        $this->admin = $app->make(AdminController::class);
30
-        $this->basename = plugin_basename($app->file);
31
-        $this->blocks = $app->make(BlocksController::class);
32
-        $this->editor = $app->make(EditorController::class);
33
-        $this->listtable = $app->make(ListTableController::class);
34
-        $this->main = $app->make(MainController::class);
35
-        $this->public = $app->make(PublicController::class);
36
-        $this->translator = $app->make(Translator::class);
37
-    }
26
+	public function __construct(Application $app)
27
+	{
28
+		$this->app = $app;
29
+		$this->admin = $app->make(AdminController::class);
30
+		$this->basename = plugin_basename($app->file);
31
+		$this->blocks = $app->make(BlocksController::class);
32
+		$this->editor = $app->make(EditorController::class);
33
+		$this->listtable = $app->make(ListTableController::class);
34
+		$this->main = $app->make(MainController::class);
35
+		$this->public = $app->make(PublicController::class);
36
+		$this->translator = $app->make(Translator::class);
37
+	}
38 38
 
39
-    /**
40
-     * @return void
41
-     */
42
-    public function run()
43
-    {
44
-        add_filter('map_meta_cap',                                            [$this->admin, 'filterCreateCapability'], 10, 2);
45
-        add_filter('mce_external_plugins',                                    [$this->admin, 'filterTinymcePlugins'], 15);
46
-        add_filter('plugin_action_links_'.$this->basename,                    [$this->admin, 'filterActionLinks']);
47
-        add_filter('dashboard_glance_items',                                  [$this->admin, 'filterDashboardGlanceItems']);
48
-        add_filter('block_categories',                                        [$this->blocks, 'filterBlockCategories']);
49
-        add_filter('classic_editor_enabled_editors_for_post_type',            [$this->blocks, 'filterEnabledEditors'], 10, 2);
50
-        add_filter('use_block_editor_for_post_type',                          [$this->blocks, 'filterUseBlockEditor'], 10, 2);
51
-        add_filter('wp_editor_settings',                                      [$this->editor, 'filterEditorSettings']);
52
-        add_filter('the_editor',                                              [$this->editor, 'filterEditorTextarea']);
53
-        add_filter('gettext',                                                 [$this->editor, 'filterPostStatusLabels'], 10, 3);
54
-        add_filter('gettext_with_context',                                    [$this->editor, 'filterPostStatusLabelsWithContext'], 10, 4);
55
-        add_filter('post_updated_messages',                                   [$this->editor, 'filterUpdateMessages']);
56
-        add_filter('bulk_post_updated_messages',                              [$this->listtable, 'filterBulkUpdateMessages'], 10, 2);
57
-        add_filter('manage_'.Application::POST_TYPE.'_posts_columns',         [$this->listtable, 'filterColumnsForPostType']);
58
-        add_filter('post_date_column_status',                                 [$this->listtable, 'filterDateColumnStatus'], 10, 2);
59
-        add_filter('default_hidden_columns',                                  [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2);
60
-        add_filter('display_post_states',                                     [$this->listtable, 'filterPostStates'], 10, 2);
61
-        add_filter('post_row_actions',                                        [$this->listtable, 'filterRowActions'], 10, 2);
62
-        add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns']);
63
-        add_filter('ngettext',                                                [$this->listtable, 'filterStatusText'], 10, 5);
64
-        add_filter('script_loader_tag',                                       [$this->public, 'filterEnqueuedScripts'], 10, 2);
65
-        add_filter('site-reviews/config/forms/submission-form',               [$this->public, 'filterFieldOrder'], 11);
66
-        add_filter('query_vars',                                              [$this->public, 'filterQueryVars']);
67
-        add_filter('site-reviews/render/view',                                [$this->public, 'filterRenderView']);
68
-        add_filter('gettext',                                                 [$this->translator, 'filterGettext'], 10, 3);
69
-        add_filter('gettext_with_context',                                    [$this->translator, 'filterGettextWithContext'], 10, 4);
70
-        add_filter('ngettext',                                                [$this->translator, 'filterNgettext'], 10, 5);
71
-        add_filter('ngettext_with_context',                                   [$this->translator, 'filterNgettextWithContext'], 10, 6);
72
-    }
39
+	/**
40
+	 * @return void
41
+	 */
42
+	public function run()
43
+	{
44
+		add_filter('map_meta_cap',                                            [$this->admin, 'filterCreateCapability'], 10, 2);
45
+		add_filter('mce_external_plugins',                                    [$this->admin, 'filterTinymcePlugins'], 15);
46
+		add_filter('plugin_action_links_'.$this->basename,                    [$this->admin, 'filterActionLinks']);
47
+		add_filter('dashboard_glance_items',                                  [$this->admin, 'filterDashboardGlanceItems']);
48
+		add_filter('block_categories',                                        [$this->blocks, 'filterBlockCategories']);
49
+		add_filter('classic_editor_enabled_editors_for_post_type',            [$this->blocks, 'filterEnabledEditors'], 10, 2);
50
+		add_filter('use_block_editor_for_post_type',                          [$this->blocks, 'filterUseBlockEditor'], 10, 2);
51
+		add_filter('wp_editor_settings',                                      [$this->editor, 'filterEditorSettings']);
52
+		add_filter('the_editor',                                              [$this->editor, 'filterEditorTextarea']);
53
+		add_filter('gettext',                                                 [$this->editor, 'filterPostStatusLabels'], 10, 3);
54
+		add_filter('gettext_with_context',                                    [$this->editor, 'filterPostStatusLabelsWithContext'], 10, 4);
55
+		add_filter('post_updated_messages',                                   [$this->editor, 'filterUpdateMessages']);
56
+		add_filter('bulk_post_updated_messages',                              [$this->listtable, 'filterBulkUpdateMessages'], 10, 2);
57
+		add_filter('manage_'.Application::POST_TYPE.'_posts_columns',         [$this->listtable, 'filterColumnsForPostType']);
58
+		add_filter('post_date_column_status',                                 [$this->listtable, 'filterDateColumnStatus'], 10, 2);
59
+		add_filter('default_hidden_columns',                                  [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2);
60
+		add_filter('display_post_states',                                     [$this->listtable, 'filterPostStates'], 10, 2);
61
+		add_filter('post_row_actions',                                        [$this->listtable, 'filterRowActions'], 10, 2);
62
+		add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns']);
63
+		add_filter('ngettext',                                                [$this->listtable, 'filterStatusText'], 10, 5);
64
+		add_filter('script_loader_tag',                                       [$this->public, 'filterEnqueuedScripts'], 10, 2);
65
+		add_filter('site-reviews/config/forms/submission-form',               [$this->public, 'filterFieldOrder'], 11);
66
+		add_filter('query_vars',                                              [$this->public, 'filterQueryVars']);
67
+		add_filter('site-reviews/render/view',                                [$this->public, 'filterRenderView']);
68
+		add_filter('gettext',                                                 [$this->translator, 'filterGettext'], 10, 3);
69
+		add_filter('gettext_with_context',                                    [$this->translator, 'filterGettextWithContext'], 10, 4);
70
+		add_filter('ngettext',                                                [$this->translator, 'filterNgettext'], 10, 5);
71
+		add_filter('ngettext_with_context',                                   [$this->translator, 'filterNgettextWithContext'], 10, 6);
72
+	}
73 73
 }
Please login to merge, or discard this patch.
plugin/Blocks/SiteReviewsSummaryBlock.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -6,83 +6,83 @@
 block discarded – undo
6 6
 
7 7
 class SiteReviewsSummaryBlock extends BlockGenerator
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    public function attributes()
13
-    {
14
-        return [
15
-            'assigned_to' => [
16
-                'default' => '',
17
-                'type' => 'string',
18
-            ],
19
-            'category' => [
20
-                'default' => '',
21
-                'type' => 'string',
22
-            ],
23
-            'className' => [
24
-                'default' => '',
25
-                'type' => 'string',
26
-            ],
27
-            'hide' => [
28
-                'default' => '',
29
-                'type' => 'string',
30
-            ],
31
-            'post_id' => [
32
-                'default' => '',
33
-                'type' => 'string',
34
-            ],
35
-            'rating' => [
36
-                'default' => '1',
37
-                'type' => 'number',
38
-            ],
39
-            'schema' => [
40
-                'default' => false,
41
-                'type' => 'boolean',
42
-            ],
43
-            'type' => [
44
-                'default' => 'local',
45
-                'type' => 'string',
46
-            ],
47
-        ];
48
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	public function attributes()
13
+	{
14
+		return [
15
+			'assigned_to' => [
16
+				'default' => '',
17
+				'type' => 'string',
18
+			],
19
+			'category' => [
20
+				'default' => '',
21
+				'type' => 'string',
22
+			],
23
+			'className' => [
24
+				'default' => '',
25
+				'type' => 'string',
26
+			],
27
+			'hide' => [
28
+				'default' => '',
29
+				'type' => 'string',
30
+			],
31
+			'post_id' => [
32
+				'default' => '',
33
+				'type' => 'string',
34
+			],
35
+			'rating' => [
36
+				'default' => '1',
37
+				'type' => 'number',
38
+			],
39
+			'schema' => [
40
+				'default' => false,
41
+				'type' => 'boolean',
42
+			],
43
+			'type' => [
44
+				'default' => 'local',
45
+				'type' => 'string',
46
+			],
47
+		];
48
+	}
49 49
 
50
-    /**
51
-     * @return string
52
-     */
53
-    public function render(array $attributes)
54
-    {
55
-        $attributes['class'] = $attributes['className'];
56
-        $shortcode = glsr(Shortcode::class);
57
-        if ('edit' == filter_input(INPUT_GET, 'context')) {
58
-            $attributes = $this->normalize($attributes);
59
-            $this->filterShortcodeClass();
60
-            if (!$this->hasVisibleFields($shortcode, $attributes)) {
61
-                $this->filterInterpolation();
62
-            }
63
-        }
64
-        return $shortcode->buildShortcode($attributes);
65
-    }
50
+	/**
51
+	 * @return string
52
+	 */
53
+	public function render(array $attributes)
54
+	{
55
+		$attributes['class'] = $attributes['className'];
56
+		$shortcode = glsr(Shortcode::class);
57
+		if ('edit' == filter_input(INPUT_GET, 'context')) {
58
+			$attributes = $this->normalize($attributes);
59
+			$this->filterShortcodeClass();
60
+			if (!$this->hasVisibleFields($shortcode, $attributes)) {
61
+				$this->filterInterpolation();
62
+			}
63
+		}
64
+		return $shortcode->buildShortcode($attributes);
65
+	}
66 66
 
67
-    /**
68
-     * @return void
69
-     */
70
-    protected function filterInterpolation()
71
-    {
72
-        add_filter('site-reviews/interpolate/reviews-summary', function ($context) {
73
-            $context['class'] = 'glsr-default glsr-block-disabled';
74
-            $context['text'] = __('You have hidden all of the fields for this block.', 'site-reviews');
75
-            return $context;
76
-        });
77
-    }
67
+	/**
68
+	 * @return void
69
+	 */
70
+	protected function filterInterpolation()
71
+	{
72
+		add_filter('site-reviews/interpolate/reviews-summary', function ($context) {
73
+			$context['class'] = 'glsr-default glsr-block-disabled';
74
+			$context['text'] = __('You have hidden all of the fields for this block.', 'site-reviews');
75
+			return $context;
76
+		});
77
+	}
78 78
 
79
-    /**
80
-     * @return void
81
-     */
82
-    protected function filterShortcodeClass()
83
-    {
84
-        add_filter('site-reviews/style', function () {
85
-            return 'default';
86
-        });
87
-    }
79
+	/**
80
+	 * @return void
81
+	 */
82
+	protected function filterShortcodeClass()
83
+	{
84
+		add_filter('site-reviews/style', function () {
85
+			return 'default';
86
+		});
87
+	}
88 88
 }
Please login to merge, or discard this patch.