Skip to content

Commit d771e8d

Browse files
gzioloclaude
andcommitted
Connectors: Address review feedback on PHPDoc and test improvements.
Removes the duplicate untyped `@param array` tag from `_wp_connectors_get_connector_script_module_data()` left over after applying the `@param array<string, mixed>` suggestion. In `wpGetConnectors.php`, adds `void` return types to all test methods for PHPStan level 8 compliance, and uses `?? null` when accessing optional array keys (`setting_name`, `credentials_url`) so PHPStan does not complain about potentially missing offsets. Props gziolo, westonruter. Fixes #64791. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent a5ea32a commit d771e8d

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

src/wp-includes/connectors.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ function _wp_connectors_pass_default_keys_to_ai_client(): void {
536536
* @since 7.0.0
537537
* @access private
538538
*
539-
* @param array $data Existing script module data.
540539
* @param array<string, mixed> $data Existing script module data.
541540
* @return array<string, mixed> Script module data with connectors added.
542541
*/

tests/phpunit/tests/connectors/wpGetConnectors.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ class Tests_Connectors_WpGetConnectors extends WP_UnitTestCase {
1515
/**
1616
* Registers the mock provider once before any tests in this class run.
1717
*/
18-
public static function set_up_before_class() {
18+
public static function set_up_before_class(): void {
1919
parent::set_up_before_class();
2020
self::register_mock_connectors_provider();
2121
}
2222

2323
/**
2424
* Unregisters the mock provider setting added by `init`.
2525
*/
26-
public static function tear_down_after_class() {
26+
public static function tear_down_after_class(): void {
2727
self::unregister_mock_connector_setting();
2828
parent::tear_down_after_class();
2929
}
3030

3131
/**
3232
* @ticket 64730
3333
*/
34-
public function test_returns_expected_connector_keys() {
34+
public function test_returns_expected_connector_keys(): void {
3535
$connectors = wp_get_connectors();
3636

3737
$this->assertArrayHasKey( 'google', $connectors );
@@ -44,7 +44,7 @@ public function test_returns_expected_connector_keys() {
4444
/**
4545
* @ticket 64730
4646
*/
47-
public function test_each_connector_has_required_fields() {
47+
public function test_each_connector_has_required_fields(): void {
4848
$connectors = wp_get_connectors();
4949

5050
$this->assertNotEmpty( $connectors, 'Connector settings should not be empty.' );
@@ -67,7 +67,7 @@ public function test_each_connector_has_required_fields() {
6767
/**
6868
* @ticket 64730
6969
*/
70-
public function test_api_key_connectors_have_setting_name_and_credentials_url() {
70+
public function test_api_key_connectors_have_setting_name_and_credentials_url(): void {
7171
$connectors = wp_get_connectors();
7272
$api_key_count = 0;
7373

@@ -81,7 +81,7 @@ public function test_api_key_connectors_have_setting_name_and_credentials_url()
8181
$this->assertArrayHasKey( 'setting_name', $connector_data['authentication'], "Connector '{$connector_id}' authentication is missing 'setting_name'." );
8282
$this->assertSame(
8383
"connectors_ai_{$connector_id}_api_key",
84-
$connector_data['authentication']['setting_name'],
84+
$connector_data['authentication']['setting_name'] ?? null,
8585
"Connector '{$connector_id}' setting_name does not match expected format."
8686
);
8787
$this->assertArrayHasKey( 'credentials_url', $connector_data['authentication'], "Connector '{$connector_id}' authentication is missing 'credentials_url'." );
@@ -93,7 +93,7 @@ public function test_api_key_connectors_have_setting_name_and_credentials_url()
9393
/**
9494
* @ticket 64730
9595
*/
96-
public function test_featured_provider_names_match_expected() {
96+
public function test_featured_provider_names_match_expected(): void {
9797
$connectors = wp_get_connectors();
9898

9999
$this->assertSame( 'Google', $connectors['google']['name'] );
@@ -104,15 +104,15 @@ public function test_featured_provider_names_match_expected() {
104104
/**
105105
* @ticket 64730
106106
*/
107-
public function test_includes_registered_provider_from_registry() {
107+
public function test_includes_registered_provider_from_registry(): void {
108108
$connectors = wp_get_connectors();
109109
$mock = $connectors['mock_connectors_test'];
110110

111111
$this->assertSame( 'Mock Connectors Test', $mock['name'] );
112112
$this->assertSame( '', $mock['description'] );
113113
$this->assertSame( 'ai_provider', $mock['type'] );
114114
$this->assertSame( 'api_key', $mock['authentication']['method'] );
115-
$this->assertNull( $mock['authentication']['credentials_url'] );
116-
$this->assertSame( 'connectors_ai_mock_connectors_test_api_key', $mock['authentication']['setting_name'] );
115+
$this->assertNull( $mock['authentication']['credentials_url'] ?? null );
116+
$this->assertSame( 'connectors_ai_mock_connectors_test_api_key', $mock['authentication']['setting_name'] ?? null );
117117
}
118118
}

0 commit comments

Comments
 (0)