diff --git a/mailpoet/tasks/phpstan/custom-stubs.php b/mailpoet/tasks/phpstan/custom-stubs.php index 4bbaf09861..01b1a035dd 100644 --- a/mailpoet/tasks/phpstan/custom-stubs.php +++ b/mailpoet/tasks/phpstan/custom-stubs.php @@ -66,6 +66,19 @@ namespace { if (!class_exists(\WP_HTML_Tag_Processor::class)) { class WP_HTML_Tag_Processor { + + /** @var int */ + const MAX_BOOKMARKS = 10; + + /** @var string */ + protected $html; + + /** @var WP_HTML_Span[] */ + protected $bookmarks = array(); + + /** @var WP_HTML_Text_Replacement[] */ + protected $lexical_updates = array(); + public function __construct($content) { } @@ -80,6 +93,36 @@ namespace { public function set_attribute($attribute, $value) { } + + public function next_token() {} + + public function get_modifiable_text() {} + + public function get_token_type() {} + + public function remove_attribute($name) {} + + public function get_tag() {} + + public function set_modifiable_text($plaintext_content ) {} + + public function set_bookmark($name) {} + } + } + + if (!class_exists(\WP_HTML_Span::class)) { + class WP_HTML_Span { + /** @var int */ + public $start; + + /** @var int */ + public $length; + + /** + * @param int $start Byte offset into document where replacement span begins. + * @param int $length Byte length of span. + */ + public function __construct( int $start, int $length ) {} } } diff --git a/mailpoet/tasks/phpstan/email-editor-phpstan.neon b/mailpoet/tasks/phpstan/email-editor-phpstan.neon index 700bf3e98c..163a4cf2c7 100644 --- a/mailpoet/tasks/phpstan/email-editor-phpstan.neon +++ b/mailpoet/tasks/phpstan/email-editor-phpstan.neon @@ -10,6 +10,8 @@ parameters: - ../../../packages/php/email-editor/tests/_support - ../../../packages/php/email-editor/tests/integration - ../../../packages/php/email-editor/tests/unit + scanFiles: + - custom-stubs.php inferPrivatePropertyTypeFromConstructor: true checkGenericClassInNonGenericObjectType: false parallel: diff --git a/packages/php/email-editor/src/Engine/class-personalizer.php b/packages/php/email-editor/src/Engine/class-personalizer.php index aedcbf9d7f..1a0791a523 100644 --- a/packages/php/email-editor/src/Engine/class-personalizer.php +++ b/packages/php/email-editor/src/Engine/class-personalizer.php @@ -63,6 +63,7 @@ class Personalizer { * )); * * @param array $context Associative array containing personalization data. + * @return void */ public function set_context( array $context ) { $this->context = $context; @@ -102,7 +103,7 @@ class Personalizer { * Parse a personalization tag to the token and attributes. * * @param string $token The token to parse. - * @return array{token: string, attributes: array} The parsed token. + * @return array{token: string, arguments: array} The parsed token. */ private function parse_token( string $token ): array { $result = array( diff --git a/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php b/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php index 7377033ec7..7f23446c24 100644 --- a/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php +++ b/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php @@ -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; } diff --git a/packages/php/email-editor/tests/integration/Engine/Renderer/Renderer_Test.php b/packages/php/email-editor/tests/integration/Engine/Renderer/Renderer_Test.php index ff4941a11f..1520cea146 100644 --- a/packages/php/email-editor/tests/integration/Engine/Renderer/Renderer_Test.php +++ b/packages/php/email-editor/tests/integration/Engine/Renderer/Renderer_Test.php @@ -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; } diff --git a/packages/php/email-editor/tests/unit/Engine/PersonalizationTags/Personalization_Tags_Registry_Test.php b/packages/php/email-editor/tests/unit/Engine/PersonalizationTags/Personalization_Tags_Registry_Test.php index aa7f4e8efc..53479290f0 100644 --- a/packages/php/email-editor/tests/unit/Engine/PersonalizationTags/Personalization_Tags_Registry_Test.php +++ b/packages/php/email-editor/tests/unit/Engine/PersonalizationTags/Personalization_Tags_Registry_Test.php @@ -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() ); diff --git a/packages/php/email-editor/tests/unit/_bootstrap.php b/packages/php/email-editor/tests/unit/_bootstrap.php index 810e308a09..b4fd6d814a 100644 --- a/packages/php/email-editor/tests/unit/_bootstrap.php +++ b/packages/php/email-editor/tests/unit/_bootstrap.php @@ -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 ) {