Skip to content

Commit 8c8770a

Browse files
committed
feat: modify 修改 phpcs,允許短語法array
1 parent e13eedb commit 8c8770a

File tree

4 files changed

+51
-45
lines changed

4 files changed

+51
-45
lines changed

inc/class/admin/class-cpt.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,41 @@ final class CPT {
2121
*
2222
* @var array
2323
*/
24-
public $post_meta_array = array();
24+
public $post_meta_array = [];
2525
/**
2626
* Rewrite
2727
*
2828
* @var array
2929
*/
30-
public $rewrite = array();
30+
public $rewrite = [];
3131

3232
/**
3333
* Constructor
3434
*/
3535
public function __construct() {
36-
$args = array(
37-
'post_meta_array' => array( 'meta', 'settings' ),
38-
'rewrite' => array(
36+
$args = [
37+
'post_meta_array' => [ 'meta', 'settings' ],
38+
'rewrite' => [
3939
'template_path' => 'test.php',
4040
'slug' => 'test',
4141
'var' => Plugin::$snake . '_test',
42-
),
43-
);
42+
],
43+
];
4444
$this->post_meta_array = $args['post_meta_array'];
45-
$this->rewrite = $args['rewrite'] ?? array();
45+
$this->rewrite = $args['rewrite'] ?? [];
4646

47-
\add_action( 'init', array( $this, 'init' ) );
47+
\add_action( 'init', [ $this, 'init' ] );
4848

4949
if ( ! empty( $args['post_meta_array'] ) ) {
50-
\add_action( 'rest_api_init', array( $this, 'add_post_meta' ) );
50+
\add_action( 'rest_api_init', [ $this, 'add_post_meta' ] );
5151
}
5252

53-
\add_action( 'load-post.php', array( $this, 'init_metabox' ) );
54-
\add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
53+
\add_action( 'load-post.php', [ $this, 'init_metabox' ] );
54+
\add_action( 'load-post-new.php', [ $this, 'init_metabox' ] );
5555

5656
if ( ! empty( $args['rewrite'] ) ) {
57-
\add_filter( 'query_vars', array( $this, 'add_query_var' ) );
58-
\add_filter( 'template_include', array( $this, 'load_custom_template' ), 99 );
57+
\add_filter( 'query_vars', [ $this, 'add_query_var' ] );
58+
\add_filter( 'template_include', [ $this, 'load_custom_template' ], 99 );
5959
}
6060
}
6161

@@ -77,7 +77,7 @@ public function init(): void {
7777
*/
7878
public static function register_cpt(): void {
7979

80-
$labels = array(
80+
$labels = [
8181
'name' => \esc_html__( 'my-app', 'wp_react_plugin' ),
8282
'singular_name' => \esc_html__( 'my-app', 'wp_react_plugin' ),
8383
'add_new' => \esc_html__( 'Add new', 'wp_react_plugin' ),
@@ -109,8 +109,8 @@ public static function register_cpt(): void {
109109
'item_reverted_to_draft' => \esc_html__( 'my-app reverted to draft', 'wp_react_plugin' ),
110110
'item_scheduled' => \esc_html__( 'my-app scheduled', 'wp_react_plugin' ),
111111
'item_updated' => \esc_html__( 'my-app updated', 'wp_react_plugin' ),
112-
);
113-
$args = array(
112+
];
113+
$args = [
114114
'label' => \esc_html__( 'my-app', 'wp_react_plugin' ),
115115
'labels' => $labels,
116116
'description' => '',
@@ -131,13 +131,13 @@ public static function register_cpt(): void {
131131
'menu_position' => 6,
132132
'menu_icon' => 'dashicons-store',
133133
'capability_type' => 'post',
134-
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields', 'author' ),
135-
'taxonomies' => array(),
134+
'supports' => [ 'title', 'editor', 'thumbnail', 'custom-fields', 'author' ],
135+
'taxonomies' => [],
136136
'rest_controller_class' => 'WP_REST_Posts_Controller',
137-
'rewrite' => array(
137+
'rewrite' => [
138138
'with_front' => true,
139-
),
140-
);
139+
],
140+
];
141141

142142
\register_post_type( 'my-app', $args );
143143
}
@@ -150,11 +150,11 @@ public function add_post_meta(): void {
150150
\register_meta(
151151
'post',
152152
Plugin::$snake . '_' . $meta_key,
153-
array(
153+
[
154154
'type' => 'string',
155155
'show_in_rest' => true,
156156
'single' => true,
157-
)
157+
]
158158
);
159159
}
160160
}
@@ -163,9 +163,9 @@ public function add_post_meta(): void {
163163
* Meta box initialization.
164164
*/
165165
public function init_metabox(): void {
166-
\add_action( 'add_meta_boxes', array( $this, 'add_metabox' ) );
167-
\add_action( 'save_post', array( $this, 'save_metabox' ), 10, 2 );
168-
\add_filter( 'rewrite_rules_array', array( $this, 'custom_post_type_rewrite_rules' ) );
166+
\add_action( 'add_meta_boxes', [ $this, 'add_metabox' ] );
167+
\add_action( 'save_post', [ $this, 'save_metabox' ], 10, 2 );
168+
\add_filter( 'rewrite_rules_array', [ $this, 'custom_post_type_rewrite_rules' ] );
169169
}
170170

171171
/**
@@ -174,11 +174,11 @@ public function init_metabox(): void {
174174
* @param string $post_type Post type.
175175
*/
176176
public function add_metabox( string $post_type ): void {
177-
if ( in_array( $post_type, array( Plugin::$kebab ) ) ) {
177+
if ( in_array( $post_type, [ Plugin::$kebab ] ) ) {
178178
\add_meta_box(
179179
Plugin::$kebab . '-metabox',
180180
__( 'My App', 'wp_react_plugin' ),
181-
array( $this, 'render_meta_box' ),
181+
[ $this, 'render_meta_box' ],
182182
$post_type,
183183
'advanced',
184184
'high'

inc/class/class-bootstrap.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public function __construct() {
2424
require_once __DIR__ . '/admin/index.php';
2525
require_once __DIR__ . '/front-end/index.php';
2626

27-
\add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_script' ), 99 );
28-
\add_action( 'wp_enqueue_scripts', array( $this, 'frontend_enqueue_script' ), 99 );
27+
\add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_script' ], 99 );
28+
\add_action( 'wp_enqueue_scripts', [ $this, 'frontend_enqueue_script' ], 99 );
2929
}
3030

3131
/**
@@ -62,10 +62,10 @@ public function enqueue_script(): void {
6262
Vite\enqueue_asset(
6363
Plugin::$dir . '/js/dist',
6464
'js/src/main.tsx',
65-
array(
65+
[
6666
'handle' => Plugin::$kebab,
6767
'in-footer' => true,
68-
)
68+
]
6969
);
7070

7171
$post_id = \get_the_ID();
@@ -74,8 +74,8 @@ public function enqueue_script(): void {
7474
\wp_localize_script(
7575
Plugin::$kebab,
7676
Plugin::$snake . '_data',
77-
array(
78-
'env' => array(
77+
[
78+
'env' => [
7979
'siteUrl' => \untrailingslashit( \site_url() ),
8080
'ajaxUrl' => \untrailingslashit( \admin_url( 'admin-ajax.php' ) ),
8181
'userId' => \wp_get_current_user()->data->ID ?? null,
@@ -89,17 +89,17 @@ public function enqueue_script(): void {
8989
'APP2_SELECTOR' => Base::APP2_SELECTOR,
9090
'API_TIMEOUT' => Base::API_TIMEOUT,
9191
'nonce' => \wp_create_nonce( Plugin::$kebab ),
92-
),
93-
)
92+
],
93+
]
9494
);
9595

9696
\wp_localize_script(
9797
Plugin::$kebab,
9898
'wpApiSettings',
99-
array(
99+
[
100100
'root' => \untrailingslashit( \esc_url_raw( rest_url() ) ),
101101
'nonce' => \wp_create_nonce( 'wp_rest' ),
102-
)
102+
]
103103
);
104104
}
105105
}

inc/class/front-end/class-entry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class Entry {
1818
* Constructor
1919
*/
2020
public function __construct() {
21-
\add_action( 'wp_footer', array( $this, 'render_app' ) );
21+
\add_action( 'wp_footer', [ $this, 'render_app' ] );
2222
}
2323

2424
/**

phpcs.xml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,22 @@
8484
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar"/>
8585
</rule>
8686

87-
<rule ref="Generic.Arrays.DisallowLongArraySyntax">
88-
<exclude name="Generic.Arrays.DisallowLongArraySyntax.Found"/>
87+
<!-- Allow short syntax arrays. -->
88+
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
89+
<rule ref="Universal.Arrays.DisallowShortArraySyntax.Found">
90+
<severity>0</severity>
91+
</rule>
92+
<!-- Disallow long array syntax -->
93+
<rule ref="Generic.Arrays.DisallowShortArraySyntax.Found">
94+
<exclude-pattern>*</exclude-pattern>
8995
</rule>
9096

91-
<rule ref="Universal.Arrays.DisallowShortArraySyntax">
92-
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found"/>
93-
</rule>
9497

9598
<rule ref="Generic.Files.LineEndings">
9699
<exclude name="Generic.Files.LineEndings.InvalidEOLChar"/>
97100
</rule>
98101

102+
103+
104+
99105
</ruleset>

0 commit comments

Comments
 (0)