Skip to content

Commit 763b033

Browse files
committed
Run inspections and clean-up.
1 parent d155705 commit 763b033

File tree

11 files changed

+48
-76
lines changed

11 files changed

+48
-76
lines changed

src/php/admin-menus/class-settings-menu.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Code_Snippets;
44

5-
use WP_Error;
65
use const Code_Snippets\Settings\CACHE_KEY;
76
use const Code_Snippets\Settings\OPTION_GROUP;
87
use const Code_Snippets\Settings\OPTION_NAME;

src/php/admin-menus/class-welcome-menu.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace Code_Snippets;
44

5-
use Code_Snippets\Cloud\Cloud_Search_List_Table;
6-
use function Code_Snippets\Settings\get_setting;
7-
85
/**
96
* This class handles the welcome menu.
107
*

src/php/class-contextual-help.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,18 @@ public function __construct( string $screen_name ) {
4444
public function load() {
4545
$this->screen = get_current_screen();
4646

47-
if ( method_exists( $this, "load_{$this->screen_name}_help" ) ) {
48-
call_user_func( array( $this, "load_{$this->screen_name}_help" ) );
47+
switch ( $this->screen_name ) {
48+
case 'manage':
49+
$this->load_manage_help();
50+
break;
51+
52+
case 'edit':
53+
$this->load_edit_help();
54+
break;
55+
56+
case 'import':
57+
$this->load_import_help();
58+
break;
4959
}
5060

5161
$this->load_help_sidebar();

src/php/class-data-item.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,13 @@ public function get_fields(): array {
9696
* @return array<string, mixed>
9797
*/
9898
public function get_modified_fields(): array {
99-
$modified_fields = [];
100-
101-
foreach ( $this->get_fields() as $field => $value ) {
102-
if ( $value && $value !== $this->default_values[ $field ] ) {
103-
$modified_fields[ $field ] = $value;
104-
}
105-
}
106-
107-
return $modified_fields;
99+
return array_filter(
100+
$this->get_fields(),
101+
function ( $value, $field ) {
102+
return $value && $value !== $this->default_values[ $field ];
103+
},
104+
ARRAY_FILTER_USE_BOTH
105+
);
108106
}
109107

110108
/**

src/php/class-list-table.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,11 +666,10 @@ public static function required_form_fields( string $context = 'main' ) {
666666
*
667667
* @param int $id Snippet ID.
668668
* @param string $action Action to perform.
669-
* @param string $scope Snippet scope; used for cache busting CSS and JS snippets.
670669
*
671670
* @return bool|string Result of performing action
672671
*/
673-
private function perform_action( int $id, string $action, string $scope = '' ) {
672+
private function perform_action( int $id, string $action ) {
674673
switch ( $action ) {
675674

676675
case 'activate':
@@ -880,7 +879,13 @@ public function no_items() {
880879
* @return void
881880
*/
882881
private function fetch_shared_network_snippets() {
882+
/**
883+
* Table data.
884+
*
885+
* @var $snippets array<string, Snippet[]>
886+
*/
883887
global $snippets;
888+
884889
$ids = get_site_option( 'shared_network_snippets' );
885890

886891
if ( ! is_multisite() || ! $ids ) {
@@ -891,7 +896,6 @@ private function fetch_shared_network_snippets() {
891896
$limit = count( $snippets['all'] );
892897

893898
for ( $i = 0; $i < $limit; $i++ ) {
894-
/** Snippet @var Snippet $snippet */
895899
$snippet = &$snippets['all'][ $i ];
896900

897901
if ( in_array( $snippet->id, $ids, true ) ) {
@@ -1014,10 +1018,12 @@ function ( Snippet $snippet ) use ( $type ) {
10141018
}
10151019

10161020
// Count the totals for each section.
1017-
$totals = array();
1018-
foreach ( $snippets as $type => $list ) {
1019-
$totals[ $type ] = count( $list );
1020-
}
1021+
$totals = array_map(
1022+
function ( $list ) {
1023+
return count( $list );
1024+
},
1025+
$snippets
1026+
);
10211027

10221028
// If the current status is empty, default to all.
10231029
if ( empty( $snippets[ $status ] ) ) {

src/php/class-upgrade.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,11 @@ private function get_sample_content(): array {
216216
),
217217
);
218218

219-
$snippets = array();
220-
221-
foreach ( $snippets_data as $sample_name => $snippet_data ) {
222-
$snippets[ $sample_name ] = new Snippet( $snippet_data );
223-
}
224-
225-
return $snippets;
219+
return array_map(
220+
function ( $snippet_data ) {
221+
return new Snippet( $snippet_data );
222+
},
223+
$snippets_data
224+
);
226225
}
227226
}

src/php/cloud/class-cloud-api.php

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Code_Snippets\Snippet;
66
use WP_Error;
7-
use function Code_Snippets\code_snippets;
87
use function Code_Snippets\get_snippet_by_cloud_id;
98
use function Code_Snippets\get_snippets;
109
use function Code_Snippets\save_snippet;
@@ -70,43 +69,6 @@ public static function get_cloud_api_url(): string {
7069
: self::get_cloud_url() . 'api/v1/';
7170
}
7271

73-
/**
74-
* Retrieve cloud settings.
75-
*
76-
* @return array
77-
*/
78-
private static function get_cloud_settings(): array {
79-
static $settings = null;
80-
81-
if ( ! is_null( $settings ) ) {
82-
return $settings;
83-
}
84-
85-
$settings = wp_cache_get( self::CLOUD_SETTINGS_CACHE_KEY );
86-
if ( $settings ) {
87-
return $settings;
88-
}
89-
90-
$settings = get_option( self::CLOUD_SETTINGS_CACHE_KEY );
91-
92-
// Check if the settings exist in the database if not create defaults.
93-
if ( false === $settings ) {
94-
$settings = [
95-
'cloud_token' => '',
96-
'local_token' => '',
97-
'token_verified' => false,
98-
'code_verifier' => '',
99-
'code_challenge' => '',
100-
'state' => '',
101-
];
102-
103-
update_option( self::CLOUD_SETTINGS_CACHE_KEY, $settings );
104-
}
105-
106-
wp_cache_set( self::CLOUD_SETTINGS_CACHE_KEY, $settings );
107-
return $settings;
108-
}
109-
11072
/**
11173
* Retrieve the cloud local token.
11274
*
@@ -335,6 +297,8 @@ public static function get_cloud_snippet_revision( string $cloud_id ): ?string {
335297
* @param string $action The action to be performed: 'download' or 'update'.
336298
*
337299
* @return array<string, string|bool> Result of operation: an array with `success` and `error_message` keys.
300+
*
301+
* @noinspection PhpUnusedParameterInspection
338302
*/
339303
public function download_or_update_snippet( int $cloud_id, string $source, string $action ): array {
340304
$cloud_id = intval( $cloud_id );

src/php/cloud/class-cloud-search-list-table.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ class Cloud_Search_List_Table extends WP_Plugin_Install_List_Table {
4141
* Class constructor.
4242
*/
4343
public function __construct() {
44-
// Declare global variable due to undeclared warning.
44+
/**
45+
* Declare global variable due to undeclared warning.
46+
*
47+
* @noinspection PhpUnusedLocalVariableInspection
48+
*/
4549
global $tab;
4650

4751
parent::__construct(

src/php/settings/settings-fields.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
namespace Code_Snippets\Settings;
1010

11-
use function Code_Snippets\code_snippets;
12-
1311
/**
1412
* Retrieve the default setting values
1513
*
@@ -211,8 +209,8 @@ function get_settings_fields(): array {
211209
'default' => true,
212210
'codemirror' => 'styleActiveLine',
213211
],
214-
215-
'keymap' => [
212+
213+
'keymap' => [
216214
'name' => __( 'Keymap', 'code-snippets' ),
217215
'type' => 'select',
218216
'desc' => __( 'The set of keyboard shortcuts to use in the code editor.', 'code-snippets' ),
@@ -232,7 +230,7 @@ function get_settings_fields(): array {
232230
'default' => 'default',
233231
'options' => get_editor_theme_list(),
234232
'codemirror' => 'theme',
235-
],
233+
],
236234
];
237235

238236
$fields = apply_filters( 'code_snippets_settings_fields', $fields );

src/php/settings/settings.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
namespace Code_Snippets\Settings;
1010

1111
use Code_Snippets\Welcome_API;
12-
use Code_Snippets\Welcome_Menu;
1312
use function Code_Snippets\clean_snippets_cache;
1413
use function Code_Snippets\code_snippets;
1514

0 commit comments

Comments
 (0)