Passed
Push — master ( b19f24...47cb12 )
by Paul
04:18
created
plugin/Modules/Html/Partials/Pagination.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -11,74 +11,74 @@
 block discarded – undo
11 11
 
12 12
 class Pagination implements PartialContract
13 13
 {
14
-    /**
15
-     * @var array
16
-     */
17
-    protected $args;
14
+	/**
15
+	 * @var array
16
+	 */
17
+	protected $args;
18 18
 
19
-    /**
20
-     * @return string
21
-     */
22
-    public function build(array $args = [])
23
-    {
24
-        $this->args = $this->normalize($args);
25
-        if ($this->args['total'] < 2) {
26
-            return '';
27
-        }
28
-        return glsr(Template::class)->build('templates/pagination', [
29
-            'context' => [
30
-                'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args),
31
-                'loader' => '<div class="glsr-loader"></div>',
32
-                'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'),
33
-            ],
34
-        ]);
35
-    }
19
+	/**
20
+	 * @return string
21
+	 */
22
+	public function build(array $args = [])
23
+	{
24
+		$this->args = $this->normalize($args);
25
+		if ($this->args['total'] < 2) {
26
+			return '';
27
+		}
28
+		return glsr(Template::class)->build('templates/pagination', [
29
+			'context' => [
30
+				'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args),
31
+				'loader' => '<div class="glsr-loader"></div>',
32
+				'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'),
33
+			],
34
+		]);
35
+	}
36 36
 
37
-    /**
38
-     * @return string
39
-     */
40
-    protected function buildFauxLinks()
41
-    {
42
-        $links = paginate_links(wp_parse_args(['type' => 'array'], $this->args));
43
-        $pattern = '/(href=["\'])([^"\']*?)(["\'])/i';
44
-        foreach ($links as &$link) {
45
-            if (!preg_match($pattern, $link, $matches)) {
46
-                continue;
47
-            }
48
-            parse_str(parse_url(Arr::get($matches, 2), PHP_URL_QUERY), $urlQuery);
49
-            $page = (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1);
50
-            $replacement = sprintf('data-page="%d" href="#"', $page);
51
-            $link = str_replace(Arr::get($matches, 0), $replacement, $link);
52
-        }
53
-        return implode("\n", $links);
54
-    }
37
+	/**
38
+	 * @return string
39
+	 */
40
+	protected function buildFauxLinks()
41
+	{
42
+		$links = paginate_links(wp_parse_args(['type' => 'array'], $this->args));
43
+		$pattern = '/(href=["\'])([^"\']*?)(["\'])/i';
44
+		foreach ($links as &$link) {
45
+			if (!preg_match($pattern, $link, $matches)) {
46
+				continue;
47
+			}
48
+			parse_str(parse_url(Arr::get($matches, 2), PHP_URL_QUERY), $urlQuery);
49
+			$page = (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1);
50
+			$replacement = sprintf('data-page="%d" href="#"', $page);
51
+			$link = str_replace(Arr::get($matches, 0), $replacement, $link);
52
+		}
53
+		return implode("\n", $links);
54
+	}
55 55
 
56
-    /**
57
-     * @return string
58
-     */
59
-    protected function buildLinks()
60
-    {
61
-        return glsr(OptionManager::class)->getBool('settings.reviews.pagination.url_parameter')
62
-            ? paginate_links($this->args)
63
-            : $this->buildFauxLinks();
64
-    }
56
+	/**
57
+	 * @return string
58
+	 */
59
+	protected function buildLinks()
60
+	{
61
+		return glsr(OptionManager::class)->getBool('settings.reviews.pagination.url_parameter')
62
+			? paginate_links($this->args)
63
+			: $this->buildFauxLinks();
64
+	}
65 65
 
66
-    /**
67
-     * @return array
68
-     */
69
-    protected function normalize(array $args)
70
-    {
71
-        if ($baseUrl = Arr::get($args, 'baseUrl')) {
72
-            $args['base'] = $baseUrl.'%_%';
73
-        }
74
-        $args = wp_parse_args(array_filter($args), [
75
-            'current' => glsr(QueryBuilder::class)->getPaged(),
76
-            'total' => 1,
77
-        ]);
78
-        $args = glsr(Style::class)->paginationArgs($args);
79
-        if ('array' == $args['type']) {
80
-            $args['type'] = 'plain';
81
-        }
82
-        return $args;
83
-    }
66
+	/**
67
+	 * @return array
68
+	 */
69
+	protected function normalize(array $args)
70
+	{
71
+		if ($baseUrl = Arr::get($args, 'baseUrl')) {
72
+			$args['base'] = $baseUrl.'%_%';
73
+		}
74
+		$args = wp_parse_args(array_filter($args), [
75
+			'current' => glsr(QueryBuilder::class)->getPaged(),
76
+			'total' => 1,
77
+		]);
78
+		$args = glsr(Style::class)->paginationArgs($args);
79
+		if ('array' == $args['type']) {
80
+			$args['type'] = 'plain';
81
+		}
82
+		return $args;
83
+	}
84 84
 }
Please login to merge, or discard this patch.
plugin/Controllers/AjaxController.php 1 patch
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -15,195 +15,195 @@
 block discarded – undo
15 15
 
16 16
 class AjaxController extends Controller
17 17
 {
18
-    /**
19
-     * @return void
20
-     */
21
-    public function routerChangeStatus(array $request)
22
-    {
23
-        wp_send_json_success($this->execute(new ChangeStatus($request)));
24
-    }
18
+	/**
19
+	 * @return void
20
+	 */
21
+	public function routerChangeStatus(array $request)
22
+	{
23
+		wp_send_json_success($this->execute(new ChangeStatus($request)));
24
+	}
25 25
 
26
-    /**
27
-     * @return void
28
-     */
29
-    public function routerClearConsole()
30
-    {
31
-        glsr(AdminController::class)->routerClearConsole();
32
-        wp_send_json_success([
33
-            'console' => glsr(Console::class)->get(),
34
-            'notices' => glsr(Notice::class)->get(),
35
-        ]);
36
-    }
26
+	/**
27
+	 * @return void
28
+	 */
29
+	public function routerClearConsole()
30
+	{
31
+		glsr(AdminController::class)->routerClearConsole();
32
+		wp_send_json_success([
33
+			'console' => glsr(Console::class)->get(),
34
+			'notices' => glsr(Notice::class)->get(),
35
+		]);
36
+	}
37 37
 
38
-    /**
39
-     * @return void
40
-     */
41
-    public function routerCountReviews()
42
-    {
43
-        glsr(AdminController::class)->routerCountReviews();
44
-        wp_send_json_success([
45
-            'notices' => glsr(Notice::class)->get(),
46
-        ]);
47
-    }
38
+	/**
39
+	 * @return void
40
+	 */
41
+	public function routerCountReviews()
42
+	{
43
+		glsr(AdminController::class)->routerCountReviews();
44
+		wp_send_json_success([
45
+			'notices' => glsr(Notice::class)->get(),
46
+		]);
47
+	}
48 48
 
49
-    /**
50
-     * @return void
51
-     */
52
-    public function routerMigrateReviews()
53
-    {
54
-        glsr(AdminController::class)->routerMigrateReviews();
55
-        wp_send_json_success([
56
-            'notices' => glsr(Notice::class)->get(),
57
-        ]);
58
-    }
49
+	/**
50
+	 * @return void
51
+	 */
52
+	public function routerMigrateReviews()
53
+	{
54
+		glsr(AdminController::class)->routerMigrateReviews();
55
+		wp_send_json_success([
56
+			'notices' => glsr(Notice::class)->get(),
57
+		]);
58
+	}
59 59
 
60
-    /**
61
-     * @return void
62
-     */
63
-    public function routerDismissNotice(array $request)
64
-    {
65
-        glsr(NoticeController::class)->routerDismissNotice($request);
66
-        wp_send_json_success();
67
-    }
60
+	/**
61
+	 * @return void
62
+	 */
63
+	public function routerDismissNotice(array $request)
64
+	{
65
+		glsr(NoticeController::class)->routerDismissNotice($request);
66
+		wp_send_json_success();
67
+	}
68 68
 
69
-    /**
70
-     * @return void
71
-     */
72
-    public function routerMceShortcode(array $request)
73
-    {
74
-        $shortcode = $request['shortcode'];
75
-        $response = false;
76
-        if (array_key_exists($shortcode, glsr()->mceShortcodes)) {
77
-            $data = glsr()->mceShortcodes[$shortcode];
78
-            if (!empty($data['errors'])) {
79
-                $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')];
80
-            }
81
-            $response = [
82
-                'body' => $data['fields'],
83
-                'close' => $data['btn_close'],
84
-                'ok' => $data['btn_okay'],
85
-                'shortcode' => $shortcode,
86
-                'title' => $data['title'],
87
-            ];
88
-        }
89
-        wp_send_json_success($response);
90
-    }
69
+	/**
70
+	 * @return void
71
+	 */
72
+	public function routerMceShortcode(array $request)
73
+	{
74
+		$shortcode = $request['shortcode'];
75
+		$response = false;
76
+		if (array_key_exists($shortcode, glsr()->mceShortcodes)) {
77
+			$data = glsr()->mceShortcodes[$shortcode];
78
+			if (!empty($data['errors'])) {
79
+				$data['btn_okay'] = [esc_html__('Okay', 'site-reviews')];
80
+			}
81
+			$response = [
82
+				'body' => $data['fields'],
83
+				'close' => $data['btn_close'],
84
+				'ok' => $data['btn_okay'],
85
+				'shortcode' => $shortcode,
86
+				'title' => $data['title'],
87
+			];
88
+		}
89
+		wp_send_json_success($response);
90
+	}
91 91
 
92
-    /**
93
-     * @return void
94
-     */
95
-    public function routerFetchConsole()
96
-    {
97
-        glsr(AdminController::class)->routerFetchConsole();
98
-        wp_send_json_success([
99
-            'console' => glsr(Console::class)->get(),
100
-            'notices' => glsr(Notice::class)->get(),
101
-        ]);
102
-    }
92
+	/**
93
+	 * @return void
94
+	 */
95
+	public function routerFetchConsole()
96
+	{
97
+		glsr(AdminController::class)->routerFetchConsole();
98
+		wp_send_json_success([
99
+			'console' => glsr(Console::class)->get(),
100
+			'notices' => glsr(Notice::class)->get(),
101
+		]);
102
+	}
103 103
 
104
-    /**
105
-     * @return void
106
-     */
107
-    public function routerResetPermissions()
108
-    {
109
-        glsr(Role::class)->resetAll();
110
-        glsr(Notice::class)->clear()->addSuccess(__('The permissions have been reset, please reload the page for them to take effect.', 'site-reviews'));
111
-        wp_send_json_success([
112
-            'notices' => glsr(Notice::class)->get(),
113
-        ]);
114
-    }
104
+	/**
105
+	 * @return void
106
+	 */
107
+	public function routerResetPermissions()
108
+	{
109
+		glsr(Role::class)->resetAll();
110
+		glsr(Notice::class)->clear()->addSuccess(__('The permissions have been reset, please reload the page for them to take effect.', 'site-reviews'));
111
+		wp_send_json_success([
112
+			'notices' => glsr(Notice::class)->get(),
113
+		]);
114
+	}
115 115
 
116
-    /**
117
-     * @return void
118
-     */
119
-    public function routerSearchPosts(array $request)
120
-    {
121
-        $results = glsr(Database::class)->searchPosts($request['search']);
122
-        wp_send_json_success([
123
-            'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
124
-            'items' => $results,
125
-        ]);
126
-    }
116
+	/**
117
+	 * @return void
118
+	 */
119
+	public function routerSearchPosts(array $request)
120
+	{
121
+		$results = glsr(Database::class)->searchPosts($request['search']);
122
+		wp_send_json_success([
123
+			'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
124
+			'items' => $results,
125
+		]);
126
+	}
127 127
 
128
-    /**
129
-     * @return void
130
-     */
131
-    public function routerSearchTranslations(array $request)
132
-    {
133
-        if (empty($request['exclude'])) {
134
-            $request['exclude'] = [];
135
-        }
136
-        $results = glsr(Translation::class)
137
-            ->search($request['search'])
138
-            ->exclude()
139
-            ->exclude($request['exclude'])
140
-            ->renderResults();
141
-        wp_send_json_success([
142
-            'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
143
-            'items' => $results,
144
-        ]);
145
-    }
128
+	/**
129
+	 * @return void
130
+	 */
131
+	public function routerSearchTranslations(array $request)
132
+	{
133
+		if (empty($request['exclude'])) {
134
+			$request['exclude'] = [];
135
+		}
136
+		$results = glsr(Translation::class)
137
+			->search($request['search'])
138
+			->exclude()
139
+			->exclude($request['exclude'])
140
+			->renderResults();
141
+		wp_send_json_success([
142
+			'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>',
143
+			'items' => $results,
144
+		]);
145
+	}
146 146
 
147
-    /**
148
-     * @return void
149
-     */
150
-    public function routerSubmitReview(array $request)
151
-    {
152
-        $command = glsr(PublicController::class)->routerSubmitReview($request);
153
-        $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true)));
154
-        $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command);
155
-        $data = [
156
-            'errors' => glsr()->sessionGet($command->form_id.'errors', false),
157
-            'message' => glsr()->sessionGet($command->form_id.'message', ''),
158
-            'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false),
159
-            'redirect' => $redirect,
160
-        ];
161
-        if (false === $data['errors']) {
162
-            glsr()->sessionClear();
163
-            wp_send_json_success($data);
164
-        }
165
-        wp_send_json_error($data);
166
-    }
147
+	/**
148
+	 * @return void
149
+	 */
150
+	public function routerSubmitReview(array $request)
151
+	{
152
+		$command = glsr(PublicController::class)->routerSubmitReview($request);
153
+		$redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true)));
154
+		$redirect = apply_filters('site-reviews/review/redirect', $redirect, $command);
155
+		$data = [
156
+			'errors' => glsr()->sessionGet($command->form_id.'errors', false),
157
+			'message' => glsr()->sessionGet($command->form_id.'message', ''),
158
+			'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false),
159
+			'redirect' => $redirect,
160
+		];
161
+		if (false === $data['errors']) {
162
+			glsr()->sessionClear();
163
+			wp_send_json_success($data);
164
+		}
165
+		wp_send_json_error($data);
166
+	}
167 167
 
168
-    /**
169
-     * @return void
170
-     */
171
-    public function routerFetchPagedReviews(array $request)
172
-    {
173
-        $args = [
174
-            'paged' => Arr::get($request, 'page', false),
175
-            'pagedUrl' => '',
176
-            'pagination' => 'ajax',
177
-            'schema' => false,
178
-        ];
179
-        if (!$args['paged']) {
180
-            $homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH));
181
-            $urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH));
182
-            $urlQuery = [];
183
-            parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery);
184
-            $args['paged'] = (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1);
185
-            $args['pagedUrl'] = $homePath === $urlPath
186
-                ? trailingslashit(home_url())
187
-                : trailingslashit(home_url($urlPath));
188
-        }
189
-        $atts = (array) json_decode(Arr::get($request, 'atts'));
190
-        $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts);
191
-        $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts));
192
-        return wp_send_json_success([
193
-            'pagination' => $html->getPagination(),
194
-            'reviews' => $html->getReviews(),
195
-        ]);
196
-    }
168
+	/**
169
+	 * @return void
170
+	 */
171
+	public function routerFetchPagedReviews(array $request)
172
+	{
173
+		$args = [
174
+			'paged' => Arr::get($request, 'page', false),
175
+			'pagedUrl' => '',
176
+			'pagination' => 'ajax',
177
+			'schema' => false,
178
+		];
179
+		if (!$args['paged']) {
180
+			$homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH));
181
+			$urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH));
182
+			$urlQuery = [];
183
+			parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery);
184
+			$args['paged'] = (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1);
185
+			$args['pagedUrl'] = $homePath === $urlPath
186
+				? trailingslashit(home_url())
187
+				: trailingslashit(home_url($urlPath));
188
+		}
189
+		$atts = (array) json_decode(Arr::get($request, 'atts'));
190
+		$atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts);
191
+		$html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts));
192
+		return wp_send_json_success([
193
+			'pagination' => $html->getPagination(),
194
+			'reviews' => $html->getReviews(),
195
+		]);
196
+	}
197 197
 
198
-    /**
199
-     * @return void
200
-     */
201
-    public function routerTogglePinned(array $request)
202
-    {
203
-        $isPinned = $this->execute(new TogglePinned($request));
204
-        wp_send_json_success([
205
-            'notices' => glsr(Notice::class)->get(),
206
-            'pinned' => $isPinned,
207
-        ]);
208
-    }
198
+	/**
199
+	 * @return void
200
+	 */
201
+	public function routerTogglePinned(array $request)
202
+	{
203
+		$isPinned = $this->execute(new TogglePinned($request));
204
+		wp_send_json_success([
205
+			'notices' => glsr(Notice::class)->get(),
206
+			'pinned' => $isPinned,
207
+		]);
208
+	}
209 209
 }
Please login to merge, or discard this patch.