Fix newly reported PHPStan errors#140
Conversation
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.unusedsuppressions fromcheck_*validators. - Removed an inline
@phpstan-ignore argument.typesuppression around the dynamic validator invocation. - Added a concrete
@paramPHPDoc forcheck_max_num_posts().
Comments suppressed due to low confidence (12)
src/Export_Command.php:597
check_include_once()treatsnullas valid input but the PHPDoc declares$onceasstring. Update the@paramtostring|nullto 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()allowsnullbut the PHPDoc declares$allow_orphan_termsasstring. Update the docblock to includenull(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
$datesaysstring, but the function explicitly allowsnull(if ( null === $date ) return true;). Update the@paramto includenull(and keep it aligned with howvalidate_args()supplies defaultnullvalues) 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
$dateisstring, but this validator handlesnullas a valid value. Change the@paramto includenullso 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()allowsnull(return trueearly), but the@paramisstring. Adjust the PHPDoc to includenullso 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()acceptsnulland then casts the value to(int)when present, but the PHPDoc saysstring. Consider documenting this asint|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()acceptsnulland also allows numeric IDs (casting to int), but the PHPDoc is@param string $category. Update the docblock to includeintandnullso 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 fornull, but the PHPDoc declares$statusasstring. Update the@paramto includenullto 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$sizeasstring, but the CLI default is an int (15) and the writer args PHPDoc expects anint. Consider updating the@paramtoint|stringand casting$sizeto an int (or otherwise normalizing) before assigning to$this->max_file_sizeto 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()treatsnullas a valid input, but the@paramis documented asstring. Update the docblock tostring|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()permitsnull, but the PHPDoc is@param string $post__in. Update the docblock to includenullso 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()acceptsnulland supports both numeric IDs and user logins, but the PHPDoc declares$authorasstring. Update the@paramto something likeint|string|nullto 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.
| 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 ) { |
There was a problem hiding this comment.
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.
No description provided.