Skip to content

Commit 8fd79e1

Browse files
authored
Merge pull request #765 from alleyinteractive/feature/create-packages-phpstan
Improve phpstan typings for generated blocks and entries
2 parents 1ecfabe + e1de55b commit 8fd79e1

5 files changed

Lines changed: 26 additions & 11 deletions

File tree

.changeset/young-gorillas-hope.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@alleyinteractive/create-block": patch
3+
"@alleyinteractive/create-entry": patch
4+
---
5+
6+
Improve the phpstan typings.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"scripts": {
1212
"prebuild": "check-node-version --package",
1313
"build": "turbo run build --cache-dir=.turbo",
14+
"changeset": "npx @changesets/cli",
1415
"preinstall": "check-node-version --package",
1516
"prelint": "check-node-version --package",
1617
"lint": "turbo run lint --cache-dir=.turbo",

packages/create-block/templates/javascript/render.php.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*
88
* @phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- File doesn't load in global scope, just appears to to PHPCS.
99
*
10-
* @var array $attributes The array of attributes for this block.
11-
* @var string $content Rendered block output. ie. <InnerBlocks.Content />.
12-
* @var WP_Block $block The instance of the WP_Block class that represents the block being rendered.
10+
* @var array<string, mixed> $attributes The array of attributes for this block.
11+
* @var string $content Rendered block output. ie. <InnerBlocks.Content />.
12+
* @var WP_Block $block The instance of the WP_Block class that represents the block being rendered.
1313
*
1414
* @package {{namespace}}
1515
*/

packages/create-block/templates/typescript/render.php.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*
88
* @phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- File doesn't load in global scope, just appears to to PHPCS.
99
*
10-
* @var array $attributes The array of attributes for this block.
11-
* @var string $content Rendered block output. ie. <InnerBlocks.Content />.
12-
* @var WP_Block $block The instance of the WP_Block class that represents the block being rendered.
10+
* @var array<string, mixed> $attributes The array of attributes for this block.
11+
* @var string $content Rendered block output. ie. <InnerBlocks.Content />.
12+
* @var WP_Block $block The instance of the WP_Block class that represents the block being rendered.
1313
*
1414
* @package {{namespace}}
1515
*/

packages/create-entry/templates/entry/index.php.mustache

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@
1616
/**
1717
* Register the {{slug}} entry point assets so that they can be enqueued.
1818
*/
19-
function {{nameSpaceSnakeCase}}_register_{{slugUnderscore}}_scripts() {
20-
// Automatically load dependencies and version.
19+
function {{nameSpaceSnakeCase}}_register_{{slugUnderscore}}_scripts(): void {
20+
/**
21+
* Asset file generated by wp-scripts.
22+
*
23+
* @var array{dependencies: string[], version: string}|false $asset_file
24+
*/
2125
$asset_file = include __DIR__ . '/index.asset.php';
2226

27+
if ( ! $asset_file ) {
28+
return;
29+
}
30+
2331
// Register the {{slug}} script.
2432
wp_register_script(
2533
'{{prefixNameSpace}}-{{slug}}-js',
@@ -45,7 +53,7 @@ add_action( 'init', '{{nameSpaceSnakeCase}}_register_{{slugUnderscore}}_scripts'
4553
/**
4654
* Enqueue scripts for the {{slug}} entry point.
4755
*/
48-
function {{nameSpaceSnakeCase}}_enqueue_{{slugUnderscore}}_scripts() {
56+
function {{nameSpaceSnakeCase}}_enqueue_{{slugUnderscore}}_scripts(): void {
4957
wp_enqueue_script( '{{prefixNameSpace}}-{{slug}}-js' );
5058
}
5159
add_action( '{{enqueueHook}}', '{{nameSpaceSnakeCase}}_enqueue_{{slugUnderscore}}_scripts' );
@@ -54,9 +62,9 @@ add_action( '{{enqueueHook}}', '{{nameSpaceSnakeCase}}_enqueue_{{slugUnderscore}
5462
/**
5563
* Enqueue styles for the {{slug}} entry point.
5664
*/
57-
function {{nameSpaceSnakeCase}}_enqueue_{{slugUnderscore}}_styles() {
65+
function {{nameSpaceSnakeCase}}_enqueue_{{slugUnderscore}}_styles(): void {
5866
wp_enqueue_style( '{{prefixNameSpace}}-{{slug}}-css' );
5967
}
6068
add_action( '{{enqueueStyleHook}}', '{{nameSpaceSnakeCase}}_enqueue_{{slugUnderscore}}_styles' );
6169
{{/hasStyles}}
62-
{{/hasEnqueue}}
70+
{{/hasEnqueue}}

0 commit comments

Comments
 (0)