Skip to content

Commit 084e681

Browse files
chore: fix phpcs
1 parent a82d57b commit 084e681

File tree

4 files changed

+105
-85
lines changed

4 files changed

+105
-85
lines changed

includes/abstract/feedzy-rss-feeds-admin-abstract.php

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ public function feedzy_define_default_image( $default_img ) {
7272
/**
7373
* Fetches the SDK logger data.
7474
*
75-
* @param array $data The default data that needs to be sent.
75+
* @param array<string, mixed> $data The default data that needs to be sent.
76+
*
77+
* @return array<string, mixed> The usage data.
7678
*
7779
* @access public
7880
*/
7981
public function get_usage_data( $data ) {
80-
global $wpdb;
81-
8282
// how many categories created.
8383
$categories = 0;
8484
$terms = get_terms( array( 'taxonomy' => 'feedzy_categories' ) );
@@ -110,7 +110,6 @@ public function get_usage_data( $data ) {
110110
$imports = apply_filters(
111111
'feedzy_usage_data',
112112
array(
113-
// how many active imports are created.
114113
'publish' => count(
115114
get_posts(
116115
array(
@@ -121,7 +120,6 @@ public function get_usage_data( $data ) {
121120
)
122121
)
123122
),
124-
// how many draft imports are created
125123
'draft' => count(
126124
get_posts(
127125
array(
@@ -132,7 +130,6 @@ public function get_usage_data( $data ) {
132130
)
133131
)
134132
),
135-
// how many posts were imported by the imports
136133
'imported' => count(
137134
get_posts(
138135
array(
@@ -145,7 +142,6 @@ public function get_usage_data( $data ) {
145142
)
146143
)
147144
),
148-
// integrations
149145
'integrations' => $integrations,
150146
)
151147
);
@@ -160,7 +156,7 @@ public function get_usage_data( $data ) {
160156
}
161157
}
162158

163-
// how many posts contain the shortcode
159+
// how many posts contain the shortcode.
164160
global $wpdb;
165161
$shortcodes = $wpdb->get_var( "SELECT count(*) FROM {$wpdb->prefix}posts WHERE post_status IN ('publish', 'private') AND post_content LIKE '%[feedzy-rss %'" ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
166162
$data = array(
@@ -294,7 +290,13 @@ public function feedzy_classes_item( $item_attr = '', $sizes = '', $item = '', $
294290
*
295291
* @return string
296292
*/
297-
public function feedzy_summary_input_filter( $description, $content, $feed_url ) {
293+
public function feedzy_summary_input_filter(
294+
$description,
295+
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
296+
$content,
297+
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
298+
$feed_url
299+
) {
298300
$description = trim( wp_strip_all_tags( $description ) );
299301
$description = trim( str_replace( array( '[…]', '[…]', '[&hellip;]' ), '', $description ) );
300302

@@ -810,7 +812,8 @@ private function init_feed( $feed_url, $cache, $sc, $allow_https = FEEDZY_ALLOW_
810812
add_filter(
811813
'wp_feed_cache_transient_lifetime',
812814
function ( $time ) use ( $cache_time ) {
813-
return $cache_time;
815+
$time = $cache_time;
816+
return $time;
814817
},
815818
10,
816819
1
@@ -849,6 +852,7 @@ function ( $time ) use ( $cache_time ) {
849852
}
850853

851854
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
855+
// phpcs:ignore WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___SERVER__HTTP_USER_AGENT__
852856
$set_server_agent = sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) . SIMPLEPIE_USERAGENT );
853857
$feed->set_useragent( apply_filters( 'http_headers_useragent', $set_server_agent ) );
854858
}
@@ -868,7 +872,7 @@ function ( $time ) use ( $cache_time ) {
868872
if ( ! empty( $error ) ) {
869873
do_action( 'themeisle_log_event', FEEDZY_NAME, sprintf( 'Error while parsing feed: %s', $error ), 'error', __FILE__, __LINE__ );
870874

871-
// curl: (60) SSL certificate problem: unable to get local issuer certificate
875+
// curl: (60) SSL certificate problem: unable to get local issuer certificate.
872876
if ( strpos( $error, 'SSL certificate' ) !== false ) {
873877
do_action( 'themeisle_log_event', FEEDZY_NAME, sprintf( 'Got an SSL Error (%s), retrying by ignoring SSL', $error ), 'debug', __FILE__, __LINE__ );
874878
$feed = $this->init_feed( $feed_url, $cache, $sc, false );
@@ -920,11 +924,11 @@ private function get_default_user_agent( $urls ) {
920924
*
921925
* @param array|string $feed_url The feeds URL/s.
922926
* @param string $cache The cache string (eg. 1_hour, 30_min etc.).
923-
* @param bool $echo Echo the results.
927+
* @param bool $echo_result Echo the results.
924928
*
925929
* @return array
926930
*/
927-
protected function get_valid_source_urls( $feed_url, $cache, $echo = true ) {
931+
protected function get_valid_source_urls( $feed_url, $cache, $echo_result = true ) {
928932
$valid_feed_url = array();
929933
if ( is_array( $feed_url ) ) {
930934
foreach ( $feed_url as $url ) {
@@ -937,7 +941,7 @@ protected function get_valid_source_urls( $feed_url, $cache, $echo = true ) {
937941
}
938942
if ( $this->check_valid_source( $url, $cache, $source_type ) ) {
939943
$valid_feed_url[] = $url;
940-
} elseif ( $echo ) {
944+
} elseif ( $echo_result ) {
941945
echo wp_kses_post(
942946
sprintf(
943947
// translators: %s: Feed URL.
@@ -957,7 +961,7 @@ protected function get_valid_source_urls( $feed_url, $cache, $echo = true ) {
957961
}
958962
if ( $this->check_valid_source( $feed_url, $cache, $source_type ) ) {
959963
$valid_feed_url[] = $feed_url;
960-
} elseif ( $echo ) {
964+
} elseif ( $echo_result ) {
961965
echo wp_kses_post(
962966
sprintf(
963967
// translators: %s: Feed URL.
@@ -1090,7 +1094,7 @@ private function render_content( $sc, $feed, $feed_url, $content = '' ) {
10901094
$sizes = apply_filters( 'feedzy_thumb_sizes', $sizes, $feed_url );
10911095
$feed_title = $this->get_feed_title_filter( $feed, $sc, $feed_url );
10921096
$feed_title['use_title'] = false;
1093-
if ( $sc['feed_title'] === 'yes' ) {
1097+
if ( 'yes' === $sc['feed_title'] ) {
10941098
$feed_title['use_title'] = true;
10951099
}
10961100
// Display the error message and quit (before showing the template for pro).
@@ -1156,7 +1160,7 @@ private function render_content( $sc, $feed, $feed_url, $content = '' ) {
11561160
$content .= '</ul> </div>';
11571161
if ( ! $is_dry_run ) {
11581162
$content = apply_filters( 'feedzy_global_output', $content, $sc, $feed_title, $feed_items );
1159-
$content .= '<style type="text/css" media="all">' . esc_attr( feedzy_default_css( $main_class ) ) . '</style>';
1163+
$content .= '<style type="text/css" media="all">' . feedzy_default_css( $main_class ) . '</style>';
11601164
}
11611165
return $content;
11621166
}
@@ -1383,13 +1387,13 @@ private function get_feed_item_filter( $sc, $sizes, $item, $feed_url, $index, $i
13831387
) {
13841388
if ( ! empty( $the_thumbnail ) ) {
13851389
$the_thumbnail = $this->feedzy_image_encode( $the_thumbnail );
1386-
$content_thumb .= '<span class="fetched" style="background-image: url(\'' . $the_thumbnail . '\');" title="' . esc_html( $item->get_title() ) . '"></span>';
1390+
$content_thumb .= '<span class="fetched" style="background-image: url(\'' . $the_thumbnail . '\');" title="' . esc_attr( $item->get_title() ) . '"></span>';
13871391
if ( ! isset( $sc['amp'] ) || 'no' !== $sc['amp'] ) {
13881392
$content_thumb .= '<amp-img width="' . $sizes['width'] . '" height="' . $sizes['height'] . '" src="' . $the_thumbnail . '">';
13891393
}
13901394
}
13911395
if ( empty( $the_thumbnail ) && 'yes' === $sc['thumb'] ) {
1392-
$content_thumb .= '<span class="default" style="background-image:url(' . $sc['default'] . ');" title="' . esc_html( $item->get_title() ) . '"></span>';
1396+
$content_thumb .= '<span class="default" style="background-image:url(' . $sc['default'] . ');" title="' . esc_attr( $item->get_title() ) . '"></span>';
13931397
if ( ! isset( $sc['amp'] ) || 'no' !== $sc['amp'] ) {
13941398
$content_thumb .= '<amp-img width="' . $sizes['width'] . '" height="' . $sizes['height'] . '" src="' . $sc['default'] . '">';
13951399
}
@@ -1698,12 +1702,12 @@ public function feedzy_retrieve_image( $item, $sc = null ) {
16981702
* @since 3.0.0
16991703
* @access public
17001704
*
1701-
* @param string $string A string with an <img/> tag.
1705+
* @param string $img_html A string with an <img/> tag.
17021706
*
17031707
* @return string
17041708
*/
1705-
public function feedzy_return_image( $string ) {
1706-
$img = html_entity_decode( $string, ENT_QUOTES, 'UTF-8' );
1709+
public function feedzy_return_image( $img_html ) {
1710+
$img = html_entity_decode( $img_html, ENT_QUOTES, 'UTF-8' );
17071711
$pattern = '/<img[^>]+\>/i';
17081712
preg_match_all( $pattern, $img, $matches );
17091713

@@ -1713,8 +1717,8 @@ public function feedzy_return_image( $string ) {
17131717
$link = $this->feedzy_scrape_image( $match );
17141718
$blacklist = $this->feedzy_blacklist_images();
17151719
$is_blacklist = false;
1716-
foreach ( $blacklist as $string ) {
1717-
if ( strpos( (string) $link, $string ) !== false ) {
1720+
foreach ( $blacklist as $img_html ) {
1721+
if ( strpos( (string) $link, $img_html ) !== false ) {
17181722
$is_blacklist = true;
17191723
break;
17201724
}
@@ -1735,15 +1739,15 @@ public function feedzy_return_image( $string ) {
17351739
* @since 3.0.0
17361740
* @access public
17371741
*
1738-
* @param string $string A string with an <img/> tag.
1742+
* @param string $img_html A string with an <img/> tag.
17391743
* @param string $link The link to search for.
17401744
*
17411745
* @return string
17421746
*/
1743-
public function feedzy_scrape_image( $string, $link = '' ) {
1747+
public function feedzy_scrape_image( $img_html, $link = '' ) {
17441748
$pattern = '/< *img[^>]*src *= *["\']?([^"\']*)/';
17451749
$match = $link;
1746-
preg_match( $pattern, $string, $link );
1750+
preg_match( $pattern, $img_html, $link );
17471751
if ( ! empty( $link ) && isset( $link[1] ) ) {
17481752
$match = $link[1];
17491753
}
@@ -1799,22 +1803,22 @@ public function feedzy_blacklist_images() {
17991803
* @since 3.0.0
18001804
* @access public
18011805
*
1802-
* @param string $string A string containing the image URL.
1806+
* @param string $img_url A string containing the image URL.
18031807
*
18041808
* @return string
18051809
*/
1806-
public function feedzy_image_encode( $string ) {
1810+
public function feedzy_image_encode( $img_url ) {
18071811
// Check if img url is set as an URL parameter.
1808-
$url_tab = wp_parse_url( $string );
1812+
$url_tab = wp_parse_url( $img_url );
18091813
if ( isset( $url_tab['query'] ) ) {
18101814
preg_match_all( '/(http|https):\/\/[^ ]+(\.gif|\.GIF|\.jpg|\.JPG|\.jpeg|\.JPEG|\.png|\.PNG)/', $url_tab['query'], $img_url );
18111815
if ( isset( $img_url[0][0] ) ) {
1812-
$string = $img_url[0][0];
1816+
$img_url = $img_url[0][0];
18131817
}
18141818
}
18151819

1816-
$return = apply_filters( 'feedzy_image_encode', esc_url( $string ), $string );
1817-
do_action( 'themeisle_log_event', FEEDZY_NAME, sprintf( 'Changing image URL from %s to %s', $string, $return ), 'debug', __FILE__, __LINE__ );
1820+
$return = apply_filters( 'feedzy_image_encode', esc_url( $img_url ), $img_url );
1821+
do_action( 'themeisle_log_event', FEEDZY_NAME, sprintf( 'Changing image URL from %s to %s', $img_url, $return ), 'debug', __FILE__, __LINE__ );
18181822
return $return;
18191823
}
18201824

@@ -1862,16 +1866,16 @@ public function load_layout( $layout_name ) {
18621866
* @access public
18631867
*
18641868
* @param string $key The key before to insert.
1865-
* @param array $array The array in which to insert the new key.
1869+
* @param array $from_array The array in which to insert the new key.
18661870
* @param string $new_key The new key name.
18671871
* @param mixed $new_value The new key value.
18681872
*
18691873
* @return array|bool
18701874
*/
1871-
protected function array_insert_before( $key, &$array, $new_key, $new_value ) {
1872-
if ( array_key_exists( $key, $array ) ) {
1875+
protected function array_insert_before( $key, &$from_array, $new_key, $new_value ) {
1876+
if ( array_key_exists( $key, $from_array ) ) {
18731877
$new = array();
1874-
foreach ( $array as $k => $value ) {
1878+
foreach ( $from_array as $k => $value ) {
18751879
if ( $k === $key ) {
18761880
$new[ $new_key ] = $new_value;
18771881
}

0 commit comments

Comments
 (0)