Skip to content

Commit 218f8c5

Browse files
gziolowestonruter
andcommitted
Apply suggestions from code review
Co-authored-by: Weston Ruter <westonruter@gmail.com>
1 parent 3445c0c commit 218f8c5

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/wp-includes/class-wp-connector-registry.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*
1515
* @since 7.0.0
1616
* @access private
17+
*
18+
* @phpstan-type Connector array{ name: string, description: string, type: string, authentication: array{ method: string, credentials_url?: string|null }, plugin?: array{ slug: string } }
1719
*/
1820
final class WP_Connector_Registry {
1921
/**
@@ -22,7 +24,7 @@ final class WP_Connector_Registry {
2224
* @since 7.0.0
2325
* @var self|null
2426
*/
25-
private static $instance = null;
27+
private static ?WP_Connector_Registry $instance = null;
2628

2729
/**
2830
* Holds the registered connectors.
@@ -31,9 +33,10 @@ final class WP_Connector_Registry {
3133
* name, description, type, authentication, and optionally plugin.
3234
*
3335
* @since 7.0.0
34-
* @var array[]
36+
* @var array<string, array>
37+
* @phpstan-var array<string, Connector>
3538
*/
36-
private $registered_connectors = array();
39+
private array $registered_connectors = array();
3740

3841
/**
3942
* Registers a new connector.
@@ -63,6 +66,9 @@ final class WP_Connector_Registry {
6366
* }
6467
* }
6568
* @return array|null The registered connector data on success, null on failure.
69+
*
70+
* @phpstan-param Connector $args
71+
* @phpstan-return Connector|null
6672
*/
6773
public function register( string $id, array $args ): ?array {
6874
if ( ! preg_match( '/^[a-z0-9_]+$/', $id ) ) {
@@ -137,7 +143,7 @@ public function register( string $id, array $args ): ?array {
137143
);
138144

139145
if ( 'api_key' === $args['authentication']['method'] ) {
140-
$connector['authentication']['credentials_url'] = isset( $args['authentication']['credentials_url'] ) ? $args['authentication']['credentials_url'] : null;
146+
$connector['authentication']['credentials_url'] = $args['authentication']['credentials_url'] ?? null;
141147
$connector['authentication']['setting_name'] = "connectors_ai_{$id}_api_key";
142148
}
143149

@@ -160,6 +166,8 @@ public function register( string $id, array $args ): ?array {
160166
*
161167
* @param string $id The connector identifier.
162168
* @return array|null The unregistered connector data on success, null on failure.
169+
*
170+
* @phpstan-return Connector|null
163171
*/
164172
public function unregister( string $id ): ?array {
165173
if ( ! $this->is_registered( $id ) ) {
@@ -187,7 +195,8 @@ public function unregister( string $id ): ?array {
187195
*
188196
* @see wp_get_connectors()
189197
*
190-
* @return array[] The array of registered connectors keyed by connector ID.
198+
* @return array<string, array> The array of registered connectors keyed by connector ID.
199+
* @phpstan-return array<string, Connector>
191200
*/
192201
public function get_all_registered(): array {
193202
return $this->registered_connectors;
@@ -220,6 +229,7 @@ public function is_registered( string $id ): bool {
220229
*
221230
* @param string $id The connector identifier.
222231
* @return array|null The registered connector data, or null if it is not registered.
232+
* @phpstan-return Connector|null
223233
*/
224234
public function get_registered( string $id ): ?array {
225235
if ( ! $this->is_registered( $id ) ) {

0 commit comments

Comments
 (0)