Skip to content

Commit

Permalink
PHPStan: re-enable bleedingEdge option
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Nov 27, 2023
1 parent 56bd269 commit 9ebfe6a
Show file tree
Hide file tree
Showing 26 changed files with 68 additions and 211 deletions.
15 changes: 1 addition & 14 deletions includes/Infrastructure/Injector/SimpleInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
* @template T
*/
final class SimpleInjector implements Injector {

/**
* Special-case index key for handling globally defined named arguments.
*/
public const GLOBAL_ARGUMENTS = '__global__';

/**
* Mappings.
*
Expand Down Expand Up @@ -70,9 +64,7 @@ final class SimpleInjector implements Injector {
*
* @var array<string, array<mixed>>
*/
private array $argument_mappings = [
self::GLOBAL_ARGUMENTS => [],
];
private array $argument_mappings = [];

/**
* Instantiator.
Expand Down Expand Up @@ -429,11 +421,6 @@ private function resolve_argument_by_name(
return $value;
}

// No argument found for the class, check if we have a global value.
if ( \array_key_exists( $name, $this->argument_mappings[ self::GLOBAL_ARGUMENTS ] ) ) {
return $this->argument_mappings[ self::GLOBAL_ARGUMENTS ][ $name ];
}

// No provided argument found, check if it has a default value.
try {
if ( $parameter->isDefaultValueAvailable() ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/Integrations/AMP.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static function get_requirements(): array {
* @param array|mixed $options Options.
* @return array|mixed Filtered options.
*
* @phpstan-param AMPOptions $options
* @phpstan-param AMPOptions|mixed $options
*
* @template T
*
Expand Down
2 changes: 1 addition & 1 deletion includes/Integrations/Jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function filter_ajax_query_attachments_args( $args ) {
* @param WP_Post $attachment Attachment object.
* @return array|mixed
*
* @phpstan-param AttachmentData $data
* @phpstan-param AttachmentData|mixed $data
* @phpstan-return AttachmentData|mixed
*
* @template T
Expand Down
2 changes: 1 addition & 1 deletion includes/Integrations/Site_Kit.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function register(): void {
* @param array|mixed $gtag_opt Array of gtag configuration options.
* @return array|mixed Modified configuration options.
*
* @phpstan-param GtagOpt $gtag_opt
* @phpstan-param GtagOpt|mixed $gtag_opt
*/
public function filter_site_kit_gtag_opt( $gtag_opt ) {
if (
Expand Down
2 changes: 1 addition & 1 deletion includes/KSES.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static function get_requirements(): array {
* originally passed to wp_insert_post().
* @return array<string,mixed>|mixed Filtered post data.
*
* @phpstan-param PostData $data
* @phpstan-param PostData|mixed $data
* @phpstan-param PostData $unsanitized_postarr
*
* @template T
Expand Down
2 changes: 1 addition & 1 deletion includes/Media/Media_Source_Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function rest_api_init(): void {
*
* @since 1.0.0
*
* @param array|mixed $response Array of prepared attachment data.
* @param array<string, mixed>|mixed $response Array of prepared attachment data.
* @return array|mixed $response Filtered attachment data.
*
* @template T
Expand Down
7 changes: 2 additions & 5 deletions includes/REST_API/Embed_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ public function get_proxy_item( $request ) {
* @param array<string, mixed>|false $embed Embed value, default to false is not set.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response|WP_Error Response object.
*
* @phpstan-param WP_REST_Request<array{context: string}> $request
*/
public function prepare_item_for_response( $embed, $request ) {
$fields = $this->get_fields_for_response( $request );
Expand All @@ -267,11 +269,6 @@ public function prepare_item_for_response( $embed, $request ) {
}
}

/**
* Request context.
*
* @var string $context
*/
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
Expand Down
36 changes: 14 additions & 22 deletions includes/REST_API/Font_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public function register_routes(): void {
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*
* @phpstan-param WP_REST_Request<array{search?: string, service?: string, include?: string[]}> $request
*/
public function get_items( $request ) {
/**
Expand All @@ -145,13 +147,7 @@ public function get_items( $request ) {

// For custom fonts the searching will be done in WP_Query already.
if ( isset( $registered['search'], $request['search'] ) && ! empty( $request['search'] ) ) {
/**
* Requested URL.
*
* @var string $search
*/
$search = $request['search'];
$fonts = array_values(
$fonts = array_values(
array_filter(
$fonts,
/**
Expand All @@ -160,7 +156,7 @@ public function get_items( $request ) {
* @param array{family: string} $font
* @return bool
*/
static fn( array $font ) => false !== stripos( $font['family'], $search )
static fn( array $font ) => false !== stripos( $font['family'], $request['search'] )
)
);
}
Expand All @@ -172,13 +168,7 @@ public function get_items( $request ) {

// Filter before doing any sorting.
if ( isset( $registered['include'], $request['include'] ) && ! empty( $request['include'] ) ) {
/**
* Include list.
*
* @var array{string} $include_list
*/
$include_list = $request['include'];
$include_list = array_map( 'strtolower', $include_list );
$include_list = array_map( 'strtolower', $request['include'] );

$fonts = array_values(
array_filter(
Expand All @@ -202,8 +192,8 @@ public function get_items( $request ) {
/**
* Font A and Font B.
*
* @param Font $a
* @param Font $b
* @phpstan-param Font $a
* @phpstan-param Font $b
* @return int
*/
static fn( array $a, array $b ): int => strnatcasecmp( $a['family'], $b['family'] )
Expand Down Expand Up @@ -263,6 +253,8 @@ public function delete_item( $request ) {
* @param WP_Post $item Post object.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response Response object.
*
* @phpstan-param WP_REST_Request<array{context: string}> $request
*/
public function prepare_item_for_response( $item, $request ): WP_REST_Response {
// Restores the more descriptive, specific name for use within this method.
Expand Down Expand Up @@ -302,11 +294,6 @@ public function prepare_item_for_response( $item, $request ): WP_REST_Response {
}
}

/**
* Request context.
*
* @var string $context
*/
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
Expand Down Expand Up @@ -687,6 +674,11 @@ protected function prepare_item_for_database( $request ) {
* @return bool Whether a font with this exact name already exists.
*/
private function font_exists( string $font_family ): bool {
/**
* A custom request to perform the lookup.
*
* @phpstan-var WP_REST_Request<array{search?: string, service?: string, include?: array<string>}> $request
*/
$request = new WP_REST_Request(
WP_REST_Server::READABLE,
$this->namespace .
Expand Down
8 changes: 2 additions & 6 deletions includes/REST_API/Hotlinking_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ public function proxy_url( WP_REST_Request $request ) {
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response|WP_Error Response object.
*
* @phpstan-param LinkData $link
* @phpstan-param LinkData $link
* @phpstan-param WP_REST_Request<array{context: string}> $request
*/
public function prepare_item_for_response( $link, $request ) {
$fields = $this->get_fields_for_response( $request );
Expand All @@ -430,11 +431,6 @@ public function prepare_item_for_response( $link, $request ) {
return $error;
}

/**
* Request context.
*
* @var string $context
*/
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
Expand Down
12 changes: 5 additions & 7 deletions includes/REST_API/Link_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,12 @@ public function parse_link( $request ) {
*
* @since 1.10.0
*
* @param array{title: string, image: string, description: string} $link Link value, default to false is not set.
* @param WP_REST_Request $request Request object.
* @param array $link Link value, default to false is not set.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response|WP_Error Response object.
*
* @phpstan-param array{title: string, image: string, description: string} $link
* @phpstan-param WP_REST_Request<array{context: string}> $request
*/
public function prepare_item_for_response( $link, $request ) {
$fields = $this->get_fields_for_response( $request );
Expand All @@ -371,11 +374,6 @@ public function prepare_item_for_response( $link, $request ) {
}
}

/**
* Request context.
*
* @var string $context
*/
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
Expand Down
51 changes: 8 additions & 43 deletions includes/REST_API/Products_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ public function get_items_permissions_check( $request ) {
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*
* @phpstan-param WP_REST_Request<array{context: string, search?: string, orderby?: string, page?: int, per_page?: int, order?: string, _web_stories_envelope?: bool, _embed?: string|string[]}> $request
*/
public function get_items( $request ) {
/**
Expand All @@ -187,40 +189,11 @@ public function get_items( $request ) {
return new WP_Error( 'rest_shopping_provider_not_found', __( 'Unable to find shopping integration.', 'web-stories' ), [ 'status' => 400 ] );
}

/**
* Request context.
*
* @var string $search_term
*/
$search_term = ! empty( $request['search'] ) ? $request['search'] : '';

/**
* Request context.
*
* @var string $orderby
*/
$orderby = ! empty( $request['orderby'] ) ? $request['orderby'] : 'date';

/**
* Request context.
*
* @var int $page
*/
$page = ! empty( $request['page'] ) ? $request['page'] : 1;

/**
* Request context.
*
* @var int $per_page
*/
$per_page = ! empty( $request['per_page'] ) ? $request['per_page'] : 100;

/**
* Request context.
*
* @var string $order
*/
$order = ! empty( $request['order'] ) ? $request['order'] : 'desc';
$orderby = ! empty( $request['orderby'] ) ? $request['orderby'] : 'date';
$page = ! empty( $request['page'] ) ? $request['page'] : 1;
$per_page = ! empty( $request['per_page'] ) ? $request['per_page'] : 100;
$order = ! empty( $request['order'] ) ? $request['order'] : 'desc';

$query_result = $query->get_search( $search_term, $page, $per_page, $orderby, $order );
if ( is_wp_error( $query_result ) ) {
Expand All @@ -243,11 +216,6 @@ public function get_items( $request ) {
$response->header( 'X-WP-HasNextPage', $query_result['has_next_page'] ? 'true' : 'false' );

if ( $request['_web_stories_envelope'] ) {
/**
* Embed directive.
*
* @var string|string[] $embed
*/
$embed = $request['_embed'] ?? false;
$embed = $embed ? rest_parse_embed_param( $embed ) : false;
$response = rest_get_server()->envelope_response( $response, $embed );
Expand All @@ -266,6 +234,8 @@ public function get_items( $request ) {
* @param Product $item Project object.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response Response object.
*
* @phpstan-param WP_REST_Request<array{context: string}> $request
*/
public function prepare_item_for_response( $item, $request ): WP_REST_Response { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
$product = $item;
Expand Down Expand Up @@ -336,11 +306,6 @@ public function prepare_item_for_response( $item, $request ): WP_REST_Response {
}
}

/**
* Request context.
*
* @var string $context
*/
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
Expand Down
7 changes: 2 additions & 5 deletions includes/REST_API/Status_Check_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public function status_check( $request ) {
* @param array{success: bool} $item Status array.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response|WP_Error Response object.
*
* @phpstan-param WP_REST_Request<array{context: string}> $request
*/
public function prepare_item_for_response( $item, $request ) {
$fields = $this->get_fields_for_response( $request );
Expand All @@ -149,11 +151,6 @@ public function prepare_item_for_response( $item, $request ) {
$data['success'] = rest_sanitize_value_from_schema( $item['success'], $schema['properties']['success'] );
}

/**
* Request context.
*
* @var string $context
*/
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
Expand Down
6 changes: 1 addition & 5 deletions includes/REST_API/Stories_Autosaves_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public function register_routes(): void {
* @param WP_Post $post Post object.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response Response object.
* @phpstan-param WP_REST_Request<array{context: string}> $request
*/
public function prepare_item_for_response( $post, $request ): WP_REST_Response {
$response = parent::prepare_item_for_response( $post, $request );
Expand All @@ -186,11 +187,6 @@ public function prepare_item_for_response( $post, $request ): WP_REST_Response {
$data['story_data'] = rest_sanitize_value_from_schema( $post_story_data, $schema['properties']['story_data'] );
}

/**
* Request context.
*
* @var string $context
*/
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->filter_response_by_context( $data, $context );
$links = $response->get_links();
Expand Down
Loading

0 comments on commit 9ebfe6a

Please sign in to comment.