Skip to content

PHPInsights for AIOSRS #165

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

Open
wants to merge 2 commits into
base: master
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
13 changes: 12 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ module.exports = function (grunt) {
},
},
},
copy: {
main: {
options: {
mode: true
},
src: [
'!phpinsights.php',
],
dest: '/'
}
},

compress: {
main: {
Expand Down Expand Up @@ -79,7 +90,7 @@ module.exports = function (grunt) {

grunt.registerTask("i18n", ["addtextdomain", "makepot"]);
grunt.registerTask("readme", ["wp_readme_to_markdown"]);
grunt.registerTask("zip", ["compress"]); // Add this line to register the zip task
grunt.registerTask("zip", ["compress", "copy"]); // Add this line to register the zip task

grunt.util.linefeed = "\n";
};
27 changes: 13 additions & 14 deletions admin/bsf-analytics/class-bsf-analytics-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@
*/

if ( ! defined( 'ABSPATH' ) ) {
exit();
exit;
}

/**
* Class BSF_Analytics_Loader.
*/
class BSF_Analytics_Loader {

/**
* Analytics Entities.
*
* @access private
* @var array Entities array.
*/
private $entities = array();
private $entities = [];

/**
* Analytics Version.
Expand All @@ -48,33 +47,33 @@ class BSF_Analytics_Loader {
*/
private static $instance = null;

/**
* Constructor
*/
public function __construct() {
add_action( 'init', [ $this, 'load_analytics' ] );
}

/**
* Get instace of class.
*
* @return object
*/
public static function get_instance() {
if ( null === self::$instance ) {
if ( self::$instance === null ) {
self::$instance = new self();
}

return self::$instance;
}

/**
* Constructor
*/
public function __construct() {
add_action( 'init', array( $this, 'load_analytics' ) );
}

/**
* Set entity for analytics.
*
* @param string $data Entity attributes data.
* @return void
*/
public function set_entity( $data ) {
public function set_entity( $data ): void {
array_push( $this->entities, $data );
}

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

if ( ! empty( $this->entities ) ) {
foreach ( $this->entities as $entity ) {
Expand Down
63 changes: 30 additions & 33 deletions admin/bsf-analytics/class-bsf-analytics-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* BSF analytics stat class.
*/
class BSF_Analytics_Stats {

/**
* Active plugins.
*
Expand All @@ -40,7 +39,7 @@ class BSF_Analytics_Stats {
* @since 1.0.0
*/
public static function instance() {
if ( null === self::$instance ) {
if ( self::$instance === null ) {
self::$instance = new self();
}

Expand All @@ -57,14 +56,32 @@ public function get_stats() {
return apply_filters( 'bsf_core_stats', $this->get_default_stats() );
}

/**
* Format plugin data.
*
* @param string $plugin plugin.
* @return array formatted plugin data.
* @since 1.0.0
*/
public function format_plugin( $plugin ) {
return [
'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'],
];
}

/**
* Retrieve stats for site.
*
* @return array stats data.
* @since 1.0.0
*/
private function get_default_stats() {
return array(
return [
'graupi_version' => defined( 'BSF_UPDATER_VERSION' ) ? BSF_UPDATER_VERSION : false,
'domain_name' => get_site_url(),
'php_os' => PHP_OS,
Expand Down Expand Up @@ -99,7 +116,7 @@ private function get_default_stats() {

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

/**
Expand Down Expand Up @@ -148,43 +165,25 @@ private function get_active_plugins() {

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

return $this->plugins;
}

/**
* Format plugin data.
*
* @param string $plugin plugin.
* @return array formatted plugin data.
* @since 1.0.0
*/
public function format_plugin( $plugin ) {
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'],
);
}

/**
* Curl SSL version.
*
* @return float SSL version.
* @since 1.0.0
*/
private function get_curl_ssl_version() {
$curl = array();
$curl = [];
if ( function_exists( 'curl_version' ) ) {
$curl = curl_version(); // phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_version
}

return isset( $curl['ssl_version'] ) ? $curl['ssl_version'] : false;
return $curl['ssl_version'] ?? false;
}

/**
Expand All @@ -198,7 +197,7 @@ private function get_curl_version() {
$curl = curl_version(); // phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_version
}

return isset( $curl['version'] ) ? $curl['version'] : false;
return $curl['version'] ?? false;
}

/**
Expand Down Expand Up @@ -244,13 +243,11 @@ function wp_timezone_string() {

$offset = (float) get_option( 'gmt_offset' );
$hours = (int) $offset;
$minutes = ( $offset - $hours );

$sign = ( $offset < 0 ) ? '-' : '+';
$abs_hour = abs( $hours );
$abs_mins = abs( $minutes * 60 );
$tz_offset = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins );
$minutes = $offset - $hours;

return $tz_offset;
$sign = $offset < 0 ? '-' : '+';
$abs_hour = abs( $hours );
$abs_mins = abs( $minutes * 60 );
return sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins );
}
}
Loading