Skip to content

Commit

Permalink
Merge pull request #861 from brainstormforce/dev-phpstan
Browse files Browse the repository at this point in the history
Build Version 1.6.38
  • Loading branch information
sushmak02 authored Aug 22, 2024
2 parents 21778be + f99a16e commit 6b5561c
Show file tree
Hide file tree
Showing 48 changed files with 46,408 additions and 3,127 deletions.
3 changes: 3 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Gruntfile.js
package.json
phpunit.xml
phpunit.xml.dist
phpstan-baseline.neon
phpstan.neon
stubs-generator.php
multisite.xml
multisite.xml.dist
phpcs.xml
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
**Requires at least:** 4.4
**Requires PHP:** 5.4
**Tested up to:** 6.6
**Stable tag:** 1.6.37
**Stable tag:** 1.6.38
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -140,6 +140,9 @@ This same applies when you are creating your Header/Footer using this plugin.

## Changelog ##

### 1.6.38 ###
- Improvement: Improved code quality syntax and security checks for better coding standards and practices.

### 1.6.37 ###
- Improvement: Compatibility with latest Elementor and Elementor Pro 3.23 version.

Expand Down
6 changes: 3 additions & 3 deletions admin/bsf-analytics/class-bsf-analytics-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BSF_Analytics_Loader {
* @access private
* @var array Entities array.
*/
private $entities = [];
private $entities = array();

/**
* Analytics Version.
Expand Down Expand Up @@ -65,7 +65,7 @@ public static function get_instance() {
* Constructor
*/
public function __construct() {
add_action( 'init', [ $this, 'load_analytics' ] );
add_action( 'init', array( $this, 'load_analytics' ) );
}

/**
Expand All @@ -84,7 +84,7 @@ public function set_entity( $data ) {
* @return void
*/
public function load_analytics() {
$unique_entities = [];
$unique_entities = array();

if ( ! empty( $this->entities ) ) {
foreach ( $this->entities as $entity ) {
Expand Down
16 changes: 8 additions & 8 deletions admin/bsf-analytics/class-bsf-analytics-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function get_stats() {
* @since 1.0.0
*/
private function get_default_stats() {
return [
return array(
'graupi_version' => defined( 'BSF_UPDATER_VERSION' ) ? BSF_UPDATER_VERSION : false,
'domain_name' => get_site_url(),
'php_os' => PHP_OS,
Expand Down Expand Up @@ -99,13 +99,13 @@ private function get_default_stats() {

'active_theme' => get_template(),
'active_stylesheet' => get_stylesheet(),
];
);
}

/**
* Get installed PHP version.
*
* @return float PHP version.
* @return string PHP version.
* @since 1.0.0
*/
private function get_php_version() {
Expand Down Expand Up @@ -148,7 +148,7 @@ private function get_active_plugins() {

$plugins = wp_get_active_and_valid_plugins();
$plugins = array_map( 'get_plugin_data', $plugins );
$this->plugins = array_map( [ $this, 'format_plugin' ], $plugins );
$this->plugins = array_map( array( $this, 'format_plugin' ), $plugins );
}

return $this->plugins;
Expand All @@ -162,14 +162,14 @@ private function get_active_plugins() {
* @since 1.0.0
*/
public function format_plugin( $plugin ) {
return [
return array(
'name' => html_entity_decode( $plugin['Name'], ENT_COMPAT, 'UTF-8' ),
'url' => $plugin['PluginURI'],
'version' => $plugin['Version'],
'slug' => $plugin['TextDomain'],
'author_name' => html_entity_decode( wp_strip_all_tags( $plugin['Author'] ), ENT_COMPAT, 'UTF-8' ),
'author_url' => $plugin['AuthorURI'],
];
);
}

/**
Expand All @@ -179,7 +179,7 @@ public function format_plugin( $plugin ) {
* @since 1.0.0
*/
private function get_curl_ssl_version() {
$curl = [];
$curl = array();
if ( function_exists( 'curl_version' ) ) {
$curl = curl_version(); // phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_version
}
Expand Down Expand Up @@ -232,7 +232,7 @@ private function is_content_writable() {
/**
* Get timezone string.
*
* @return string timezone string.
* @return string | mixed timezone string.
* @since 1.0.0
*/
function wp_timezone_string() {
Expand Down
63 changes: 39 additions & 24 deletions admin/bsf-analytics/class-bsf-analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class BSF_Analytics {
* @param string $analytics_path directory path to analytics library.
* @param float $analytics_version analytics library version.
* @since 1.0.0
* @return void
*/
public function __construct( $args, $analytics_path, $analytics_version ) {

Expand All @@ -52,13 +53,13 @@ public function __construct( $args, $analytics_path, $analytics_version ) {
define( 'BSF_ANALYTICS_VERSION', $analytics_version );
define( 'BSF_ANALYTICS_URI', $this->get_analytics_url( $analytics_path ) );

add_action( 'admin_init', [ $this, 'handle_optin_optout' ] );
add_action( 'admin_notices', [ $this, 'option_notice' ] );
add_action( 'init', [ $this, 'maybe_track_analytics' ], 99 );
add_action( 'admin_init', array( $this, 'handle_optin_optout' ) );
add_action( 'admin_notices', array( $this, 'option_notice' ) );
add_action( 'init', array( $this, 'maybe_track_analytics' ), 99 );

$this->set_actions();

add_action( 'admin_init', [ $this, 'register_usage_tracking_setting' ] );
add_action( 'admin_init', array( $this, 'register_usage_tracking_setting' ) );

$this->includes();
}
Expand All @@ -67,21 +68,22 @@ public function __construct( $args, $analytics_path, $analytics_version ) {
* Setup actions for admin notice style and analytics cron event.
*
* @since 1.0.4
* @return void
*/
public function set_actions() {

foreach ( $this->entities as $key => $data ) {
add_action( 'astra_notice_before_markup_' . $key . '-optin-notice', [ $this, 'enqueue_assets' ] );
add_action( 'update_option_' . $key . '_analytics_optin', [ $this, 'update_analytics_option_callback' ], 10, 3 );
add_action( 'add_option_' . $key . '_analytics_optin', [ $this, 'add_analytics_option_callback' ], 10, 2 );
add_action( 'astra_notice_before_markup_' . $key . '-optin-notice', array( $this, 'enqueue_assets' ) );
add_action( 'update_option_' . $key . '_analytics_optin', array( $this, 'update_analytics_option_callback' ), 10, 3 );
add_action( 'add_option_' . $key . '_analytics_optin', array( $this, 'add_analytics_option_callback' ), 10, 2 );
}
}

/**
* BSF Analytics URL
*
* @param string $analytics_path directory path to analytics library.
* @return String URL of bsf-analytics directory.
* @return string URL of bsf-analytics directory.
* @since 1.0.0
*/
public function get_analytics_url( $analytics_path ) {
Expand Down Expand Up @@ -129,15 +131,16 @@ public function enqueue_assets() {
* Send analytics API call.
*
* @since 1.0.0
* @return void
*/
public function send() {
wp_remote_post(
$this->get_api_url() . 'wp-json/bsf-core/v1/analytics/',
[
array(
'body' => BSF_Analytics_Stats::instance()->get_stats(),
'timeout' => 5,
'blocking' => false,
]
)
);
}

Expand Down Expand Up @@ -171,7 +174,7 @@ public function is_tracking_enabled() {
*/
public function is_white_label_enabled( $source ) {

$options = apply_filters( $source . '_white_label_options', [] );
$options = apply_filters( $source . '_white_label_options', array() );
$is_enabled = false;

if ( is_array( $options ) ) {
Expand All @@ -190,6 +193,7 @@ public function is_white_label_enabled( $source ) {
* Display admin notice for usage tracking.
*
* @since 1.0.0
* @return void
*/
public function option_notice() {

Expand Down Expand Up @@ -222,7 +226,7 @@ public function option_notice() {
$language_dir = is_rtl() ? 'rtl' : 'ltr';

Astra_Notices::add_notice(
[
array(
'id' => $key . '-optin-notice',
'type' => '',
'message' => sprintf(
Expand All @@ -242,19 +246,19 @@ public function option_notice() {
/* translators: %s usage doc link */
sprintf( $notice_string . '<span dir="%2s"><a href="%3s" target="_blank" rel="noreferrer noopener">%4s</a><span>', esc_html( $data['product_name'] ), $language_dir, esc_url( $usage_doc_link ), __( ' Know More.', 'header-footer-elementor' ) ),
add_query_arg(
[
array(
$key . '_analytics_optin' => 'yes',
$key . '_analytics_nonce' => wp_create_nonce( $key . '_analytics_optin' ),
'bsf_analytics_source' => $key,
]
)
),
__( 'Yes! Allow it', 'header-footer-elementor' ),
add_query_arg(
[
array(
$key . '_analytics_optin' => 'no',
$key . '_analytics_nonce' => wp_create_nonce( $key . '_analytics_optin' ),
'bsf_analytics_source' => $key,
]
)
),
MONTH_IN_SECONDS,
__( 'No Thanks', 'header-footer-elementor' )
Expand All @@ -263,7 +267,7 @@ public function option_notice() {
'repeat-notice-after' => false,
'priority' => 18,
'display-with-other-notices' => true,
]
)
);
}
}
Expand All @@ -272,6 +276,7 @@ public function option_notice() {
* Process usage tracking opt out.
*
* @since 1.0.0
* @return void
*/
public function handle_optin_optout() {

Expand Down Expand Up @@ -299,11 +304,11 @@ public function handle_optin_optout() {

wp_safe_redirect(
remove_query_arg(
[
array(
$source . '_analytics_optin',
$source . '_analytics_nonce',
'bsf_analytics_source',
]
)
)
);
}
Expand All @@ -313,6 +318,7 @@ public function handle_optin_optout() {
*
* @param string $source source of analytics.
* @since 1.0.0
* @return void
*/
private function optin( $source ) {
update_site_option( $source . '_analytics_optin', 'yes' );
Expand All @@ -323,6 +329,7 @@ private function optin( $source ) {
*
* @param string $source source of analytics.
* @since 1.0.0
* @return void
*/
private function optout( $source ) {
update_site_option( $source . '_analytics_optin', 'no' );
Expand All @@ -332,6 +339,7 @@ private function optout( $source ) {
* Load analytics stat class.
*
* @since 1.0.0
* @return void
*/
private function includes() {
require_once __DIR__ . '/class-bsf-analytics-stats.php';
Expand All @@ -341,6 +349,7 @@ private function includes() {
* Register usage tracking option in General settings page.
*
* @since 1.0.0
* @return void
*/
public function register_usage_tracking_setting() {

Expand All @@ -356,23 +365,23 @@ public function register_usage_tracking_setting() {
register_setting(
'general', // Options group.
$key . '_analytics_optin', // Option name/database.
[ 'sanitize_callback' => [ $this, 'sanitize_option' ] ] // sanitize callback function.
array( 'sanitize_callback' => array( $this, 'sanitize_option' ) ) // sanitize callback function.
);

add_settings_field(
$key . '-analytics-optin', // Field ID.
__( 'Usage Tracking', 'header-footer-elementor' ), // Field title.
[ $this, 'render_settings_field_html' ], // Field callback function.
array( $this, 'render_settings_field_html' ), // Field callback function.
'general',
'default', // Settings page slug.
[
array(
'type' => 'checkbox',
'title' => $author,
'name' => $key . '_analytics_optin',
'label_for' => $key . '-analytics-optin',
'id' => $key . '-analytics-optin',
'usage_doc_link' => $usage_doc_link,
]
)
);
}
}
Expand All @@ -382,6 +391,7 @@ public function register_usage_tracking_setting() {
*
* @param bool $input Option value.
* @since 1.0.0
* @return string
*/
public function sanitize_option( $input ) {

Expand All @@ -397,6 +407,7 @@ public function sanitize_option( $input ) {
*
* @param array $args arguments to field.
* @since 1.0.0
* @return void
*/
public function render_settings_field_html( $args ) {
?>
Expand All @@ -423,7 +434,7 @@ public function render_settings_field_html( $args ) {
* Set analytics installed time in option.
*
* @param string $source source of analytics.
* @return string $time analytics installed time.
* @return string | mixed $time analytics installed time.
* @since 1.0.0
*/
private function get_analytics_install_time( $source ) {
Expand All @@ -445,6 +456,7 @@ private function get_analytics_install_time( $source ) {
* @param string $value value of option.
* @param string $option Option name.
* @since 1.0.0
* @return void
*/
public function update_analytics_option_callback( $old_value, $value, $option ) {
if ( is_multisite() ) {
Expand All @@ -458,6 +470,7 @@ public function update_analytics_option_callback( $old_value, $value, $option )
* @param string $option Option name.
* @param string $value value of option.
* @since 1.0.0
* @return void
*/
public function add_analytics_option_callback( $option, $value ) {
if ( is_multisite() ) {
Expand All @@ -469,6 +482,7 @@ public function add_analytics_option_callback( $option, $value ) {
* Send analaytics track event if tracking is enabled.
*
* @since 1.0.0
* @return void
*/
public function maybe_track_analytics() {

Expand All @@ -490,6 +504,7 @@ public function maybe_track_analytics() {
*
* @param string $option name of option.
* @param string $value value of option.
* @return void
* @since 1.0.0
*/
public function add_option_to_network( $option, $value ) {
Expand Down
Loading

0 comments on commit 6b5561c

Please sign in to comment.