Add conditional return type for sanitize_post_field #383
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The return type of
sanitize_post_field()depends on both the$fieldbeing sanitised and the$context.For integer fields
it returns an integer. If
$valueis of type int, we can even return a constant integer or an integer range.For the field value
'ancestors, it returns an array with non-negative integer values.For all other fields, the type depends on the
$context:'raw':$valueis returned as is, which is handled via the templateT; for constant types, the same constant type is returned.'attribute'|'edit'|'js':$valueis escaped--and may be transformed--usingesc_attr(),esc_html(), oresc_js(). Assuming the filters in these functions do not alter the type, the returned type isstring, even if$valueis a constant string. The only exception is the field value'post_content'which might be filtered but is only escaped ifuser_can_richedit() === false. In this case the default return type ofmixedis retained.$contextvalues:$valueis not escaped but is filtered, with the filter callback documented as returningmixed. Therefore, the default return type ofmixedis retained.Related: #382, szepeviktor/phpstan-wordpress#297