Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes according to Coding Standards #36

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions inc/classes/class-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Assets {
protected function __construct() {

$this->setup_hooks();

}

/**
Expand All @@ -33,7 +32,6 @@ protected function __construct() {
protected function setup_hooks() {

add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );

}

/**
Expand Down
3 changes: 0 additions & 3 deletions inc/classes/class-notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Notice {
protected function __construct() {

$this->setup_hooks();

}

/**
Expand All @@ -36,7 +35,6 @@ protected function setup_hooks() {
* Actions.
*/
add_action( 'admin_notices', array( $this, 'display_notice' ) );

}

/**
Expand Down Expand Up @@ -73,6 +71,5 @@ public function display_notice() {
</p>
</div>
<?php

}
}
2 changes: 0 additions & 2 deletions inc/classes/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ protected function __construct() {
Settings::get_instance();
Search::get_instance();
Notice::get_instance();

}

}
39 changes: 16 additions & 23 deletions inc/classes/class-search-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Search_Engine {
protected function __construct() {

$this->init();

}

/**
Expand All @@ -48,7 +47,6 @@ protected function init() {

$this->api_key = get_option( 'gcs_api_key' );
$this->cse_id = get_option( 'gcs_cse_id' );

}

/**
Expand Down Expand Up @@ -105,38 +103,35 @@ public function get_search_results( $search_query, $page = 1, $posts_per_page =
return new \WP_Error( $response_code, $response_message );
} elseif ( 200 !== $response_code ) {
return new \WP_Error( $response_code, __( 'Unknown error occurred', 'search-with-google' ) );
} else {

if ( ! is_wp_error( $response ) ) {
} elseif ( ! is_wp_error( $response ) ) {

$response_body = wp_remote_retrieve_body( $response );
$result = json_decode( $response_body );

if ( ! is_wp_error( $result ) ) {
if ( ! is_wp_error( $result ) ) {

if ( isset( $result->searchInformation->totalResults ) && isset( $result->items ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
if ( isset( $result->searchInformation->totalResults ) && isset( $result->items ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase

$total_results = (int) $result->searchInformation->totalResults; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$total_results = (int) $result->searchInformation->totalResults; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase

// If no results found and pagination request then try another request.
if ( 0 === $total_results && $page > 1 ) {
return $this->get_search_results( $search_query, $page - 1, $posts_per_page );
}
// If no results found and pagination request then try another request.
if ( 0 === $total_results && $page > 1 ) {
return $this->get_search_results( $search_query, $page - 1, $posts_per_page );
}

if ( ! empty( $result->items ) ) {
foreach ( $result->items as $item ) {
if ( ! empty( $result->items ) ) {
foreach ( $result->items as $item ) {

$item_detail['title'] = $item->title;
$item_detail['link'] = $item->link;
$item_detail['snippet'] = $item->snippet;
$item_detail['title'] = $item->title;
$item_detail['link'] = $item->link;
$item_detail['snippet'] = $item->snippet;

$item_details[] = $item_detail;
}
$item_details[] = $item_detail;
}
}
} else {
return new \WP_Error( $response_code, __( 'Unknown error occurred', 'search-with-google' ) );
}
} else {
return new \WP_Error( $response_code, __( 'Unknown error occurred', 'search-with-google' ) );
}
}

Expand All @@ -157,7 +152,6 @@ public function get_search_results( $search_query, $page = 1, $posts_per_page =
public function get_start_index( $page, $posts_per_page ) {

return ( $page * $posts_per_page ) - ( $posts_per_page - 1 );

}

/**
Expand All @@ -175,6 +169,5 @@ private function get_api_url() {
}

return $api_url;

}
}
8 changes: 0 additions & 8 deletions inc/classes/class-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Search {
protected function __construct() {

$this->setup_hooks();

}

/**
Expand All @@ -37,7 +36,6 @@ protected function setup_hooks() {
*/
add_filter( 'posts_pre_query', array( $this, 'filter_search_query' ), 10, 2 );
add_filter( 'page_link', array( $this, 'update_permalink' ), 10, 2 );

}

/**
Expand Down Expand Up @@ -85,7 +83,6 @@ public function filter_search_query( $posts, $query ) {
$query->max_num_pages = intval( floor( $query->found_posts / $posts_per_page ) );

return $posts;

}

/**
Expand All @@ -100,7 +97,6 @@ public function filter_search_query( $posts, $query ) {
public function get_transient_key( $search_query, $page, $posts_per_page ) {

return 'gcs_results_' . sanitize_title( $search_query ) . '_' . $page . '_' . $posts_per_page;

}

/**
Expand All @@ -121,7 +117,6 @@ public function get_posts( $items ) {
}

return $posts;

}

/**
Expand Down Expand Up @@ -151,7 +146,6 @@ public function get_post( $item ) {

// Convert to WP_Post object.
return new \WP_Post( $post );

}

/**
Expand All @@ -166,7 +160,6 @@ public function get_post_name( $url ) {
$url_parse = wp_parse_url( $url );

return ltrim( $url_parse['path'], '/' );

}

/**
Expand All @@ -186,6 +179,5 @@ public function update_permalink( $permalink, $post_id ) {
}

return $permalink;

}
}
4 changes: 0 additions & 4 deletions inc/classes/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Settings {
protected function __construct() {

$this->setup_hooks();

}
/**
* Action / Filters to be declare here.
Expand All @@ -32,7 +31,6 @@ protected function __construct() {
protected function setup_hooks() {

add_action( 'admin_init', array( $this, 'register_settings' ) );

}

/**
Expand Down Expand Up @@ -84,7 +82,6 @@ public function register_settings() {
'reading',
'cse_settings_section'
);

}

/**
Expand Down Expand Up @@ -146,7 +143,6 @@ public function cse_search_type_field_cb() {
<span><?php esc_html_e( 'Custom Search API', 'search-with-google' ); ?></span>
</div>
<?php

}
}

7 changes: 3 additions & 4 deletions inc/helpers/autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
/**
* Auto loader function.
*
* @param string $resource Source namespace.
* @param string $resource_path Source namespace.
*
* @return void
*/
function autoloader( $resource = '' ) {
function autoloader( $resource_path = '' ) {

$resource_path = false;
$namespace_root = 'RT\Search_With_Google\\';
$resource = trim( $resource, '\\' );
$resource = trim( $resource_path, '\\' );

if ( empty( $resource ) || strpos( $resource, '\\' ) === false || strpos( $resource, $namespace_root ) !== 0 ) {
// Not our namespace, bail out.
Expand Down Expand Up @@ -80,7 +80,6 @@ function autoloader( $resource = '' ) {
// We are already making sure that the file exists and it's valid.
require_once( $resource_path ); // phpcs:ignore
}

}

spl_autoload_register( '\RT\Search_With_Google\Inc\Helpers\autoloader' );
2 changes: 0 additions & 2 deletions inc/traits/trait-singleton.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,5 @@ final public static function get_instance() {
}

return $instance[ $called_class ];

}

} // End trait
Loading