Skip to content

Fix newly reported PHPStan errors#140

Merged
swissspidy merged 1 commit intomainfrom
fix/phpstan
Apr 30, 2026
Merged

Fix newly reported PHPStan errors#140
swissspidy merged 1 commit intomainfrom
fix/phpstan

Conversation

@swissspidy
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings April 30, 2026 07:12
@swissspidy swissspidy requested a review from a team as a code owner April 30, 2026 07:12
@github-actions github-actions Bot added scope:testing Related to testing status:unconfirmed Issue was could not be confirmed yet labels Apr 30, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request cleans up the src/Export_Command.php file by removing several @phpstan-ignore annotations related to unused methods and argument types. It also adds a specific @param type definition for the check_max_num_posts method. I have no feedback to provide as there were no review comments to evaluate.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes now-unneeded inline PHPStan suppressions in Export_Command and adjusts one validator’s PHPDoc so the codebase’s static analysis passes cleanly again.

Changes:

  • Removed several @phpstan-ignore method.unused suppressions from check_* validators.
  • Removed an inline @phpstan-ignore argument.type suppression around the dynamic validator invocation.
  • Added a concrete @param PHPDoc for check_max_num_posts().
Comments suppressed due to low confidence (12)

src/Export_Command.php:597

  • check_include_once() treats null as valid input but the PHPDoc declares $once as string. Update the @param to string|null to align docs/static analysis with actual accepted values.
	/**
	 * @param string $once
	 */
	private function check_include_once( $once ) {
		if ( null === $once ) {
			return true;
		}

src/Export_Command.php:618

  • check_allow_orphan_terms() allows null but the PHPDoc declares $allow_orphan_terms as string. Update the docblock to include null (and possibly a narrower union like '0'|'1'|null) so the documentation matches behavior and intended inputs.
	/**
	 * @param string $allow_orphan_terms
	 */
	private function check_allow_orphan_terms( $allow_orphan_terms ) {
		if ( null === $allow_orphan_terms ) {
			return true;
		}

src/Export_Command.php:313

  • The PHPDoc for $date says string, but the function explicitly allows null (if ( null === $date ) return true;). Update the @param to include null (and keep it aligned with how validate_args() supplies default null values) so static analysis and docs match actual accepted input.
	/**
	 * @param string $date
	 */
	private function check_start_date( $date ) {
		if ( null === $date ) {
			return true;

src/Export_Command.php:330

  • The PHPDoc for $date is string, but this validator handles null as a valid value. Change the @param to include null so the docblock matches runtime behavior and avoids misleading type assumptions in static analysis.
	/**
	 * @param string $date
	 */
	private function check_end_date( $date ) {
		if ( null === $date ) {
			return true;

src/Export_Command.php:375

  • check_post_type__not_in() allows null (return true early), but the @param is string. Adjust the PHPDoc to include null so the declared type matches the implementation and CLI defaults.
	/**
	 * @param string $post_type
	 */
	private function check_post_type__not_in( $post_type ) {
		if ( null === $post_type ) {
			return true;
		}

src/Export_Command.php:421

  • check_start_id() accepts null and then casts the value to (int) when present, but the PHPDoc says string. Consider documenting this as int|string|null (or similar) to reflect the real accepted input types from CLI parsing.
	/**
	 * @param string $start_id
	 */
	private function check_start_id( $start_id ) {
		if ( null === $start_id ) {
			return true;
		}

src/Export_Command.php:491

  • check_category() accepts null and also allows numeric IDs (casting to int), but the PHPDoc is @param string $category. Update the docblock to include int and null so it matches the implementation.
	/**
	 * @param string $category
	 */
	private function check_category( $category ) {
		if ( null === $category ) {
			return true;
		}

src/Export_Command.php:512

  • check_post_status() returns early for null, but the PHPDoc declares $status as string. Update the @param to include null to match how defaults are passed and how the function behaves.
	/**
	 * @param string $status
	 */
	private function check_post_status( $status ) {
		if ( null === $status ) {
			return true;
		}

src/Export_Command.php:586

  • check_max_file_size() documents $size as string, but the CLI default is an int (15) and the writer args PHPDoc expects an int. Consider updating the @param to int|string and casting $size to an int (or otherwise normalizing) before assigning to $this->max_file_size to keep types consistent end-to-end.
	/**
	 * @param string $size
	 */
	private function check_max_file_size( $size ) {
		if ( ! is_numeric( $size ) ) {
			WP_CLI::warning( 'max_file_size should be numeric.' );
			return false;
		}

		$this->max_file_size = $size;

src/Export_Command.php:347

  • check_post_type() treats null as a valid input, but the @param is documented as string. Update the docblock to string|null (or a more precise union) to reflect actual accepted values from parsed CLI args.
	/**
	 * @param string $post_type
	 */
	private function check_post_type( $post_type ) {
		if ( null === $post_type || 'any' === $post_type ) {
			return true;

src/Export_Command.php:402

  • check_post__in() permits null, but the PHPDoc is @param string $post__in. Update the docblock to include null so static analysis doesn’t treat the early-return branch as dead and the docs match actual input.
	/**
	 * @param string $post__in
	 */
	private function check_post__in( $post__in ) {
		if ( null === $post__in ) {
			return true;
		}

src/Export_Command.php:441

  • check_author() accepts null and supports both numeric IDs and user logins, but the PHPDoc declares $author as string. Update the @param to something like int|string|null to match the behavior and the command help text.
	/**
	 * @param string $author
	 */
	private function check_author( $author ) {
		if ( null === $author ) {
			return true;
		}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Export_Command.php
Comment on lines 272 to 275
foreach ( $args as $key => $value ) {
if ( is_callable( [ $this, 'check_' . $key ] ) ) {
/** @phpstan-ignore argument.type */
$result = call_user_func( [ $this, 'check_' . $key ], $value );
if ( false === $result ) {
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate_args() removes the PHPStan suppression but still passes an inline array expression into is_callable()/call_user_func(). PHPStan generally can’t narrow this expression to callable, which can re-trigger argument.type errors. Store the callback into a local variable (or use a dynamic method call via a $method variable) so the is_callable() check can narrow the type before invocation.

Copilot uses AI. Check for mistakes.
@swissspidy swissspidy merged commit fb7d727 into main Apr 30, 2026
19 of 69 checks passed
@swissspidy swissspidy deleted the fix/phpstan branch April 30, 2026 07:30
@swissspidy swissspidy added this to the 2.1.17 milestone Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:testing Related to testing status:unconfirmed Issue was could not be confirmed yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants