Skip to content

Commit

Permalink
chore: enforce array shorthand syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
HardeepAsrani committed Oct 7, 2024
1 parent c06c2d3 commit 36c3685
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 315 deletions.
354 changes: 177 additions & 177 deletions inc/API.php

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions inc/BaseAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ class BaseAPI {
*
* @var array
*/
private $errors = array();
private $errors = [];

/**
* Constructor.
*/
public function __construct() {
$this->table = DB_Table::instance();

$this->errors = array(
$this->errors = [
'invalid_api_key' => __( 'Incorrect API key provided.', 'hyve-lite' ),
'missing_scope' => __( ' You have insufficient permissions for this operation.', 'hyve-lite' ),
);
];
}

/**
Expand Down Expand Up @@ -97,13 +97,13 @@ public function moderate( $chunks, $id = null ) {
}

$openai = OpenAI::instance();
$results = array();
$results = [];
$return = true;
$settings = Main::get_settings();
$moderation_threshold = $settings['moderation_threshold'];

if ( ! is_array( $chunks ) ) {
$chunks = array( $chunks );
$chunks = [ $chunks ];
}

foreach ( $chunks as $chunk ) {
Expand All @@ -119,7 +119,7 @@ public function moderate( $chunks, $id = null ) {
}

if ( ! empty( $results ) ) {
$flagged = array();
$flagged = [];

foreach ( $results as $result ) {
$categories = $result->categories;
Expand Down
4 changes: 2 additions & 2 deletions inc/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class Block {
* Constructor.
*/
public function __construct() {
add_action( 'init', array( $this, 'register_block' ) );
add_shortcode( 'hyve', array( $this, 'render_shortcode' ) );
add_action( 'init', [ $this, 'register_block' ] );
add_shortcode( 'hyve', [ $this, 'render_shortcode' ] );
}

/**
Expand Down
38 changes: 19 additions & 19 deletions inc/DB_Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public function __construct() {
global $wpdb;
$this->table_name = $wpdb->prefix . 'hyve';

add_action( 'hyve_process_post', array( $this, 'process_post' ), 10, 1 );
add_action( 'hyve_delete_posts', array( $this, 'delete_posts' ), 10, 1 );
add_action( 'hyve_process_post', [ $this, 'process_post' ], 10, 1 );
add_action( 'hyve_delete_posts', [ $this, 'delete_posts' ], 10, 1 );

if ( ! $this->table_exists() || version_compare( $this->version, get_option( $this->table_name . '_db_version' ), '>' ) ) {
$this->create_table();
Expand Down Expand Up @@ -125,7 +125,7 @@ public function table_exists() {
* @return array
*/
public function get_columns() {
return array(
return [
'date' => '%s',
'modified' => '%s',
'post_id' => '%s',
Expand All @@ -135,7 +135,7 @@ public function get_columns() {
'token_count' => '%d',
'post_status' => '%s',
'storage' => '%s',
);
];
}

/**
Expand All @@ -146,7 +146,7 @@ public function get_columns() {
* @return array
*/
public function get_column_defaults() {
return array(
return [
'date' => gmdate( 'Y-m-d H:i:s' ),
'modified' => gmdate( 'Y-m-d H:i:s' ),
'post_id' => '',
Expand All @@ -156,7 +156,7 @@ public function get_column_defaults() {
'token_count' => 0,
'post_status' => 'scheduled',
'storage' => 'WordPress',
);
];
}

/**
Expand Down Expand Up @@ -228,7 +228,7 @@ public function update( $id, $data ) {

$data = array_intersect_key( $data, $column_formats );

$wpdb->update( $this->table_name, $data, array( 'id' => $id ), $column_formats, array( '%d' ) );
$wpdb->update( $this->table_name, $data, [ 'id' => $id ], $column_formats, [ '%d' ] );

$this->delete_cache( 'entry_' . $id );
$this->delete_cache( 'entries_processed' );
Expand All @@ -248,7 +248,7 @@ public function update( $id, $data ) {
public function delete_by_post_id( $post_id ) {
global $wpdb;

$wpdb->delete( $this->table_name, array( 'post_id' => $post_id ), array( '%d' ) );
$wpdb->delete( $this->table_name, [ 'post_id' => $post_id ], [ '%d' ] );

$this->delete_cache( 'entry_post_' . $post_id );
$this->delete_cache( 'entries' );
Expand Down Expand Up @@ -314,7 +314,7 @@ public function get_by_storage( $storage, $limit = 100 ) {
*/
public function update_storage( $to, $from ) {
global $wpdb;
$wpdb->update( $this->table_name, array( 'storage' => $to ), array( 'storage' => $from ), array( '%s' ), array( '%s' ) );
$wpdb->update( $this->table_name, [ 'storage' => $to ], [ 'storage' => $from ], [ '%s' ], [ '%s' ] );
$this->delete_cache( 'entries' );
$this->delete_cache( 'entries_processed' );
return $wpdb->rows_affected;
Expand All @@ -334,7 +334,7 @@ public function get_posts_over_limit() {
$posts = $wpdb->get_results( $wpdb->prepare( 'SELECT post_id FROM %i ORDER BY id DESC LIMIT %d, %d', $this->table_name, $limit, $this->get_count() ) );

if ( ! $posts ) {
return array();
return [];
}

$posts = wp_list_pluck( $posts, 'post_id' );
Expand All @@ -359,7 +359,7 @@ public function process_post( $id ) {
$embeddings = $openai->create_embeddings( $content );

if ( is_wp_error( $embeddings ) || ! $embeddings ) {
wp_schedule_single_event( time() + 60, 'hyve_process_post', array( $id ) );
wp_schedule_single_event( time() + 60, 'hyve_process_post', [ $id ] );
return;
}

Expand All @@ -371,13 +371,13 @@ public function process_post( $id ) {
try {
$success = Qdrant_API::instance()->add_point(
$embeddings,
array(
[
'post_id' => $post->post_id,
'post_title' => $post->post_title,
'post_content' => $post->post_content,
'token_count' => $post->token_count,
'website_url' => get_site_url(),
)
]
);

$storage = 'Qdrant';
Expand All @@ -386,7 +386,7 @@ public function process_post( $id ) {
}

if ( is_wp_error( $success ) ) {
wp_schedule_single_event( time() + 60, 'hyve_process_post', array( $id ) );
wp_schedule_single_event( time() + 60, 'hyve_process_post', [ $id ] );
return;
}
}
Expand All @@ -395,11 +395,11 @@ public function process_post( $id ) {

$this->update(
$id,
array(
[
'embeddings' => $embeddings,
'post_status' => 'processed',
'storage' => $storage,
)
]
);
}

Expand All @@ -412,7 +412,7 @@ public function process_post( $id ) {
*
* @return void
*/
public function delete_posts( $posts = array() ) {
public function delete_posts( $posts = [] ) {
$twenty = array_slice( $posts, 0, 20 );

foreach ( $twenty as $id ) {
Expand All @@ -427,7 +427,7 @@ public function delete_posts( $posts = array() ) {
$has_more = count( $posts ) > 20;

if ( $has_more ) {
wp_schedule_single_event( time() + 10, 'hyve_delete_posts', array( array_slice( $posts, 20 ) ) );
wp_schedule_single_event( time() + 10, 'hyve_delete_posts', [ array_slice( $posts, 20 ) ] );
}
}

Expand Down Expand Up @@ -473,7 +473,7 @@ private function get_cache( $key ) {
return false;
}

$entries = array();
$entries = [];

for ( $i = 0; $i < $total; $i++ ) {
$chunk_key = $key . '_' . $i;
Expand Down
54 changes: 27 additions & 27 deletions inc/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public function __construct() {
new Block();
new Threads();

add_action( 'admin_menu', array( $this, 'register_menu_page' ) );
add_action( 'save_post', array( $this, 'update_meta' ) );
add_action( 'delete_post', array( $this, 'delete_post' ) );
add_action( 'admin_menu', [ $this, 'register_menu_page' ] );
add_action( 'save_post', [ $this, 'update_meta' ] );
add_action( 'delete_post', [ $this, 'delete_post' ] );

$settings = self::get_settings();

Expand All @@ -65,7 +65,7 @@ public function __construct() {
isset( $settings['api_key'] ) && isset( $settings['assistant_id'] ) &&
! empty( $settings['api_key'] ) && ! empty( $settings['assistant_id'] )
) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) );
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_assets' ] );
}
}

Expand All @@ -82,12 +82,12 @@ public function register_menu_page() {
__( 'Hyve', 'hyve-lite' ),
'manage_options',
'hyve',
array( $this, 'menu_page' ),
[ $this, 'menu_page' ],
'dashicons-format-chat',
99
);

add_action( "admin_print_scripts-$page_hook_suffix", array( $this, 'enqueue_options_assets' ) );
add_action( "admin_print_scripts-$page_hook_suffix", [ $this, 'enqueue_options_assets' ] );
}

/**
Expand Down Expand Up @@ -116,7 +116,7 @@ public function enqueue_options_assets() {
wp_enqueue_style(
'hyve-styles',
HYVE_LITE_URL . 'build/backend/style-index.css',
array( 'wp-components' ),
[ 'wp-components' ],
$asset_file['version']
);

Expand All @@ -130,14 +130,14 @@ public function enqueue_options_assets() {

wp_set_script_translations( 'hyve-lite-scripts', 'hyve-lite' );

$post_types = get_post_types( array( 'public' => true ), 'objects' );
$post_types_for_js = array();
$post_types = get_post_types( [ 'public' => true ], 'objects' );
$post_types_for_js = [];

foreach ( $post_types as $post_type ) {
$post_types_for_js[] = array(
$post_types_for_js[] = [
'label' => $post_type->labels->name,
'value' => $post_type->name,
);
];
}

$settings = self::get_settings();
Expand All @@ -147,24 +147,24 @@ public function enqueue_options_assets() {
'hyve',
apply_filters(
'hyve_options_data',
array(
[
'api' => $this->api->get_endpoint(),
'postTypes' => $post_types_for_js,
'hasAPIKey' => isset( $settings['api_key'] ) && ! empty( $settings['api_key'] ),
'chunksLimit' => apply_filters( 'hyve_chunks_limit', 500 ),
'isQdrantActive' => Qdrant_API::is_active(),
'assets' => array(
'assets' => [
'images' => HYVE_LITE_URL . 'assets/images/',
),
'stats' => array(
],
'stats' => [
'threads' => Threads::get_thread_count(),
'messages' => Threads::get_messages_count(),
'totalChunks' => $this->table->get_count(),
),
],
'docs' => 'https://docs.themeisle.com/article/2009-hyve-documentation',
'qdrant_docs' => 'https://docs.themeisle.com/article/2066-integrate-hyve-with-qdrant',
'pro' => 'https://themeisle.com/plugins/hyve/',
)
]
)
);
}
Expand All @@ -179,7 +179,7 @@ public function enqueue_options_assets() {
public static function get_default_settings() {
return apply_filters(
'hyve_default_settings',
array(
[
'api_key' => '',
'qdrant_api_key' => '',
'qdrant_endpoint' => '',
Expand All @@ -189,7 +189,7 @@ public static function get_default_settings() {
'chat_model' => 'gpt-4o-mini',
'temperature' => 1,
'top_p' => 1,
'moderation_threshold' => array(
'moderation_threshold' => [
'sexual' => 80,
'hate' => 70,
'harassment' => 70,
Expand All @@ -201,8 +201,8 @@ public static function get_default_settings() {
'self-harm/instructions' => 50,
'harassment/threatening' => 60,
'violence' => 70,
),
)
],
]
);
}

Expand All @@ -214,7 +214,7 @@ public static function get_default_settings() {
* @return array
*/
public static function get_settings() {
$settings = get_option( 'hyve_settings', array() );
$settings = get_option( 'hyve_settings', [] );
return wp_parse_args( $settings, self::get_default_settings() );
}

Expand All @@ -231,7 +231,7 @@ public function enqueue_assets() {
wp_register_style(
'hyve-styles',
HYVE_LITE_URL . 'build/frontend/style-index.css',
array(),
[],
$asset_file['version']
);

Expand All @@ -252,15 +252,15 @@ public function enqueue_assets() {
'hyve',
apply_filters(
'hyve_frontend_data',
array(
[
'api' => $this->api->get_endpoint(),
'audio' => array(
'audio' => [
'click' => HYVE_LITE_URL . 'assets/audio/click.mp3',
'ping' => HYVE_LITE_URL . 'assets/audio/ping.mp3',
),
],
'welcome' => $settings['welcome_message'] ?? '',
'isEnabled' => $settings['chat_enabled'],
)
]
)
);

Expand Down
Loading

0 comments on commit 36c3685

Please sign in to comment.