From a8370a5b26b359e0741ef2265f371531f58dc41d Mon Sep 17 00:00:00 2001 From: Callum Bridgford-Whittick Date: Thu, 13 Aug 2026 16:58:05 +0100 Subject: [PATCH] REST API: Remove a redundant private property in WP_REST_Template_Autosaves_Controller. `WP_REST_Template_Autosaves_Controller` declared its own private `$parent_post_type` and assigned it in the constructor immediately after calling `parent::__construct()`, which already performs the same assignment. Because both declarations are private, PHP allocates a separate slot for each, and the subclass copy was never read by any method. The sibling `WP_REST_Template_Revisions_Controller`, added in the same changeset, needs its copy: `get_parent()` reads `$this->parent_post_type` from the subclass, where the ancestor's private property is out of scope. No method on the autosaves controller does the same, so the property and its assignment are removed and the surrounding alignment restored. This was the only `property.onlyWritten` occurrence, so the baseline is emptied. The file is removed along with its `includes` entry in `phpstan.neon.dist`. Props CallumBW95. See #65817. --- phpstan.neon.dist | 1 - ...-wp-rest-template-autosaves-controller.php | 13 ++-------- .../baselines/property.onlyWritten.neon | 25 ------------------- 3 files changed, 2 insertions(+), 37 deletions(-) delete mode 100644 tests/phpstan/baselines/property.onlyWritten.neon diff --git a/phpstan.neon.dist b/phpstan.neon.dist index fa1e3f209c322..b9b109b5d08fe 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -76,7 +76,6 @@ includes: - tests/phpstan/baselines/property.defaultValue.neon - tests/phpstan/baselines/property.nonObject.neon - tests/phpstan/baselines/property.notFound.neon - - tests/phpstan/baselines/property.onlyWritten.neon - tests/phpstan/baselines/property.phpDocType.neon - tests/phpstan/baselines/property.private.neon - tests/phpstan/baselines/property.protected.neon diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php index dbdca575089fc..4dd5cb21c0cc5 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php @@ -15,14 +15,6 @@ * @see WP_REST_Autosaves_Controller */ class WP_REST_Template_Autosaves_Controller extends WP_REST_Autosaves_Controller { - /** - * Parent post type. - * - * @since 6.4.0 - * @var string - */ - private $parent_post_type; - /** * Parent post controller. * @@ -56,9 +48,8 @@ class WP_REST_Template_Autosaves_Controller extends WP_REST_Autosaves_Controller */ public function __construct( $parent_post_type ) { parent::__construct( $parent_post_type ); - $this->parent_post_type = $parent_post_type; - $post_type_object = get_post_type_object( $parent_post_type ); - $parent_controller = $post_type_object->get_rest_controller(); + $post_type_object = get_post_type_object( $parent_post_type ); + $parent_controller = $post_type_object->get_rest_controller(); if ( ! $parent_controller ) { $parent_controller = new WP_REST_Templates_Controller( $parent_post_type ); diff --git a/tests/phpstan/baselines/property.onlyWritten.neon b/tests/phpstan/baselines/property.onlyWritten.neon deleted file mode 100644 index f4b740e1bdf02..0000000000000 --- a/tests/phpstan/baselines/property.onlyWritten.neon +++ /dev/null @@ -1,25 +0,0 @@ -# PHPStan baseline for the `property.onlyWritten` errors in WordPress core. -# -# https://phpstan.org/error-identifiers/property.onlyWritten -# -# 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=property.onlyWritten -# -# which reruns the analysis with this file suppressed so the errors surface again. - -parameters: - ignoreErrors: - - - message: '#^Property WP_REST_Template_Autosaves_Controller\:\:\$parent_post_type is never read, only written\.$#' - identifier: property.onlyWritten - count: 1 - path: ../../../src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php