Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review WPCOM suggestions for PHP 8.1 #7532

Open
renatho opened this issue Mar 8, 2024 · 0 comments
Open

Review WPCOM suggestions for PHP 8.1 #7532

renatho opened this issue Mar 8, 2024 · 0 comments
Labels
[Pri] Normal Can wait for the next release [Status] Triaged Issue has been triaged [Type] Bug

Comments

@renatho
Copy link
Contributor

renatho commented Mar 8, 2024

Review the following appointments (I think we could skip the vendor ones, but I kept here just for thoughts):

9) wp-content/a8c-plugins/sensei/includes/internal/emails/views/html-settings.php:42

    ---------- begin diff ----------
@@ @@
 					<?php call_user_func( $field['callback'], $field['args'] ); ?>
 				</td>
 			</tr>
-		<?php } ?>
+<?php } ?>
 		<tr><td></td></tr>
 		<tr>
 			<th scope="row">
    ----------- end diff -----------

10) wp-content/a8c-plugins/sensei/includes/mailpoet/class-sync-job.php:48

    ---------- begin diff ----------
@@ @@
 		$sensei_lists   = $sensei_mp_instance->get_sensei_lists();
 		$current_batch  = array_slice( $sensei_lists, $offset, $this->get_batch_size() );

-		$remaining = count( $sensei_lists ) - $offset;
+		$remaining = (is_countable($sensei_lists) ? count( $sensei_lists ) : 0) - $offset;

 		foreach ( $current_batch as $list ) {
 			$list_name = Repository::get_list_name( $list['name'], $list['post_type'] );
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)


11) wp-content/a8c-plugins/sensei/templates/course-results/lessons.php:160

    ---------- begin diff ----------
@@ @@

 			<?php endforeach; // lessons ?>

-		<?php endif; // lessons count > 0 ?>
+<?php endif; // lessons count > 0 ?>


 		<h2 class="total-grade">
    ----------- end diff -----------

12) wp-content/a8c-plugins/sensei/third-party/sabberworm/php-css-parser/src/Value/CalcFunction.php:25

    ---------- begin diff ----------
@@ @@
      */
     public static function parse(ParserState $oParserState, $bIgnoreCase = \false)
     {
-        $aOperators = ['+', '-', '*', '/'];
+        $oVal = null;
+								$aOperators = ['+', '-', '*', '/'];
         $sFunction = $oParserState->parseIdentifier();
         if ($oParserState->peek() != '(') {
             // Found ; or end of line before an opening bracket
    ----------- end diff -----------

Applied rules:
 * CommonNotEqualRector (https://stackoverflow.com/a/4294663/1348344)
 * AddDefaultValueForUndefinedVariableRector (https://github.com/vimeo/psalm/blob/29b70442b11e3e66113935a2ee22e165a70c74a4/docs/fixing_code.md#possiblyundefinedvariable)


13) wp-content/a8c-plugins/sensei/third-party/sabberworm/php-css-parser/src/RuleSet/RuleSet.php:100

    ---------- begin diff ----------
@@ @@
         if (!isset($this->aRules[$sRule])) {
             $this->aRules[$sRule] = [];
         }
-        $iPosition = \count($this->aRules[$sRule]);
+        $iPosition = is_countable($this->aRules[$sRule]) ? \count($this->aRules[$sRule]) : 0;
         if ($oSibling !== null) {
             $iSiblingPos = \array_search($oSibling, $this->aRules[$sRule], \true);
             if ($iSiblingPos !== \false) {
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)


14) wp-content/a8c-plugins/sensei/third-party/sabberworm/php-css-parser/src/RuleSet/DeclarationBlock.php:471

    ---------- begin diff ----------
@@ @@
      */
     public function createShorthandProperties(array $aProperties, $sShorthand)
     {
-        $aRules = $this->getRulesAssoc();
+        $oRule = null;
+								$aRules = $this->getRulesAssoc();
         $aNewValues = [];
         foreach ($aProperties as $sProperty) {
             if (!isset($aRules[$sProperty])) {
    ----------- end diff -----------

Applied rules:
 * CommonNotEqualRector (https://stackoverflow.com/a/4294663/1348344)
 * AddDefaultValueForUndefinedVariableRector (https://github.com/vimeo/psalm/blob/29b70442b11e3e66113935a2ee22e165a70c74a4/docs/fixing_code.md#possiblyundefinedvariable)


15) wp-content/a8c-plugins/sensei/includes/template-functions.php:767

    ---------- begin diff ----------
@@ @@
 		?>
 	</div>

-	<?php
+<?php
 }

 /**
    ----------- end diff -----------

Applied rules:
 * CommonNotEqualRector (https://stackoverflow.com/a/4294663/1348344)


16) wp-content/a8c-plugins/sensei/vendor/woocommerce/action-scheduler/lib/cron-expression/CronExpression.php:94

    ---------- begin diff ----------
@@ @@
     public function setExpression($value)
     {
         $this->cronParts = preg_split('/\s/', $value, -1, PREG_SPLIT_NO_EMPTY);
-        if (count($this->cronParts) < 5) {
+        if ((is_countable($this->cronParts) ? count($this->cronParts) : 0) < 5) {
             throw new InvalidArgumentException(
                 $value . ' is not a valid CRON expression'
             );
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)


17) wp-content/a8c-plugins/sensei/vendor/woocommerce/action-scheduler/classes/abstracts/ActionScheduler_Abstract_ListTable.php:582

    ---------- begin diff ----------
@@ @@
 				)
 			);
 			$span_class  = ! empty( $action['class'] ) ? $action['class'] : $action_key;
-			$separator   = ( $action_count < count( $this->row_actions[ $column_name ] ) ) ? ' | ' : '';
+			$separator   = ( $action_count < (is_countable($this->row_actions[ $column_name ]) ? count( $this->row_actions[ $column_name ] ) : 0) ) ? ' | ' : '';

 			$actions .= sprintf( '<span class="%s">', esc_attr( $span_class ) );
 			$actions .= sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', esc_url( $action_link ), esc_attr( $action['desc'] ), esc_html( $action['name'] ) );
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)


18) wp-content/a8c-plugins/sensei/vendor/woocommerce/action-scheduler/classes/WP_CLI/Migration_Command.php:141

    ---------- begin diff ----------
@@ @@
 			WP_CLI::debug( 'Beginning migration of batch: ' . print_r( $batch, true ) );
 		}, 10, 1 );
 		add_action( 'action_scheduler/migration_batch_complete', function ( $batch ) {
-			WP_CLI::log( sprintf( 'Completed migration of %d actions', count( $batch ) ) );
+			WP_CLI::log( sprintf( 'Completed migration of %d actions', is_countable($batch) ? count( $batch ) : 0 ) );
 		}, 10, 1 );
 	}
 }
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)


19) wp-content/a8c-plugins/sensei/vendor/woocommerce/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_QueueRunner.php:66

    ---------- begin diff ----------
@@ @@
 		$this->monitor->attach( $this->claim );
 		$this->actions = $this->claim->get_actions();

-		return count( $this->actions );
+		return is_countable($this->actions) ? count( $this->actions ) : 0;
 	}

 	/**
@@ @@
 	 * @author Jeremy Pry
 	 */
 	protected function setup_progress_bar() {
-		$count              = count( $this->actions );
+		$count              = count( (array) $this->actions );
 		$this->progress_bar = new ProgressBar(
 			/* translators: %d: amount of actions */
 			sprintf( _n( 'Running %d action', 'Running %d actions', $count, 'action-scheduler' ), $count ),
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)


20) wp-content/a8c-plugins/sensei/includes/class-sensei-usage-tracking.php:254

    ---------- begin diff ----------
@@ @@
 			'version'       => Sensei()->version,
 			'theme'         => $theme['Name'],
 			'theme_version' => $theme['Version'],
-			'templates'     => count( $template_overrides ),
+			'templates'     => is_countable($template_overrides) ? count( $template_overrides ) : 0,
 			'mismatch'      => 0,
 		];
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)


21) wp-content/a8c-plugins/sensei/vendor/woocommerce/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php:371

    ---------- begin diff ----------
@@ @@
 		if ( $query['status'] ) {
 			$post_statuses = array_map( array( $this, 'get_post_status_by_action_status' ), (array) $query['status'] );
 			$placeholders  = array_fill( 0, count( $post_statuses ), '%s' );
-			$sql          .= ' AND p.post_status IN (' . join( ', ', $placeholders ) . ')';
+			$sql          .= ' AND p.post_status IN (' . implode( ', ', $placeholders ) . ')';
 			$sql_params    = array_merge( $sql_params, array_values( $post_statuses ) );
 		}

@@ @@

 		if ( ! empty( $hooks ) ) {
 			$placeholders = array_fill( 0, count( $hooks ), '%s' );
-			$where       .= ' AND post_title IN (' . join( ', ', $placeholders ) . ')';
+			$where       .= ' AND post_title IN (' . implode( ', ', $placeholders ) . ')';
 			$params       = array_merge( $params, array_values( $hooks ) );
 		}

@@ @@
 		 * If we're not limiting by IDs, then include the post_date_gmt clause.
 		 */
 		if ( $limit_ids ) {
-			$where .= ' AND ID IN (' . join( ',', $ids ) . ')';
+			$where .= ' AND ID IN (' . implode( ',', $ids ) . ')';
 		} else {
 			$where   .= ' AND post_date_gmt <= %s';
 			$params[] = $date->format( 'Y-m-d H:i:s' );
    ----------- end diff -----------

Applied rules:
 * RenameFunctionRector


22) wp-content/a8c-plugins/sensei/vendor/woocommerce/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php:495

    ---------- begin diff ----------
@@ @@
 		if ( $query['status'] ) {
 			$statuses     = (array) $query['status'];
 			$placeholders = array_fill( 0, count( $statuses ), '%s' );
-			$sql         .= ' AND a.status IN (' . join( ', ', $placeholders ) . ')';
+			$sql         .= ' AND a.status IN (' . implode( ', ', $placeholders ) . ')';
 			$sql_params   = array_merge( $sql_params, array_values( $statuses ) );
 		}

@@ @@
 				break;
 			}

-			$format     = array_fill( 0, count( $action_ids ), '%d' );
+			$format     = array_fill( 0, is_countable($action_ids) ? count( $action_ids ) : 0, '%d' );
 			$query_in   = '(' . implode( ',', $format ) . ')';
 			$parameters = $action_ids;
 			array_unshift( $parameters, self::STATUS_CANCELED );
@@ @@
 		$params[] = self::STATUS_PENDING;

 		if ( ! empty( $hooks ) ) {
-			$placeholders = array_fill( 0, count( $hooks ), '%s' );
-			$where        .= ' AND hook IN (' . join( ', ', $placeholders ) . ')';
+			$placeholders = array_fill( 0, is_countable($hooks) ? count( $hooks ) : 0, '%s' );
+			$where        .= ' AND hook IN (' . implode( ', ', $placeholders ) . ')';
 			$params       = array_merge( $params, array_values( $hooks ) );
 		}
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)
 * RenameFunctionRector


23) wp-content/a8c-plugins/sensei/includes/class-sensei-modules.php:2416

    ---------- begin diff ----------
@@ @@
 				</div>
 			<?php endif; ?>
 		</div>
-		<?php
+<?php
 	}
    ----------- end diff -----------

Applied rules:
 * CommonNotEqualRector (https://stackoverflow.com/a/4294663/1348344)


24) wp-content/a8c-plugins/sensei/includes/class-sensei-learner.php:284

    ---------- begin diff ----------
@@ @@
 						]
 					);

-					$format_comment_ids = implode( ', ', array_fill( 0, count( $comment_ids ), '%s' ) );
+					$format_comment_ids = implode( ', ', array_fill( 0, is_countable($comment_ids) ? count( $comment_ids ) : 0, '%s' ) );

 					$sql = "DELETE FROM $wpdb->comments WHERE comment_ID IN ( $format_comment_ids )";
 					$wpdb->query( call_user_func_array( [ $wpdb, 'prepare' ], array_merge( [ $sql ], $comment_ids ) ) );
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)


25) wp-content/a8c-plugins/sensei/includes/class-sensei-frontend.php:1122

    ---------- begin diff ----------
@@ @@

 					</form>
 				</div>
-				<?php
+<?php
 			}
 			?>
 			</div>
 		</div>

-		<?php
+<?php
 	}

 	public function sensei_lesson_meta( $post_id = 0 ) {
    ----------- end diff -----------

Applied rules:
 * CommonNotEqualRector (https://stackoverflow.com/a/4294663/1348344)
@renatho renatho added [Type] Bug [Pri] Normal Can wait for the next release [Status] Triaged Issue has been triaged labels Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Pri] Normal Can wait for the next release [Status] Triaged Issue has been triaged [Type] Bug
Projects
None yet
Development

No branches or pull requests

1 participant