Apply Rector suggestions for PHP 8.1 (#43229)

* Apply Rector suggestions

* Add changelog entry

* Update changelog entry

* Fix PHP Lint errors
This commit is contained in:
Alfredo Sumaran 2024-01-19 04:07:06 -05:00 committed by GitHub
parent 32282a00ce
commit 5b6897e690
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 3 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Apply type checks and instantiate arrays before assignment

View File

@ -180,15 +180,15 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
$limit = apply_filters( 'woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base() ); $limit = apply_filters( 'woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base() );
$total = 0; $total = 0;
if ( ! empty( $items['create'] ) ) { if ( ! empty( $items['create'] ) && is_countable( $items['create'] ) ) {
$total += count( $items['create'] ); $total += count( $items['create'] );
} }
if ( ! empty( $items['update'] ) ) { if ( ! empty( $items['update'] ) && is_countable( $items['update'] ) ) {
$total += count( $items['update'] ); $total += count( $items['update'] );
} }
if ( ! empty( $items['delete'] ) ) { if ( ! empty( $items['delete'] ) && is_countable( $items['delete'] ) ) {
$total += count( $items['delete'] ); $total += count( $items['delete'] );
} }

View File

@ -111,6 +111,7 @@ class WC_REST_Data_Currencies_Controller extends WC_REST_Data_Controller {
*/ */
public function get_items( $request ) { public function get_items( $request ) {
$currencies = get_woocommerce_currencies(); $currencies = get_woocommerce_currencies();
$data = array();
foreach ( array_keys( $currencies ) as $code ) { foreach ( array_keys( $currencies ) as $code ) {
$currency = $this->get_currency( $code, $request ); $currency = $this->get_currency( $code, $request );
$response = $this->prepare_item_for_response( $currency, $request ); $response = $this->prepare_item_for_response( $currency, $request );

View File

@ -735,6 +735,7 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller {
* @return array|WP_Error $prepared_review * @return array|WP_Error $prepared_review
*/ */
protected function prepare_item_for_database( $request ) { protected function prepare_item_for_database( $request ) {
$prepared_review = array();
if ( isset( $request['id'] ) ) { if ( isset( $request['id'] ) ) {
$prepared_review['comment_ID'] = (int) $request['id']; $prepared_review['comment_ID'] = (int) $request['id'];
} }