Skip to content

PHPStan: correct includes/acf-field-functions.php #52

Closed

Description

@kraftbj
message: '#^@param array \$sub_field does not accept actual type of parameter\: int\|false\.$#'
			identifier: parameter.phpDocType
			count: 1
			path: ../includes/acf-field-functions.php

		-
			message: '#^Action callback returns array but should not return anything\.$#'
			identifier: return.void
			count: 1
			path: ../includes/acf-field-functions.php

		-
			message: '#^Expected 2 @param tags, found 1\.$#'
			identifier: paramTag.count
			count: 1
			path: ../includes/acf-field-functions.php

		-
			message: '#^Function wp_trash_post invoked with 2 parameters, 0\-1 required\.$#'
			identifier: arguments.count
			count: 1
			path: ../includes/acf-field-functions.php

		-
			message: '#^Function wp_untrash_post invoked with 2 parameters, 0\-1 required\.$#'
			identifier: arguments.count
			count: 1
			path: ../includes/acf-field-functions.php

		-
			message: '#^One or more @param tags has an invalid name or invalid syntax\.$#'
			identifier: phpDoc.parseError
			count: 2
			path: ../includes/acf-field-functions.php

Activity

  1. changed the title [-]'#^@param array \$sub_field does not accept actual type of parameter\: int\|false\.$#'[/-] [+]PHPStan: correct includes/acf-field-functions.php[/+] on Mar 4, 2025
  2. added theissue type on Mar 14, 2025
  3. pkevan commented on Apr 23, 2025

    @pkevan
    Contributor

    Started looking at these in an attempt to clear out some issues, and in this particular one, the hardest one to fix is:

    message: '#^Action callback returns array but should not return anything\.$#'
    			identifier: return.void
    			count: 1
    			path: ../includes/acf-field-functions.php
    

    which relates to (

    /**
    * acf_translate_field
    *
    * Translates a field's settings.
    *
    * @date 8/03/2016
    * @since ACF 5.3.2
    *
    * @param array $field The field array.
    * @return array
    */
    function acf_translate_field( $field = array() ) {
    // Get settings.
    $l10n = acf_get_setting( 'l10n' );
    $l10n_textdomain = acf_get_setting( 'l10n_textdomain' );
    // Translate field settings if textdomain is set.
    if ( $l10n && $l10n_textdomain ) {
    $field['label'] = acf_translate( $field['label'] );
    $field['instructions'] = acf_translate( $field['instructions'] );
    /**
    * Filters the $field array to translate strings.
    *
    * @date 12/02/2014
    * @since ACF 5.0.0
    *
    * @param array $field The field array.
    */
    $field = apply_filters( 'acf/translate_field', $field );
    }
    // Return field.
    return $field;
    }
    // Register variation.
    acf_add_filter_variations( 'acf/translate_field', array( 'type' ), 0 );
    // Translate fields passing through validation.
    add_action( 'acf/validate_field', 'acf_translate_field' );
    ). the easy fix would be to avoid having a return in the function, but I'm hesitant to change that since other themes could be reliant on that function.

    function _acf_translate_field( $field = array() ) {
    	acf_translate_field( $field );
    }
    
    // Translate fields passing through validation.
    add_action( 'acf/validate_field', '_acf_translate_field' );
    

    Thoughts?

  4. kraftbj commented on Apr 23, 2025

    @kraftbj
    ContributorAuthor

    I've seen this elsewhere is the original code. They're using add_action when they're treating it as add_filter. Behind the scenes, it all works (e.g. apply_filters will run things added via add_action), but it's not correct.

    I only glanced at it, but my suggestion is updating it to add_filter on 334.

  5. pkevan commented on Apr 23, 2025

    @pkevan
    Contributor

    updating it to add_filter on 334.

    🤦 of course - spent too long looking at it to not see that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions