Skip to content

Commit be119d1

Browse files
committed
linting + coding standards
1 parent 0f5141d commit be119d1

18 files changed

+1126
-1391
lines changed

admin/CF7_AntiSpam_Admin_Charts.php

Lines changed: 87 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -22,60 +22,62 @@ class CF7_AntiSpam_Admin_Charts {
2222
/**
2323
* It queries the database for all the emails received in the last week, then it creates two lists:
2424
* one with the number of emails received per day, and one with the number of emails received per type (ham or spam)
25+
*
2526
* @param $max_mail_count int The maximum number of emails to retrieve
2627
* @param $date_after string The date after which the emails will be retrieved
2728
*
2829
* @return WP_Query The query object
2930
*/
30-
public function cf7a_get_flamingo_stats($max_mail_count, $date_after = '1 week ago') {
31+
public function cf7a_get_flamingo_stats( $max_mail_count, $date_after = '1 week ago' ) {
3132
$args = array(
32-
'post_type' => 'flamingo_inbound',
33-
'post_status' => array( 'flamingo-spam', 'publish' ),
34-
'posts_per_page' => $max_mail_count,
35-
'orderby' => 'date',
36-
'order' => 'DESC',
37-
'date_query' => array(
38-
array(
39-
'after' => $date_after,
40-
),
33+
'post_type' => 'flamingo_inbound',
34+
'post_status' => array( 'flamingo-spam', 'publish' ),
35+
'posts_per_page' => $max_mail_count,
36+
'orderby' => 'date',
37+
'order' => 'DESC',
38+
'date_query' => array(
39+
array(
40+
'after' => $date_after,
4141
),
42+
),
4243
);
4344

4445
return new WP_Query( $args );
4546
}
4647

4748
/**
4849
* Processes email query results and organizes them by type and date
50+
*
4951
* @param WP_Query $query The query object containing email posts
5052
* @return array Organized mail collection with by_type and by_date arrays
5153
*/
52-
private function cf7a_process_mail_collection($query) {
54+
private function cf7a_process_mail_collection( $query ) {
5355
$mail_collection = array(
54-
'by_type' => array(
55-
'ham' => 0,
56-
'spam' => 0,
57-
),
58-
'by_date' => array(),
56+
'by_type' => array(
57+
'ham' => 0,
58+
'spam' => 0,
59+
),
60+
'by_date' => array(),
5961
);
6062

6163
while ( $query->have_posts() ) {
6264
$query->the_post();
6365
global $post;
6466

6567
$is_ham = 'flamingo-spam' !== $post->post_status;
66-
$today = esc_html( get_the_date( 'Y-m-d' ) );
68+
$today = esc_html( get_the_date( 'Y-m-d' ) );
6769

68-
// Initialize date array if not exists
69-
if ( ! isset( $mail_collection['by_date'][ $today ] ) ) {
70-
$mail_collection['by_date'][ $today ] = array();
71-
}
70+
// Initialize the date array if not exists
71+
if ( ! isset( $mail_collection['by_date'][ $today ] ) ) {
72+
$mail_collection['by_date'][ $today ] = array();
73+
}
7274

7375
// Count by type
74-
$mail_collection['by_type'][ $is_ham ? 'ham' : 'spam' ]++;
76+
++$mail_collection['by_type'][ $is_ham ? 'ham' : 'spam' ];
7577

7678
// Store by date
7779
$mail_collection['by_date'][ $today ][] = array(
78-
'status' => $is_ham ? 'ham' : 'spam'
80+
'status' => $is_ham ? 'ham' : 'spam',
7981
);
8082
}
8183

@@ -85,84 +87,87 @@ private function cf7a_process_mail_collection($query) {
8587

8688
/**
8789
* Renders the email list HTML
90+
*
8891
* @param WP_Query $query The query object containing email posts
8992
*/
90-
private function cf7a_render_email_list($query) {
93+
private function cf7a_render_email_list( $query ) {
9194
echo '<div id="antispam-widget-list" class="activity-block">';
9295
echo '<h3>' . esc_html__( 'Last Week Emails', 'cf7-antispam' ) . '</h3>';
9396
echo '<ul>';
9497

9598
$query->rewind_posts();
96-
while ( $query->have_posts() ) {
97-
$query->the_post();
98-
global $post;
99-
100-
$is_ham = 'flamingo-spam' !== $post->post_status;
101-
102-
if ( wp_date( 'Y-m-d' ) > wp_date( 'Y-m-d', strtotime( '-1 week' ) ) ) {
103-
printf(
104-
'<li class="cf7-a_list-item"><span class="timestamp">%s </span><a href="%s" value="post-id-%s"><span>%s</span> %s</a> - %s</li>',
105-
get_the_date( 'Y-m-d' ),
106-
admin_url( 'admin.php?page=flamingo_inbound&post=' . $post->ID . '&action=edit' ),
107-
$post->ID,
108-
$is_ham ? '🔵' : '🔴',
109-
esc_html( get_post_meta( $post->ID, '_from' )[0] ),
110-
esc_html( $post->post_title )
111-
);
112-
}
99+
while ( $query->have_posts() ) {
100+
$query->the_post();
101+
global $post;
102+
103+
$is_ham = 'flamingo-spam' !== $post->post_status;
104+
105+
if ( wp_date( 'Y-m-d' ) > wp_date( 'Y-m-d', strtotime( '-1 week' ) ) ) {
106+
printf(
107+
'<li class="cf7-a_list-item"><span class="timestamp">%s </span><a href="%s" value="post-id-%s"><span>%s</span> %s</a> - %s</li>',
108+
get_the_date( 'Y-m-d' ),
109+
admin_url( 'admin.php?page=flamingo_inbound&post=' . $post->ID . '&action=edit' ),
110+
$post->ID,
111+
$is_ham ? '🔵' : '🔴',
112+
esc_html( get_post_meta( $post->ID, '_from' )[0] ),
113+
esc_html( $post->post_title )
114+
);
113115
}
116+
}
114117

115118
echo '</ul></div>';
116119
wp_reset_postdata();
117120
}
118121

119122
/**
120123
* Converts mail collection to chart data format
124+
*
121125
* @param array $mail_collection The organized mail collection
122126
* @return array Chart data with ham and spam counts by date
123127
*/
124-
private function cf7a_prepare_chart_data($mail_collection) {
128+
private function cf7a_prepare_chart_data( $mail_collection ) {
125129
$mail_collection['by_date'] = array_reverse( $mail_collection['by_date'] );
126-
$count = array();
130+
$count = array();
127131

128132
// Process data by date
129-
foreach ( $mail_collection['by_date'] as $date => $items ) {
130-
if ( ! isset( $count[ $date ] ) ) {
131-
$count[ $date ] = array(
132-
'ham' => 0,
133-
'spam' => 0,
134-
);
135-
}
133+
foreach ( $mail_collection['by_date'] as $date => $items ) {
134+
if ( ! isset( $count[ $date ] ) ) {
135+
$count[ $date ] = array(
136+
'ham' => 0,
137+
'spam' => 0,
138+
);
139+
}
136140

137-
// Count items by status for each date
138-
foreach ( $items as $item ) {
139-
$count[ $date ][ $item['status'] ]++;
140-
}
141+
// Count items by status for each date
142+
foreach ( $items as $item ) {
143+
++$count[ $date ][ $item['status'] ];
141144
}
145+
}
142146

143147
// Extract ham and spam arrays for chart
144-
$ham = array();
148+
$ham = array();
145149
$spam = array();
146150

147-
foreach ( $count as $date_count ) {
148-
$ham[] = $date_count['ham'];
149-
$spam[] = $date_count['spam'];
150-
}
151+
foreach ( $count as $date_count ) {
152+
$ham[] = $date_count['ham'];
153+
$spam[] = $date_count['spam'];
154+
}
151155

152156
return array(
153-
'dates' => array_keys( $mail_collection['by_date'] ),
154-
'ham' => $ham,
155-
'spam' => $spam,
156-
'by_type' => $mail_collection['by_type']
157+
'dates' => array_keys( $mail_collection['by_date'] ),
158+
'ham' => $ham,
159+
'spam' => $spam,
160+
'by_type' => $mail_collection['by_type'],
157161
);
158162
}
159163

160164
/**
161165
* Renders the JavaScript chart data
166+
*
162167
* @param array $chart_data Prepared chart data
163168
*/
164-
private function cf7a_render_chart_script($chart_data) {
165-
?>
169+
private function cf7a_render_chart_script( $chart_data ) {
170+
?>
166171
<script>
167172
var spamChartData = {
168173
lineData: {
@@ -201,7 +206,7 @@ private function cf7a_render_chart_script($chart_data) {
201206
* Renders the footer links
202207
*/
203208
private function cf7a_render_footer() {
204-
?>
209+
?>
205210
<p class="community-events-footer">
206211
<a href="<?php echo esc_url_raw( admin_url( 'admin.php?page=flamingo' ) ); ?>">
207212
<?php esc_html_e( 'Flamingo Inbound Messages', 'flamingo' ); ?>
@@ -221,8 +226,8 @@ private function cf7a_render_footer() {
221226
*/
222227
private function cf7a_render_empty_state() {
223228
printf(
224-
'<div class="cf7-a_widget-empty"><span class="dashicons dashicons-welcome-comments"></span><p>%s</p></div>',
225-
esc_html__( 'You have not received any e-mails in the last 7 days.', 'cf7-antispam' )
229+
'<div class="cf7-a_widget-empty"><span class="dashicons dashicons-welcome-comments"></span><p>%s</p></div>',
230+
esc_html__( 'You have not received any e-mails in the last 7 days.', 'cf7-antispam' )
226231
);
227232
}
228233

@@ -234,29 +239,29 @@ private function cf7a_render_empty_state() {
234239
*/
235240
public function cf7a_flamingo_widget() {
236241
$max_mail_count = apply_filters( 'cf7a_dashboard_max_mail_count', 25 );
237-
$query = $this->cf7a_get_flamingo_stats($max_mail_count);
242+
$query = $this->cf7a_get_flamingo_stats( $max_mail_count );
238243

239-
if ( ! $query->have_posts() ) {
240-
$this->cf7a_render_empty_state();
241-
return;
242-
}
244+
if ( ! $query->have_posts() ) {
245+
$this->cf7a_render_empty_state();
246+
return;
247+
}
243248

244249
// Process the mail collection
245-
$mail_collection = $this->cf7a_process_mail_collection($query);
250+
$mail_collection = $this->cf7a_process_mail_collection( $query );
246251

247252
// Prepare chart data
248-
$chart_data = $this->cf7a_prepare_chart_data($mail_collection);
253+
$chart_data = $this->cf7a_prepare_chart_data( $mail_collection );
249254

250255
// Render the widget
251-
?>
256+
?>
252257
<div id="antispam-widget">
253258
<canvas id="line-chart" width="400" height="200"></canvas>
254259
<hr>
255260
<canvas id="pie-chart" width="50" height="50"></canvas>
256261
<?php
257-
$this->cf7a_render_email_list($query);
262+
$this->cf7a_render_email_list( $query );
258263
$this->cf7a_render_footer();
259-
$this->cf7a_render_chart_script($chart_data);
264+
$this->cf7a_render_chart_script( $chart_data );
260265
?>
261266
</div>
262267
<?php
@@ -270,18 +275,18 @@ public function cf7a_flamingo_widget() {
270275
*/
271276
public function cf7a_dash_charts() {
272277
$max_mail_count = apply_filters( 'cf7a_admin_dashboard_max_mail_count', 50 );
273-
$query = $this->cf7a_get_flamingo_stats($max_mail_count, '1 year ago');
278+
$query = $this->cf7a_get_flamingo_stats( $max_mail_count, '1 year ago' );
274279

275280
if ( ! $query->have_posts() ) {
276281
$this->cf7a_render_empty_state();
277282
return;
278283
}
279284

280285
// Process the mail collection
281-
$mail_collection = $this->cf7a_process_mail_collection($query);
286+
$mail_collection = $this->cf7a_process_mail_collection( $query );
282287

283288
// Prepare chart data
284-
$chart_data = $this->cf7a_prepare_chart_data($mail_collection);
289+
$chart_data = $this->cf7a_prepare_chart_data( $mail_collection );
285290

286291
// Render the widget
287292
?>
@@ -295,7 +300,7 @@ public function cf7a_dash_charts() {
295300
</div>
296301
</div>
297302
<?php
298-
$this->cf7a_render_chart_script($chart_data);
303+
$this->cf7a_render_chart_script( $chart_data );
299304
?>
300305
</div>
301306
<?php

0 commit comments

Comments
 (0)