Fix PHPStan errors

MAILPOET-6318
This commit is contained in:
Oluwaseun Olorunsola
2024-11-29 11:06:30 +01:00
committed by Jan Lysý
parent 9a6225873c
commit 6df51455d2
7 changed files with 63 additions and 6 deletions

View File

@@ -134,8 +134,8 @@ class Content_Renderer_Test extends \MailPoetTest {
*/
private function getStylesValueForTag( $html, $tag ): ?string {
$html = new \WP_HTML_Tag_Processor( $html );
if ( $html->next_tag( $tag ) ) { // @phpstan-ignore-line
return $html->get_attribute( 'style' ); // @phpstan-ignore-line
if ( $html->next_tag( $tag ) ) {
return $html->get_attribute( 'style' );
}
return null;
}

View File

@@ -211,7 +211,7 @@ class Renderer_Test extends \MailPoetTest {
private function getStylesValueForTag( string $html, array $query ): ?string {
$html = new \WP_HTML_Tag_Processor( $html );
if ( $html->next_tag( $query ) ) {
return $html->get_attribute( 'style' ); // @phpstan-ignore-line
return $html->get_attribute( 'style' );
}
return null;
}

View File

@@ -86,6 +86,7 @@ class PersonalizationTagsRegistryTest extends TestCase {
$this->registry->register( new Personalization_Tag( 'tag2', 'tag-2', 'Category 2', $callback2 ) );
// Retrieve the tag and ensure the first registration is preserved.
/** @var Personalization_Tag $tag */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
$tag = $this->registry->get_by_token( 'tag-1' );
$this->assertSame( 'tag1', $tag->get_name() );
$this->assertSame( 'Category 1', $tag->get_category() );

View File

@@ -41,13 +41,21 @@ if ( ! function_exists( 'add_filter' ) ) {
*
* @param string $tag Tag to add filter for.
* @param callable $callback Callback to call.
* @param int $priority Optional. Used to specify the order in which the functions
* associated with a particular filter are executed.
* Lower numbers correspond with earlier execution,
* and functions with the same priority are executed
* in the order in which they were added to the filter. Default 10.
* @param int $accepted_args Optional. The number of arguments the function accepts. Default 1.
* @return bool Always returns true.
*/
function add_filter( $tag, $callback ) {
function add_filter( $tag, $callback, $priority = 10, $accepted_args = 1 ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
global $wp_filters;
if ( ! isset( $wp_filters ) ) {
$wp_filters = array();
}
$wp_filters[ $tag ][] = $callback;
return true;
}
}
@@ -57,8 +65,10 @@ if ( ! function_exists( 'apply_filters' ) ) {
*
* @param string $tag Tag to apply filters for.
* @param mixed $value Value to filter.
* @param mixed ...$args Optional. Additional parameters to pass to the callback functions.
* @return mixed The filtered value after all hooked functions are applied to it.
*/
function apply_filters( $tag, $value ) {
function apply_filters( $tag, $value, ...$args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
global $wp_filters;
if ( isset( $wp_filters[ $tag ] ) ) {
foreach ( $wp_filters[ $tag ] as $callback ) {