Skip to content

Commit 3615722

Browse files
Enforce checks against redeclaration for functions and classes (#52696)
Enforce checks against redeclaration for functions and classes. See https://github.com/WordPress/gutenberg/blob/trunk/lib/README.md#wrap-functions-and-classes-with--function_exists-and--class_exists Props: @tellthemachines @azaozz @ramonjd @anton-vlasenko
1 parent 757113d commit 3615722

35 files changed

+794
-138
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
/packages/scripts @gziolo @ntwb @nerrad @ajitbohra @ryanwelcher
8383
/packages/stylelint-config @ntwb
8484
/test/e2e @kevin940726 @Mamaduka
85+
/test/php/gutenberg-coding-standards @anton-vlasenko
8586

8687
# UI Components
8788
/packages/components @ajitbohra

composer.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,18 @@
3232
"wp-coding-standards/wpcs": "^2.2",
3333
"sirbrillig/phpcs-variable-analysis": "^2.8",
3434
"spatie/phpunit-watcher": "^1.23",
35-
"yoast/phpunit-polyfills": "^1.0"
35+
"yoast/phpunit-polyfills": "^1.0",
36+
"gutenberg/gutenberg-coding-standards": "@dev"
3637
},
38+
"repositories": [
39+
{
40+
"type": "path",
41+
"url": "./test/php/gutenberg-coding-standards",
42+
"options": {
43+
"symlink": false
44+
}
45+
}
46+
],
3747
"require": {
3848
"composer/installers": "~1.0"
3949
},

lib/class-wp-duotone-gutenberg.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
* @since 6.3.0
3333
*/
3434

35+
if ( class_exists( 'WP_Duotone_Gutenberg' ) ) {
36+
return;
37+
}
38+
3539
/**
3640
* Manages duotone block supports and global styles.
3741
*

lib/class-wp-theme-json-data-gutenberg.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
* @since 6.1.0
77
*/
88

9+
if ( class_exists( 'WP_Theme_JSON_Data_Gutenberg' ) ) {
10+
return;
11+
}
12+
913
/**
1014
* Class to provide access to update a theme.json structure.
1115
*/

lib/class-wp-theme-json-gutenberg.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
* @since 5.8.0
77
*/
88

9+
if ( class_exists( 'WP_Theme_JSON_Gutenberg' ) ) {
10+
return;
11+
}
12+
913
/**
1014
* Class that encapsulates the processing of structures that adhere to the theme.json spec.
1115
*

lib/class-wp-theme-json-resolver-gutenberg.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
* @since 5.8.0
77
*/
88

9+
if ( class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' ) ) {
10+
return;
11+
}
12+
913
/**
1014
* Class that abstracts the processing of the different data sources
1115
* for site-level config and offers an API to work with them.

lib/compat/wordpress-6.2/html-api/class-wp-html-attribute-token.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
* @since 6.2.0
88
*/
99

10+
if ( class_exists( 'WP_HTML_Attribute_Token' ) ) {
11+
return;
12+
}
13+
1014
/**
1115
* Data structure for the attribute token that allows to drastically improve performance.
1216
*

lib/compat/wordpress-6.2/html-api/class-wp-html-span.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
* @since 6.2.0
88
*/
99

10+
if ( class_exists( 'WP_HTML_Span' ) ) {
11+
return;
12+
}
13+
1014
/**
1115
* Represents a textual span inside an HTML document.
1216
*

lib/compat/wordpress-6.2/html-api/class-wp-html-tag-processor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
* @since 6.2.0
2727
*/
2828

29+
if ( class_exists( 'WP_HTML_Tag_Processor' ) ) {
30+
return;
31+
}
32+
2933
/**
3034
* Modifies attributes in an HTML document for tags matching a query.
3135
*

lib/compat/wordpress-6.2/html-api/class-wp-html-text-replacement.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
* @since 6.2.0
88
*/
99

10+
if ( class_exists( 'WP_HTML_Text_Replacement' ) ) {
11+
return;
12+
}
13+
1014
/**
1115
* Data structure used to replace existing content from start to end that allows to drastically improve performance.
1216
*

0 commit comments

Comments
 (0)