diff --git a/phpstan.neon.dist b/phpstan.neon.dist index fa1e3f209c322..49a0412cb6a57 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -57,7 +57,6 @@ includes: - tests/phpstan/baselines/instanceof.alwaysTrue.neon - tests/phpstan/baselines/isset.offset.neon - tests/phpstan/baselines/isset.property.neon - - tests/phpstan/baselines/isset.variable.neon - tests/phpstan/baselines/method.childParameterType.neon - tests/phpstan/baselines/method.nonObject.neon - tests/phpstan/baselines/method.notFound.neon diff --git a/src/wp-admin/includes/class-custom-image-header.php b/src/wp-admin/includes/class-custom-image-header.php index 97a1a16052d12..c1816ffae2d9c 100644 --- a/src/wp-admin/includes/class-custom-image-header.php +++ b/src/wp-admin/includes/class-custom-image-header.php @@ -841,7 +841,7 @@ public function step_2() { $file = get_attached_file( $attachment_id, true ); $url = wp_get_attachment_image_src( $attachment_id, 'full' ); $url = $url[0]; - } elseif ( isset( $_POST ) ) { + } else { $data = $this->step_2_manage_upload(); $attachment_id = $data['attachment_id']; $file = $data['file']; diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index 8c0015020f35d..99b9735011bbc 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -397,9 +397,10 @@ function wp_edit_theme_plugin_file( $args ) { $file = $args['file']; $content = $args['newcontent']; - $plugin = null; - $theme = null; - $real_file = null; + $plugin = null; + $stylesheet = null; + $theme = null; + $real_file = null; if ( ! empty( $args['plugin'] ) ) { $plugin = $args['plugin']; @@ -560,7 +561,7 @@ function wp_edit_theme_plugin_file( $args ) { // Attempt loopback request to editor to see if user just whitescreened themselves. if ( $plugin ) { $url = add_query_arg( compact( 'plugin', 'file' ), admin_url( 'plugin-editor.php' ) ); - } elseif ( isset( $stylesheet ) ) { + } elseif ( $stylesheet ) { $url = add_query_arg( array( 'theme' => $stylesheet, diff --git a/src/wp-admin/includes/media.php b/src/wp-admin/includes/media.php index 6c50a1daba4fd..ce25f0ab26b08 100644 --- a/src/wp-admin/includes/media.php +++ b/src/wp-admin/includes/media.php @@ -1773,7 +1773,7 @@ function get_media_item( $attachment_id, $args = null ) { if ( isset( $_GET['post_id'] ) ) { $calling_post_id = absint( $_GET['post_id'] ); - } elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set. + } elseif ( ! empty( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set. $calling_post_id = $post->post_parent; } diff --git a/src/wp-includes/class-wp-block-parser.php b/src/wp-includes/class-wp-block-parser.php index ea66e3b51d38d..02b40dfdddc78 100644 --- a/src/wp-includes/class-wp-block-parser.php +++ b/src/wp-includes/class-wp-block-parser.php @@ -268,7 +268,7 @@ public function next_token() { $is_closer = isset( $matches['closer'] ) && -1 !== $matches['closer'][1]; $is_void = isset( $matches['void'] ) && -1 !== $matches['void'][1]; $namespace = $matches['namespace']; - $namespace = ( isset( $namespace ) && -1 !== $namespace[1] ) ? $namespace[0] : 'core/'; + $namespace = -1 !== $namespace[1] ? $namespace[0] : 'core/'; $name = $namespace . $matches['name'][0]; $has_attrs = isset( $matches['attrs'] ) && -1 !== $matches['attrs'][1]; diff --git a/src/wp-includes/class-wp-oembed.php b/src/wp-includes/class-wp-oembed.php index 39029bd9a2b8d..b1a23ff66144d 100644 --- a/src/wp-includes/class-wp-oembed.php +++ b/src/wp-includes/class-wp-oembed.php @@ -674,6 +674,7 @@ private function _parse_xml( $response_body ) { return false; } + $loader = null; if ( PHP_VERSION_ID < 80000 ) { /* * This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading @@ -688,7 +689,7 @@ private function _parse_xml( $response_body ) { libxml_use_internal_errors( $errors ); - if ( PHP_VERSION_ID < 80000 && isset( $loader ) ) { + if ( PHP_VERSION_ID < 80000 ) { // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.libxml_disable_entity_loaderDeprecated libxml_disable_entity_loader( $loader ); } diff --git a/src/wp-includes/template.php b/src/wp-includes/template.php index 6ec1934f866ec..d2b74e188c095 100644 --- a/src/wp-includes/template.php +++ b/src/wp-includes/template.php @@ -782,7 +782,9 @@ function locate_template( $template_names, $load = false, $load_once = true, $ar function load_template( $_template_file, $load_once = true, $args = array() ) { global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; - if ( is_array( $wp_query->query_vars ) ) { + /** @var array{ s?: scalar, ... } $query_vars */ + $query_vars = $wp_query->query_vars; + if ( is_array( $query_vars ) ) { /* * This use of extract() cannot be removed. There are many possible ways that * templates could depend on variables that it creates existing, and no way to @@ -792,11 +794,11 @@ function load_template( $_template_file, $load_once = true, $args = array() ) { * function variables cannot be overwritten. */ // phpcs:ignore WordPress.PHP.DontExtract.extract_extract - extract( $wp_query->query_vars, EXTR_SKIP ); + extract( $query_vars, EXTR_SKIP ); } if ( isset( $s ) ) { - $s = esc_attr( $s ); // @phpstan-ignore variable.undefined (It's extracted from query vars.) + $s = esc_attr( (string) $s ); } /** diff --git a/tests/phpstan/baselines/isset.variable.neon b/tests/phpstan/baselines/isset.variable.neon deleted file mode 100644 index f14ef0755fdb9..0000000000000 --- a/tests/phpstan/baselines/isset.variable.neon +++ /dev/null @@ -1,50 +0,0 @@ -# PHPStan baseline for the `isset.variable` errors in WordPress core. -# -# https://phpstan.org/error-identifiers/isset.variable -# -# Each entry is scoped to a single file and carries an exact occurrence count, -# so that a new instance is reported as a new error rather than being absorbed -# silently. Fixing an occurrence therefore means decrementing or removing its -# entry here as part of the same change. -# -# The goal is to empty this file and delete it, along with the `includes` entry -# for it in phpstan.neon.dist. -# -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with -# -# composer phpstan:baselines -- --identifier=isset.variable -# -# which reruns the analysis with this file suppressed so the errors surface again. - -parameters: - ignoreErrors: - - - message: '#^Variable \$_POST in isset\(\) always exists and is not nullable\.$#' - identifier: isset.variable - count: 1 - path: ../../../src/wp-admin/includes/class-custom-image-header.php - - - message: '#^Variable \$stylesheet in isset\(\) always exists and is not nullable\.$#' - identifier: isset.variable - count: 1 - path: ../../../src/wp-admin/includes/file.php - - - message: '#^Variable \$_POST in isset\(\) always exists and is not nullable\.$#' - identifier: isset.variable - count: 1 - path: ../../../src/wp-admin/includes/media.php - - - message: '#^Variable \$namespace in isset\(\) always exists and is not nullable\.$#' - identifier: isset.variable - count: 1 - path: ../../../src/wp-includes/class-wp-block-parser.php - - - message: '#^Variable \$loader in isset\(\) always exists and is not nullable\.$#' - identifier: isset.variable - count: 1 - path: ../../../src/wp-includes/class-wp-oembed.php - - - message: '#^Variable \$s in isset\(\) is never defined\.$#' - identifier: isset.variable - count: 1 - path: ../../../src/wp-includes/template.php