Fix PHPStan errors after updating WordPress Stubs

[MAILPOET-6356]
This commit is contained in:
Rostislav Wolny
2024-12-17 10:32:46 +01:00
committed by Rostislav Wolný
parent 82172969d1
commit 91f90a03d1
8 changed files with 36 additions and 32 deletions

View File

@@ -145,6 +145,7 @@ class WordPress {
}
/**
* @param 'names'|'objects' $output
* @return string[]|\WP_Post_Type[]
*/
public function getPostTypes(array $args = [], string $output = 'names', string $operator = 'and'): array {
@@ -156,6 +157,7 @@ class WordPress {
}
/**
* @param 'names'|'objects' $output
* @param 'and'|'or' $operator
* @return string[]|\WP_Taxonomy[]
*/

View File

@@ -47,7 +47,7 @@ class AutomationFlowEndpoint extends Endpoint {
}
public function handle(Request $request): Response {
$id = absint($request->getParam('id'));
$id = absint(is_numeric($request->getParam('id')) ? $request->getParam('id') : 0);
$automation = $this->automationStorage->getAutomation($id);
if (!$automation) {
throw Exceptions::automationNotFound($id);

View File

@@ -28,7 +28,7 @@ class OverviewEndpoint extends Endpoint {
}
public function handle(Request $request): Response {
$id = absint($request->getParam('id'));
$id = absint(is_numeric($request->getParam('id')) ? $request->getParam('id') : 0);
$automation = $this->automationStorage->getAutomation($id);
if (!$automation) {
throw Exceptions::automationNotFound($id);

View File

@@ -44,7 +44,7 @@ class ContextFactory {
*/
private function getPostTypes(): array {
/** @var \WP_Post_Type[] $postTypes */
$postTypes = $this->wp->getPostTypes([], 'object');
$postTypes = $this->wp->getPostTypes([], 'objects');
return array_values(array_map(function(\WP_Post_Type $type): array {
$supports = ['comments' => false];
@@ -74,7 +74,7 @@ class ContextFactory {
private function getTaxonomies(): array {
/** @var \WP_Taxonomy[] $taxonomies */
$taxonomies = array_filter(
$this->wp->getTaxonomies([], 'object'),
$this->wp->getTaxonomies([], 'objects'),
function($object): bool {
return $object instanceof \WP_Taxonomy;
}

View File

@@ -111,8 +111,8 @@ class Widget extends \WP_Widget {
*/
public function update($newInstance, $oldInstance) {
$instance = $oldInstance;
$instance['title'] = strip_tags($newInstance['title']);
$instance['form'] = (int)$newInstance['form'];
$instance['title'] = strip_tags(is_string($newInstance['title']) ? $newInstance['title'] : '');
$instance['form'] = is_numeric($newInstance['form']) ? (int)$newInstance['form'] : null;
return $instance;
}
@@ -168,6 +168,8 @@ class Widget extends \WP_Widget {
}
/**
* @phpstan-ignore-next-line $args are not passed to parent and our rendering is custom so it is ok that $args doesn't match parent's $arg shape.
* @param array{form?: int|string, form_type?: string, before_widget?: string, after_widget?: string, before_title?: string, after_title?: string } $args Widget arguments.
* Output the widget itself.
*/
public function widget($args, $instance = null) {

View File

@@ -691,7 +691,7 @@ class Functions {
}
/**
* @param 'hot_categories'|'hot_tags'|'plugin_information'|'query_plugins' $action
* @param 'hot_tags'|'plugin_information'|'query_plugins' $action
* @param array|object $args
* @return object|array|WP_Error
*/

View File

@@ -69,7 +69,7 @@ parameters:
-
# WP annotates parameter as callable, but passes empty string as a default.
message: '/function add_(sub)?menu_page expects callable\(\): mixed, ''''\|\(callable\(\): mixed\) given/'
count: 2
count: 1
path: ../../lib/WP/Functions.php
-
# We don't allow seting properties for read-only entity WpPostEntity

View File

@@ -29,14 +29,14 @@ class DefaultsExtension extends Extension {
}
private function setupWordPress() {
update_option('siteurl', 'http://test.local', 'yes');
update_option('home', 'http://test.local', 'yes');
update_option('blogname', 'MP Dev', 'yes');
update_option('admin_email', 'test@example.com', 'yes');
update_option('gmt_offset', '0', 'yes');
update_option('users_can_register', '1', 'yes');
update_option('siteurl', 'http://test.local', true);
update_option('home', 'http://test.local', true);
update_option('blogname', 'MP Dev', true);
update_option('admin_email', 'test@example.com', true);
update_option('gmt_offset', '0', true);
update_option('users_can_register', '1', true);
update_site_option('registration', 'user');
update_option('permalink_structure', '/%year%/%monthnum%/%day%/%postname%/', 'yes');
update_option('permalink_structure', '/%year%/%monthnum%/%day%/%postname%/', true);
// posts & pages
$this->createPost('post', 'hello-world', 'Hello world!', 'Hello from WordPress.');
@@ -58,17 +58,17 @@ class DefaultsExtension extends Extension {
private function setupWooCommerce() {
global $wpdb;
// address
update_option('woocommerce_store_address', 'Address', 'yes');
update_option('woocommerce_store_address_2', '', 'yes');
update_option('woocommerce_store_city', 'Paris', 'yes');
update_option('woocommerce_default_country', 'FR:*', 'yes');
update_option('woocommerce_store_postcode', '75000', 'yes');
update_option('woocommerce_store_address', 'Address', true);
update_option('woocommerce_store_address_2', '', true);
update_option('woocommerce_store_city', 'Paris', true);
update_option('woocommerce_default_country', 'FR:*', true);
update_option('woocommerce_store_postcode', '75000', true);
// currency
update_option('woocommerce_currency', 'EUR', 'yes');
update_option('woocommerce_currency_pos', 'right', 'yes');
update_option('woocommerce_price_thousand_sep', ' ', 'yes');
update_option('woocommerce_price_decimal_sep', ',', 'yes');
update_option('woocommerce_currency', 'EUR', true);
update_option('woocommerce_currency_pos', 'right', true);
update_option('woocommerce_price_thousand_sep', ' ', true);
update_option('woocommerce_price_decimal_sep', ',', true);
// pages
// block-based pages are created automatically by WooCommerce
@@ -77,16 +77,16 @@ class DefaultsExtension extends Extension {
$checkoutPageId = $this->createPage('shortcode-checkout', 'Shortcode Checkout', '[woocommerce_checkout]');
$myAccountPageId = $this->createPage('shortcode-my-account', 'Shortcode My account', '[woocommerce_my_account]');
update_option('woocommerce_shop_page_id', $shopPageId, 'yes');
update_option('woocommerce_cart_page_id', $cartPageId, 'yes');
update_option('woocommerce_checkout_page_id', $checkoutPageId, 'yes');
update_option('woocommerce_myaccount_page_id', $myAccountPageId, 'yes');
update_option('woocommerce_shop_page_id', $shopPageId, true);
update_option('woocommerce_cart_page_id', $cartPageId, true);
update_option('woocommerce_checkout_page_id', $checkoutPageId, true);
update_option('woocommerce_myaccount_page_id', $myAccountPageId, true);
// other
update_option('woocommerce_bacs_settings', ['enabled' => 'yes'], 'yes');
update_option('woocommerce_cod_settings', ['enabled' => 'yes', 'enable_for_virtual' => 'yes'], 'yes');
update_option('woocommerce_enable_signup_and_login_from_checkout', 'yes', 'no');
update_option('woocommerce_enable_myaccount_registration', 'yes', 'no');
update_option('woocommerce_bacs_settings', ['enabled' => 'yes'], true);
update_option('woocommerce_cod_settings', ['enabled' => 'yes', 'enable_for_virtual' => 'yes'], true);
update_option('woocommerce_enable_signup_and_login_from_checkout', 'yes', false);
update_option('woocommerce_enable_myaccount_registration', 'yes', false);
// don't send customer/order emails, the mail() function is not configured and outputs warning,
// these lines can be removed when https://github.com/lucatume/wp-browser/issues/316 is solved