pronamic/wp-documentor

Empty list of arguments when `apply_filters` is used in a conditional clause instead of assigned to a variable

LuigiPulcini opened this issue · 2 comments

This issue is similar to #11.

The list of arguments is empty when apply_filters is used inside a conditional clause instead of assigned to a variable first.

So, when using the right doc block, the following code doesn't output the correct result:

if ( apply_filters( 'some_condition_filter', $some_condition, $some_other_parameter ) ) {
    do_something();
}

and must be replaced with as follows:

$some_condition = apply_filters( 'some_condition_filter', $some_condition, $some_other_parameter );

if ( $some_condition ) {
    do_something();
}

I just created a test for this issue:

<?php
/**
* Test for issue 17.
*
* @author Pronamic <info@pronamic.eu>
* @copyright 2005-2022 Pronamic
* @license GPL-3.0-or-later
* @package Pronamic\WordPress\Documentor
*/
/**
* Test issue 17.
*
* @link https://github.com/pronamic/wp-documentor/issues/17
* @param bool $some_condition Condition.
* @param mixed $some_other_parameter Other parameter.
* @return bool
*/
if ( apply_filters( 'some_condition_filter', $some_condition, $some_other_parameter ) ) {
do_something();
}

The arguments table is not empty?

## Filters
### `some_condition_filter`
*Test issue 17.*
**Arguments**
Argument | Type | Description
-------- | ---- | -----------
`$some_condition` | `bool` | Condition.
`$some_other_parameter` | `mixed` | Other parameter.
Source: [tests/issue-17/test-issue-17.php](test-issue-17.php), [line 11](test-issue-17.php#L11-L19)

Or am I seeing this wrong @LuigiPulcini?

Same happens when casting the value returned by apply_filters

$should_do = (bool) apply_filters( 'should_we_do_it', true, $some_value );