Update comments and fix code style warnings

MAILPOET-6318
This commit is contained in:
Oluwaseun Olorunsola
2024-11-26 12:48:28 +01:00
committed by Jan Lysý
parent a15f8ba562
commit b1cc53ec5b
9 changed files with 58 additions and 50 deletions

View File

@@ -14,17 +14,17 @@ parameters:
checkGenericClassInNonGenericObjectType: false
parallel:
processTimeout: 300.0
maximumNumberOfProcesses: 3 # Static analysis is running on Circle CI medium+ that has 3 CPUs
maximumNumberOfProcesses: 4 # Using 4 CPUs for Static analysis on Github actions
ignoreErrors:
- '#_before\(\) has no return type specified#' # skip integration test before errors
-
message: '#has no return type specified.#'
message: '#has no return type specified.#' # ignore has no return type specified for integration test files
path: ../../../packages/php/email-editor/tests/integration/*
-
message: '#assertStringContainsString\(\) expects string#'
message: '#assertStringContainsString\(\) expects string#' # ignore expects string, string|true|null given in integration test files. The test will fail if an invalid value is provided
path: ../../../packages/php/email-editor/tests/integration/*
-
message: '#assertStringNotContainsString\(\) expects string#'
message: '#assertStringNotContainsString\(\) expects string#' # ignore expects string, string|true|null given in integration test files. The test will fail if an invalid value is provided
path: ../../../packages/php/email-editor/tests/integration/*
reportUnmatchedIgnoredErrors: true
dynamicConstantNames:

View File

@@ -89,7 +89,7 @@ class Renderer {
*/
public function render( \WP_Post $post, string $subject, string $pre_header, string $language, $meta_robots = '' ): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
$template_id = 'mailpoet/mailpoet//' . ( get_page_template_slug( $post ) ? get_page_template_slug( $post ) : 'email-general' );
/** @var \WP_Block_Template $template */ // phpcs:ignore
/** @var \WP_Block_Template $template */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
$template = $this->templates->get_block_template( $template_id );
$theme = $this->templates->get_block_template_theme( $template_id, $template->wp_id );

View File

@@ -371,7 +371,7 @@ class Templates {
return array_map(
function ( $custom_template ) {
/** @var \WP_Post $custom_template */ // phpcs:ignore
/** @var \WP_Post $custom_template */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
return $this->utils->build_block_template_from_post( $custom_template );
},
$custom_templates

View File

@@ -94,11 +94,11 @@ class Utils {
return $template;
}
// phpcs:disable
/**
* Build a block template from a file.
*
* @param object{
* @template TemplateObject
* @phpstan-type TemplateObject object{
* slug: string,
* id: string,
* title: string,
@@ -108,11 +108,11 @@ class Utils {
* theme: string,
* source: string,
* post_types: array<string>
* } $template_object Template object.
* }
* @param TemplateObject $template_object Template object.
* @return WP_Block_Template
*/
public function build_block_template_from_file( $template_object ): WP_Block_Template {
// phpcs:enable
$template = new WP_Block_Template();
$template->id = $template_object->id;
$template->theme = $template_object->theme;

View File

@@ -89,7 +89,7 @@ class Theme_Controller {
if ( is_array( $style_value ) ) {
$styles[ $key ] = $this->recursive_extract_preset_variables( $style_value );
} elseif ( strpos( $style_value, 'var:preset|' ) === 0 ) {
/** @var string $style_value */ // phpcs:ignore
/** @var string $style_value */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$styles[ $key ] = 'var(--wp--' . str_replace( '|', '--', str_replace( 'var:', '', $style_value ) ) . ')';
} else {
$styles[ $key ] = $style_value;

View File

@@ -153,7 +153,7 @@ class Image extends Abstract_Block_Renderer {
$html = new \WP_HTML_Tag_Processor( $block_content );
if ( $html->next_tag( array( 'tag_name' => 'img' ) ) ) {
// Getting height from styles and if it's set, we set the height attribute.
/** @var string $styles */ // phpcs:ignore
/** @var string $styles */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
$styles = $html->get_attribute( 'style' ) ?? '';
$styles = $settings_controller->parse_styles_to_array( $styles );
$height = $styles['height'] ?? null;
@@ -280,7 +280,7 @@ class Image extends Abstract_Block_Renderer {
private function add_style_to_element( $block_content, array $tag, string $style ): string {
$html = new \WP_HTML_Tag_Processor( $block_content );
if ( $html->next_tag( $tag ) ) {
/** @var string $element_style */ // phpcs:ignore
/** @var string $element_style */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
$element_style = $html->get_attribute( 'style' ) ?? '';
$element_style = ! empty( $element_style ) ? ( rtrim( $element_style, ';' ) . ';' ) : ''; // Adding semicolon if it's missing.
$element_style .= $style;
@@ -301,7 +301,7 @@ class Image extends Abstract_Block_Renderer {
private function remove_style_attribute_from_element( $block_content, array $tag, string $style_name ): string {
$html = new \WP_HTML_Tag_Processor( $block_content );
if ( $html->next_tag( $tag ) ) {
/** @var string $element_style */ // phpcs:ignore
/** @var string $element_style */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
$element_style = $html->get_attribute( 'style' ) ?? '';
$element_style = preg_replace( '/' . $style_name . ':(.?[0-9]+px)+;?/', '', $element_style );
$html->set_attribute( 'style', esc_attr( strval( $element_style ) ) );

View File

@@ -27,7 +27,7 @@ class List_Block extends Abstract_Block_Renderer {
$html = new \WP_HTML_Tag_Processor( $block_content );
$tag_name = ( $parsed_block['attrs']['ordered'] ?? false ) ? 'ol' : 'ul';
if ( $html->next_tag( array( 'tag_name' => $tag_name ) ) ) {
/** @var string $styles */ // phpcs:ignore
/** @var string $styles */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
$styles = $html->get_attribute( 'style' ) ?? '';
$styles = $settings_controller->parse_styles_to_array( $styles );

View File

@@ -38,14 +38,14 @@ class Text extends Abstract_Block_Renderer {
$html = new \WP_HTML_Tag_Processor( $block_content );
$classes = 'email-text-block';
if ( $html->next_tag() ) {
/** @var string $block_classes */ // phpcs:ignore
/** @var string $block_classes */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
$block_classes = $html->get_attribute( 'class' ) ?? '';
$classes .= ' ' . $block_classes;
// remove has-background to prevent double padding applied for wrapper and inner element.
$block_classes = str_replace( 'has-background', '', $block_classes );
// remove border related classes because we handle border on wrapping table cell.
$block_classes = preg_replace( '/[a-z-]+-border-[a-z-]+/', '', $block_classes );
/** @var string $block_classes */ // phpcs:ignore
/** @var string $block_classes */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
$html->set_attribute( 'class', trim( $block_classes ) );
$block_content = $html->get_updated_html();
}
@@ -118,7 +118,7 @@ class Text extends Abstract_Block_Renderer {
// to prevent CSS Inliner from adding a default value and overriding the value set by user, which is on the wrapper element.
// The value provided by WP uses clamp() function which is not supported in many email clients.
$element_style = preg_replace( '/font-size:[^;]+;?/', 'font-size: inherit;', strval( $element_style ) );
/** @var string $element_style */ // phpcs:ignore
/** @var string $element_style */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
$html->set_attribute( 'style', esc_attr( $element_style ) );
$block_content = $html->get_updated_html();
}

View File

@@ -1,42 +1,50 @@
<?php // phpcs:ignoreFile
<?php
/**
* This file is part of the MailPoet Email Editor package.
*
* @package MailPoet\EmailEditor
*/
// throw exception if anything fails.
set_error_handler(
declare(strict_types = 1);
/**
* Throw exception if anything fails.
*/
set_error_handler( // phpcs:ignore -- This file is not used within WordPress environment.
function ( $severity, $message, $file, $line ) {
throw new ErrorException( $message, 0, $severity, $file, $line );
throw new ErrorException( $message, 0, $severity, $file, $line ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
}
);
$mailpoetRootDir = dirname( __DIR__, 4 );
$mailpoet_root_dir = dirname( __DIR__, 4 );
$emailEditorPhpDir = dirname( __DIR__, 1 );
$email_editor_php_dir = dirname( __DIR__, 1 );
$phpStanDir = "$mailpoetRootDir/mailpoet/tasks/phpstan";
$phpStanBin = "$phpStanDir/vendor/bin/phpstan";
$php_stan_dir = "$mailpoet_root_dir/mailpoet/tasks/phpstan";
$php_stan_bin = "$php_stan_dir/vendor/bin/phpstan";
$emailEditorCustomConfig = "$phpStanDir/email-editor-phpstan.neon";
$email_editor_custom_config = "$php_stan_dir/email-editor-phpstan.neon";
$extraAgrPhpVersion = '';
$extra_agr_php_version = '';
if ( $argc > 1 && isset( $argv[1] ) && stripos( $argv[1], 'php-version' ) !== false ) {
$rawArgv = explode( '=', escapeshellcmd( $argv[1] ) );
$value = $rawArgv[1];
$extraAgrPhpVersion = "ANALYSIS_PHP_VERSION=$value ";
$raw_argv = explode( '=', escapeshellcmd( $argv[1] ) );
$value = $raw_argv[1];
$extra_agr_php_version = "ANALYSIS_PHP_VERSION=$value ";
}
$commands = array(
"cd $phpStanDir && ", // we run commands from the PHPStan dir because we save MailPoet-specific configuration in it
"$extraAgrPhpVersion",
"cd $php_stan_dir && ", // we run commands from the PHPStan dir because we save MailPoet-specific configuration in it.
"$extra_agr_php_version",
'php -d memory_limit=-1 ',
"$phpStanBin analyse ",
"-c $emailEditorCustomConfig ",
"$emailEditorPhpDir/src ",
"$emailEditorPhpDir/tests/integration ",
"$emailEditorPhpDir/tests/unit ",
"$php_stan_bin analyse ",
"-c $email_editor_custom_config ",
"$email_editor_php_dir/src ",
"$email_editor_php_dir/tests/integration ",
"$email_editor_php_dir/tests/unit ",
);
$allCommands = implode( ' ', $commands );
$all_commands = implode( ' ', $commands );
echo "[run-phpstan] Running command: $allCommands \n";
echo "[run-phpstan] Running command: $all_commands \n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- This file is not used within WordPress environment.
passthru( $allCommands );
passthru( $all_commands ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_passthru -- This file is not used within WordPress environment.