Skip to content

Commit 1377fae

Browse files
committed
Convert new functionality to be PSR-compliant.
1 parent c8fd032 commit 1377fae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1205
-481
lines changed

phpcs.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
<!-- allow hooks containing forward slashes -->
99
<exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores" />
1010

11-
<!-- necessary for core plugin function -->
12-
<exclude name="Squiz.PHP.Eval.Discouraged" />
11+
<!-- PSR-4 -->
12+
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
13+
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
14+
<exclude name="Squiz.Commenting.FileComment.Missing" />
1315

1416
<!-- allow embedding PHP within HTML attribute values -->
1517
<exclude name="Squiz.PHP.EmbeddedPhp.ContentBeforeOpen" />
@@ -34,7 +36,7 @@
3436
<exclude name="WordPress.PHP.DisallowShortTernary.Found" />
3537
<exclude name="Generic.PHP.DisallowShortOpenTag.EchoFound" />
3638
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found" />
37-
</rule>
39+
</rule>
3840

3941
<rule ref="PHPCompatibilityWP">
4042
<include-pattern>*\.php$</include-pattern>

src/php/Admin/Bootstrap_Admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ public function debug_information( array $info ): array {
241241
* Print any admin notices that have not been dismissed.
242242
*
243243
* @return void
244+
* @noinspection PhpRedundantOptionalArgumentInspection
244245
*/
245246
public function print_notices() {
246247
global $current_user;

src/php/Admin/Menus/Admin_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\Admin\Menus;
44

5-
use Code_Snippets\Model\Snippet;
65
use function Code_Snippets\code_snippets;
76

87
/**

src/php/Admin/Menus/Edit_Menu.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use function Code_Snippets\Settings\get_setting;
1111
use function Code_Snippets\Settings\get_settings_values;
1212
use function Code_Snippets\Utils\enqueue_code_editor;
13+
use const Code_Snippets\PLUGIN_FILE;
14+
use const Code_Snippets\PLUGIN_VERSION;
1315

1416
/**
1517
* This class handles the add/edit menu.
@@ -145,7 +147,6 @@ public function load_snippet_data() {
145147
* @return void
146148
*/
147149
public function enqueue_assets() {
148-
$plugin = code_snippets();
149150
$rtl = is_rtl() ? '-rtl' : '';
150151

151152
$settings = get_settings_values();
@@ -156,20 +157,20 @@ public function enqueue_assets() {
156157

157158
wp_enqueue_style(
158159
self::CSS_HANDLE,
159-
plugins_url( "dist/edit$rtl.css", $plugin->file ),
160+
plugins_url( "dist/edit$rtl.css", PLUGIN_FILE ),
160161
[
161162
'code-editor',
162163
'wp-components',
163164
],
164-
$plugin->version
165+
PLUGIN_VERSION
165166
);
166167

167168
wp_enqueue_script(
168169
self::JS_HANDLE,
169-
plugins_url( 'dist/edit.js', $plugin->file ),
170+
plugins_url( 'dist/edit.js', PLUGIN_FILE ),
170171
[ 'code-snippets-code-editor' ] + self::$script_deps,
171-
$plugin->version,
172-
true
172+
PLUGIN_VERSION,
173+
[ 'in_footer' => true ]
173174
);
174175

175176
wp_set_script_translations( self::JS_HANDLE, 'code-snippets' );
@@ -179,7 +180,7 @@ public function enqueue_assets() {
179180
wp_enqueue_editor();
180181
}
181182

182-
$plugin->localize_script( self::JS_HANDLE );
183+
code_snippets()->localize_script( self::JS_HANDLE );
183184

184185
wp_localize_script(
185186
self::JS_HANDLE,

src/php/Admin/Menus/Import_Menu.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Code_Snippets\Admin\Menus;
44

55
use Code_Snippets\Admin\Contextual_Help;
6-
use Code_Snippets\Import;
6+
use Code_Snippets\Export\Import;
77
use function Code_Snippets\code_snippets;
88

99
/**

src/php/Admin/Menus/Manage_Menu.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,17 @@ public function enqueue_assets() {
183183

184184
wp_enqueue_style(
185185
self::CSS_HANDLE,
186-
plugins_url( "dist/manage$rtl.css", $plugin->file ),
186+
plugins_url( "dist/manage$rtl.css", PLUGIN_FILE ),
187187
self::$style_deps,
188-
$plugin->version
188+
PLUGIN_VERSION
189189
);
190190

191191
wp_enqueue_script(
192192
self::JS_HANDLE,
193-
plugins_url( 'dist/manage.js', $plugin->file ),
193+
plugins_url( 'dist/manage.js', PLUGIN_FILE ),
194194
self::$script_deps,
195-
$plugin->version,
196-
true
195+
PLUGIN_VERSION,
196+
[ 'in_footer' => true ]
197197
);
198198

199199
Code_Highlighter::enqueue_all_prism_themes();

src/php/Client/Cloud_API.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static function get_local_token(): string {
8181
/**
8282
* Check if the API key is set and verified.
8383
*
84-
* @return boolean
84+
* @return bool
8585
*/
8686
public static function is_cloud_connection_available(): bool {
8787
return false;
@@ -174,9 +174,9 @@ private static function unpack_request_json( $response ): ?array {
174174
/**
175175
* Search Code Snippets Cloud -> Static Function
176176
*
177-
* @param string $search_method Search by name of codevault or keyword(s).
178-
* @param string $search Search query.
179-
* @param integer $page Search result page to retrieve. Defaults to '0'.
177+
* @param string $search_method Search by name of codevault or keyword(s).
178+
* @param string $search Search query.
179+
* @param int $page Search result page to retrieve. Defaults to '0'.
180180
*
181181
* @return Cloud_Snippets Result of search query.
182182
*/

src/php/Core/DB.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public function get_table_name( ?bool $is_network = null ): string {
9999
/**
100100
* Determine whether a database table exists.
101101
*
102-
* @param string $table_name Name of database table to check.
103-
* @param boolean $refresh Rerun the query, instead of using a cached value.
102+
* @param string $table_name Name of database table to check.
103+
* @param bool $refresh Rerun the query, instead of using a cached value.
104104
*
105105
* @return bool Whether the database table exists.
106106
*/
@@ -188,7 +188,7 @@ public static function create_table( string $table_name ): bool {
188188
*
189189
* @param string $table_name Name of table to fetch snippets from.
190190
* @param array<string> $scopes List of scopes to include in query.
191-
* @param boolean $active_only Whether to only fetch active snippets from the table.
191+
* @param bool $active_only Whether to only fetch active snippets from the table.
192192
*
193193
* @return array<string, array<string, mixed>>|false List of active snippets, if any could be retrieved.
194194
*
@@ -280,6 +280,8 @@ static function ( $a, $b ) use ( $comparisons ) {
280280
* network: bool,
281281
* priority: int,
282282
* } List of active snippets.
283+
*
284+
* @noinspection PhpRedundantOptionalArgumentInspection
283285
*/
284286
public function fetch_active_snippets( array $scopes ): array {
285287
$active_snippets = [];

src/php/Export/Export.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ abstract class Export {
2222
/**
2323
* Class constructor
2424
*
25-
* @param array<int> $ids List of snippet IDs to export.
26-
* @param boolean|null $network Whether to fetch snippets from local or network table.
25+
* @param array<int> $ids List of snippet IDs to export.
26+
* @param bool|null $network Whether to fetch snippets from local or network table.
2727
*/
2828
public function __construct( array $ids, ?bool $network = null ) {
2929
$this->snippets_list = get_snippets( $ids, $network );

src/php/Export/Export_JSON.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Code_Snippets\Export;
44

55
use Code_Snippets\Model\Snippet;
6-
use function Code_Snippets\code_snippets;
6+
use const Code_Snippets\PLUGIN_VERSION;
77

88
/**
99
* Handles exporting snippets from the site in various downloadable formats
@@ -41,7 +41,7 @@ function ( $value ) {
4141
}
4242

4343
return [
44-
'generator' => 'Code Snippets v' . code_snippets()->version,
44+
'generator' => 'Code Snippets v' . PLUGIN_VERSION,
4545
'date_created' => gmdate( 'Y-m-d H:i' ),
4646
'snippets' => $snippets,
4747
];

0 commit comments

Comments
 (0)