Skip to content

Commit d78536d

Browse files
authored
PHPCS: enalbe VariableAnalysis.CodeAnalysis.VariableAnalysis rule (#782)
* PHPCS: enalbe VariableAnalysis.CodeAnalysis.VariableAnalysis rule * Fix all php lint error * Restore method call * remove comment
1 parent a52d29c commit d78536d

File tree

9 files changed

+22
-29
lines changed

9 files changed

+22
-29
lines changed

includes/class-create-block-theme-api.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function register_rest_routes() {
157157
);
158158
}
159159

160-
function rest_get_theme_data( $request ) {
160+
function rest_get_theme_data() {
161161
try {
162162
$theme_data = CBT_Theme_JSON_Resolver::get_theme_file_contents();
163163
return new WP_REST_Response(
@@ -177,7 +177,7 @@ function rest_get_theme_data( $request ) {
177177
}
178178
}
179179

180-
function rest_get_readme_data( $request ) {
180+
function rest_get_readme_data() {
181181
try {
182182
$readme_data = CBT_Theme_Readme::get_sections();
183183
return new WP_REST_Response(
@@ -288,7 +288,7 @@ function rest_create_blank_theme( $request ) {
288288
/**
289289
* Export the theme as a ZIP file.
290290
*/
291-
function rest_export_theme( $request ) {
291+
function rest_export_theme() {
292292
if ( ! class_exists( 'ZipArchive' ) ) {
293293
return new WP_Error(
294294
'missing_zip_package',
@@ -306,10 +306,10 @@ function rest_export_theme( $request ) {
306306

307307
if ( is_child_theme() ) {
308308
wp_cache_flush();
309-
$zip = CBT_Theme_Zip::add_templates_to_zip( $zip, 'current', $theme_slug );
309+
$zip = CBT_Theme_Zip::add_templates_to_zip( $zip, 'current' );
310310
$theme_json = CBT_Theme_JSON_Resolver::export_theme_data( 'current' );
311311
} else {
312-
$zip = CBT_Theme_Zip::add_templates_to_zip( $zip, 'all', null );
312+
$zip = CBT_Theme_Zip::add_templates_to_zip( $zip, 'all' );
313313
$theme_json = CBT_Theme_JSON_Resolver::export_theme_data( 'all' );
314314
}
315315

@@ -418,7 +418,7 @@ function rest_save_theme( $request ) {
418418
* It includes the font families from the theme.json data (theme.json file + global styles) and the theme style variations.
419419
* The font families with font faces containing src urls relative to the theme folder are converted to absolute urls.
420420
*/
421-
function rest_get_font_families( $request ) {
421+
function rest_get_font_families() {
422422
$font_families = CBT_Theme_Fonts::get_all_fonts();
423423

424424
return new WP_REST_Response(
@@ -457,6 +457,7 @@ function rest_reset_theme( $request ) {
457457
}
458458

459459
private function sanitize_theme_data( $theme ) {
460+
$sanitized_theme = array();
460461
$sanitized_theme['name'] = sanitize_text_field( $theme['name'] );
461462
$sanitized_theme['description'] = sanitize_text_field( $theme['description'] ?? '' );
462463
$sanitized_theme['uri'] = sanitize_text_field( $theme['uri'] ?? '' );

includes/class-create-block-theme.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ private function load_dependencies() {
5656
* @access private
5757
*/
5858
private function define_admin_hooks() {
59-
$plugin_api = new CBT_Theme_API();
60-
$editor_tools = new CBT_Editor_Tools();
61-
$admin_landing = new CBT_Admin_Landing();
59+
new CBT_Theme_API();
60+
new CBT_Editor_Tools();
61+
new CBT_Admin_Landing();
6262
}
6363

6464
/**

includes/create-theme/theme-patterns.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static function replace_local_pattern_references( $pattern ) {
8989
$templates_to_update = array_unique( $templates_to_update );
9090

9191
// Only update templates that reference the pattern
92-
CBT_Theme_Templates::add_templates_to_local( 'all', null, null, $options, $templates_to_update );
92+
CBT_Theme_Templates::add_templates_to_local( 'all', null, null, null, $templates_to_update );
9393

9494
// List all template and pattern files in the theme
9595
$base_dir = get_stylesheet_directory();
@@ -185,7 +185,6 @@ public static function add_patterns_to_theme( $options = null ) {
185185
}
186186

187187
// Create the pattern file.
188-
$pattern_file = $patterns_dir . $pattern->name . '.php';
189188
file_put_contents(
190189
$patterns_dir . DIRECTORY_SEPARATOR . $pattern->name . '.php',
191190
$pattern->content

includes/create-theme/theme-readme.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,17 @@ public static function get_content() {
3131
* {
3232
* @type string $name The theme name.
3333
* @type string $description The theme description.
34-
* @type string $uri The theme URI.
3534
* @type string $author The theme author.
36-
* @type string $author_uri The theme author URI.
37-
* @type string $copyright_year The copyright year.
3835
* @type string $image_credits The image credits.
3936
* @type string $recommended_plugins The recommended plugins.
40-
* @type bool $is_child_theme Whether the theme is a child theme.
4137
* }
4238
*
4339
* @return string The readme content.
4440
*/
4541
public static function create( $theme ) {
4642
$name = $theme['name'];
4743
$description = $theme['description'] ?? '';
48-
$uri = $theme['uri'] ?? '';
4944
$author = $theme['author'] ?? '';
50-
$author_uri = $theme['author_uri'] ?? '';
51-
$copy_year = $theme['copyright_year'] ?? gmdate( 'Y' );
5245
$wp_version = $theme['wp_version'] ?? CBT_Theme_Utils::get_current_wordpress_version();
5346
$requires_wp = ( '' === $theme['requires_wp'] ) ? CBT_Theme_Utils::get_current_wordpress_version() : $theme['requires_wp'];
5447
$required_php_version = $theme['required_php_version'] ?? '5.7';
@@ -57,7 +50,6 @@ public static function create( $theme ) {
5750
$image_credits = $theme['image_credits'] ?? '';
5851
$recommended_plugins = $theme['recommended_plugins'] ?? '';
5952
$font_credits = $theme['font_credits'] ?? '';
60-
$is_child_theme = $theme['is_child_theme'] ?? false;
6153

6254
// Generates the copyright section text.
6355
$copyright_section_content = self::get_copyright_text( $theme );

includes/create-theme/theme-styles.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static function clear_user_styles_customizations() {
115115
$update_request->set_param( 'id', $user_custom_post_type_id );
116116
$update_request->set_param( 'settings', array() );
117117
$update_request->set_param( 'styles', array() );
118-
$updated_global_styles = $global_styles_controller->update_item( $update_request );
118+
$global_styles_controller->update_item( $update_request );
119119
delete_transient( 'global_styles' );
120120
delete_transient( 'global_styles_' . get_stylesheet() );
121121
delete_transient( 'gutenberg_global_styles' );

includes/create-theme/theme-utils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static function clone_theme_to_folder( $location, $new_slug, $new_name )
5353
);
5454

5555
// Add all the files (except for templates)
56-
foreach ( $files as $name => $file ) {
56+
foreach ( $files as $file ) {
5757

5858
// Get real and relative path for current file
5959
$file_path = wp_normalize_path( $file );

includes/create-theme/theme-zip.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static function copy_theme_to_zip( $zip, $new_slug, $new_name ) {
110110
);
111111

112112
// Add all the files (except for templates)
113-
foreach ( $files as $name => $file ) {
113+
foreach ( $files as $file ) {
114114

115115
// Skip directories (they would be added automatically)
116116
if ( ! $file->isDir() ) {
@@ -162,7 +162,7 @@ public static function copy_theme_to_zip( $zip, $new_slug, $new_name ) {
162162
* user = only user edited templates
163163
* all = all templates no matter what
164164
*/
165-
public static function add_templates_to_zip( $zip, $export_type, $new_slug ) {
165+
public static function add_templates_to_zip( $zip, $export_type ) {
166166

167167
$theme_templates = CBT_Theme_Templates::get_theme_templates( $export_type );
168168
$template_folders = get_block_theme_folders();

phpcs.xml.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
</properties>
2525
</rule>
2626

27+
<!-- Detect unused PHP variables -->
28+
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis">
29+
<properties>
30+
<property name="allowUnusedParametersBeforeUsed" value="true"/>
31+
</properties>
32+
</rule>
33+
2734
<!-- Strip the filepaths down to the relevant bit. -->
2835
<arg name="basepath" value="./"/>
2936

tests/CbtThemeReadme/create.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,9 @@ public function test_create( $data ) {
2424
$readme_without_newlines = $this->remove_newlines( $readme );
2525

2626
$expected_name = '== ' . $data['name'] . ' ==';
27-
$expected_description = '== Description ==' . $data['description'];
28-
$expected_uri = 'Theme URI: ' . $data['uri'];
2927
$expected_author = 'Contributors: ' . $data['author'];
30-
$expected_author_uri = 'Author URI: ' . $data['author_uri'];
3128
$expected_requires_wp = 'Requires at least: ' . $data['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version();
3229
$expected_wp_version = 'Tested up to: ' . $data['wp_version'] ?? CBT_Theme_Utils::get_current_wordpress_version();
33-
$expected_php_version = 'Requires PHP: ' . $data['required_php_version'];
34-
$expected_license = 'License: ' . $data['license'];
35-
$expected_license_uri = 'License URI: ' . $data['license_uri'];
3630
$expected_font_credits = '== Fonts ==' .
3731
( isset( $data['font_credits'] )
3832
? $this->remove_newlines( $data['font_credits'] )

0 commit comments

Comments
 (0)