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

@@ -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 ) {}
}
}

View File

@@ -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:

View File

@@ -63,6 +63,7 @@ class Personalizer {
* ));
*
* @param array<string, mixed> $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(

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 ) {