Fix PHPCS errors

This commit is contained in:
Daniel Dudzic 2024-04-09 23:44:51 +02:00
parent 7b499b3780
commit 708fcc0faa
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
6 changed files with 118 additions and 90 deletions

View file

@ -12,7 +12,7 @@ namespace WooCommerce\PayPalCommerce\PayLaterWCBlocks;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
return array(
'paylater-wc-blocks.url' => static function ( ContainerInterface $container ): string {
'paylater-wc-blocks.url' => static function ( ContainerInterface $container ): string {
/**
* Cannot return false for this path.
*

View file

@ -15,8 +15,20 @@ use Automattic\WooCommerce\Blocks\Integrations\IntegrationInterface;
* Class for integrating with WooCommerce Blocks
*/
class PayLaterWCBlocksIntegration implements IntegrationInterface {
protected $paylater_wc_blocks_url;
protected $ppcp_asset_version;
/**
* The URL of the Pay Later WooCommerce Blocks plugin.
*
* @var string
*/
protected $paylater_wc_blocks_url;
/**
* The version of the Pay Later WooCommerce Blocks plugin.
*
* @var string
*/
protected $ppcp_asset_version;
/**
* Constructor
@ -24,10 +36,10 @@ class PayLaterWCBlocksIntegration implements IntegrationInterface {
* @param string $paylater_wc_blocks_url The URL of the Pay Later WooCommerce Blocks plugin.
* @param string $ppcp_asset_version The version of the Pay Later WooCommerce Blocks plugin.
*/
public function __construct( string $paylater_wc_blocks_url, string $ppcp_asset_version ) {
$this->paylater_wc_blocks_url = $paylater_wc_blocks_url;
$this->ppcp_asset_version = $ppcp_asset_version;
}
public function __construct( string $paylater_wc_blocks_url, string $ppcp_asset_version ) {
$this->paylater_wc_blocks_url = $paylater_wc_blocks_url;
$this->ppcp_asset_version = $ppcp_asset_version;
}
/**
* The name of the integration.
@ -64,31 +76,31 @@ class PayLaterWCBlocksIntegration implements IntegrationInterface {
* @return void
*/
private function register_main_integration() : void {
$cart_block_script_path = 'assets/js/ppcp-cart-paylater-messages-block.js';
$cart_block_script_path = 'assets/js/ppcp-cart-paylater-messages-block.js';
$checkout_block_script_path = 'assets/js/ppcp-checkout-paylater-messages-block.js';
$style_path = 'build/style-index.css';
$style_path = 'build/style-index.css';
$cart_block_script_url = $this->paylater_wc_blocks_url . $cart_block_script_path;
$cart_block_script_url = $this->paylater_wc_blocks_url . $cart_block_script_path;
$checkout_block_script_url = $this->paylater_wc_blocks_url . $checkout_block_script_path;
$style_url = $this->paylater_wc_blocks_url . $style_path;
$style_url = $this->paylater_wc_blocks_url . $style_path;
$cart_block_script_asset_path = $this->paylater_wc_blocks_url . 'assets/ppcp-cart-paylater-messages-block.asset.php';
$cart_block_script_asset_path = $this->paylater_wc_blocks_url . 'assets/ppcp-cart-paylater-messages-block.asset.php';
$checkout_block_script_asset_path = $this->paylater_wc_blocks_url . 'assets/ppcp-checkout-paylater-messages-block.asset.php';
$cart_block_script_asset = file_exists( $cart_block_script_asset_path )
$cart_block_script_asset = file_exists( $cart_block_script_asset_path )
? require $cart_block_script_asset_path
: [
'dependencies' => [],
: array(
'dependencies' => array(),
'version' => $this->get_file_version( $cart_block_script_asset_path ),
];
);
$checkout_block_script_asset = file_exists( $checkout_block_script_asset_path )
$checkout_block_script_asset = file_exists( $checkout_block_script_asset_path )
? require $checkout_block_script_asset_path
: [
'dependencies' => [],
: array(
'dependencies' => array(),
'version' => $this->get_file_version( $checkout_block_script_asset_path ),
];
);
wp_register_script(
'ppcp-cart-paylater-messages-block',
@ -125,7 +137,7 @@ class PayLaterWCBlocksIntegration implements IntegrationInterface {
* @return string[]
*/
public function get_script_handles(): array {
return [ 'ppcp-checkout-paylater-messages-block', 'ppcp-cart-paylater-messages-block', 'ppcp-cart-paylater-messages-block-frontend', 'ppcp-checkout-paylater-messages-block-frontend' ];
return array( 'ppcp-checkout-paylater-messages-block', 'ppcp-cart-paylater-messages-block', 'ppcp-cart-paylater-messages-block-frontend', 'ppcp-checkout-paylater-messages-block-frontend' );
}
/**
@ -134,7 +146,7 @@ class PayLaterWCBlocksIntegration implements IntegrationInterface {
* @return string[]
*/
public function get_editor_script_handles(): array {
return [ 'ppcp-cart-paylater-wc-blocks-editor', 'ppcp-checkout-paylater-wc-blocks-editor', 'ppcp-checkout-paylater-messages-block', 'ppcp-cart-paylater-messages-block' ];
return array( 'ppcp-cart-paylater-wc-blocks-editor', 'ppcp-checkout-paylater-wc-blocks-editor', 'ppcp-checkout-paylater-messages-block', 'ppcp-cart-paylater-messages-block' );
}
/**
@ -144,9 +156,9 @@ class PayLaterWCBlocksIntegration implements IntegrationInterface {
*/
public function get_script_data(): array {
return [
return array(
'ppcp-paylater-wc-blocks-active' => true,
];
);
}
/**
@ -155,27 +167,26 @@ class PayLaterWCBlocksIntegration implements IntegrationInterface {
* @return void
*/
public function register_paylater_wc_blocks_editor_scripts(): void {
$cart_block_script_path = 'assets/js/cart-paylater-messages-block.js';
$checkout_block_script_path = 'assets/js/checkout-paylater-messages-block.js';
$cart_block_script_url = $this->paylater_wc_blocks_url . $cart_block_script_path;
$checkout_block_script_url = $this->paylater_wc_blocks_url . $checkout_block_script_path;
$cart_block_script_asset_path = $this->paylater_wc_blocks_url . 'assets/cart-paylater-messages-block.asset.php';
$cart_block_script_path = 'assets/js/cart-paylater-messages-block.js';
$checkout_block_script_path = 'assets/js/checkout-paylater-messages-block.js';
$cart_block_script_url = $this->paylater_wc_blocks_url . $cart_block_script_path;
$checkout_block_script_url = $this->paylater_wc_blocks_url . $checkout_block_script_path;
$cart_block_script_asset_path = $this->paylater_wc_blocks_url . 'assets/cart-paylater-messages-block.asset.php';
$checkout_block_script_asset_path = $this->paylater_wc_blocks_url . 'assets/checkout-paylater-messages-block.asset.php';
$cart_block_script_asset = file_exists( $cart_block_script_asset_path )
? require $cart_block_script_asset_path
: [
'dependencies' => [],
: array(
'dependencies' => array(),
'version' => $this->get_file_version( $cart_block_script_asset_path ),
];
);
$checkout_block_script_asset = file_exists( $checkout_block_script_asset_path )
? require $checkout_block_script_asset_path
: [
'dependencies' => [],
: array(
'dependencies' => array(),
'version' => $this->get_file_version( $checkout_block_script_asset_path ),
];
);
wp_register_script(
'ppcp-cart-paylater-wc-blocks-editor',
@ -212,26 +223,26 @@ class PayLaterWCBlocksIntegration implements IntegrationInterface {
* @return void
*/
public function register_paylater_wc_blocks_frontend_scripts(): void {
$cart_block_script_path = 'assets/js/cart-paylater-messages-block-frontend.js';
$checkout_block_script_path = 'assets/js/checkout-paylater-messages-block-frontend.js';
$cart_block_script_url = $this->paylater_wc_blocks_url . $cart_block_script_path;
$checkout_block_script_url = $this->paylater_wc_blocks_url . $checkout_block_script_path;
$cart_block_script_asset_path = $this->paylater_wc_blocks_url . 'assets/cart-paylater-messages-block-frontend.asset.php';
$cart_block_script_path = 'assets/js/cart-paylater-messages-block-frontend.js';
$checkout_block_script_path = 'assets/js/checkout-paylater-messages-block-frontend.js';
$cart_block_script_url = $this->paylater_wc_blocks_url . $cart_block_script_path;
$checkout_block_script_url = $this->paylater_wc_blocks_url . $checkout_block_script_path;
$cart_block_script_asset_path = $this->paylater_wc_blocks_url . 'assets/cart-paylater-messages-block-frontend.asset.php';
$checkout_block_script_asset_path = $this->paylater_wc_blocks_url . 'assets/checkout-paylater-messages-block-frontend.asset.php';
$cart_block_script_asset = file_exists( $cart_block_script_asset_path )
? require $cart_block_script_asset_path
: [
'dependencies' => [],
: array(
'dependencies' => array(),
'version' => $this->get_file_version( $cart_block_script_asset_path ),
];
);
$checkout_block_script_asset = file_exists( $checkout_block_script_asset_path )
? require $checkout_block_script_asset_path
: [
'dependencies' => [],
: array(
'dependencies' => array(),
'version' => $this->get_file_version( $checkout_block_script_asset_path ),
];
);
wp_register_script(
'ppcp-cart-paylater-messages-block-frontend',

View file

@ -40,7 +40,7 @@ class PayLaterWCBlocksModule implements ModuleInterface {
* Returns whether the block is enabled.
*
* @param SettingsStatus $settings_status The Settings status helper.
* @param string $location The location to check.
* @param string $location The location to check.
* @return bool true if the block is enabled, otherwise false.
*/
public static function is_block_enabled( SettingsStatus $settings_status, string $location ): bool {
@ -51,7 +51,7 @@ class PayLaterWCBlocksModule implements ModuleInterface {
* Returns whether the placement is enabled.
*
* @param SettingsStatus $settings_status The Settings status helper.
* @param string $location The location to check.
* @param string $location The location to check.
* @return bool true if the placement is enabled, otherwise false.
*/
public static function is_placement_enabled( SettingsStatus $settings_status, string $location ) : bool {
@ -82,17 +82,22 @@ class PayLaterWCBlocksModule implements ModuleInterface {
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
add_action( 'woocommerce_blocks_loaded', function() use ( $c ): void {
add_action(
'woocommerce_blocks_checkout_block_registration',
function( $integration_registry ) use ( $c ): void {
$integration_registry->register( new PayLaterWCBlocksIntegration(
$c->get( 'paylater-wc-blocks.url' ),
$c->get( 'ppcp.asset-version' )
) );
}
);
});
add_action(
'woocommerce_blocks_loaded',
function() use ( $c ): void {
add_action(
'woocommerce_blocks_checkout_block_registration',
function( $integration_registry ) use ( $c ): void {
$integration_registry->register(
new PayLaterWCBlocksIntegration(
$c->get( 'paylater-wc-blocks.url' ),
$c->get( 'ppcp.asset-version' )
)
);
}
);
}
);
add_action(
'init',
@ -172,16 +177,16 @@ class PayLaterWCBlocksModule implements ModuleInterface {
function( $categories ): array {
return array_merge(
$categories,
[
[
array(
array(
'slug' => 'ppcp-cart-paylater-messages-block',
'title' => __( 'PayPal Cart Pay Later Messages Blocks', 'woocommerce-paypal-payments' ),
],
[
),
array(
'slug' => 'ppcp-checkout-paylater-messages-block',
'title' => __( 'PayPal Checkout Pay Later Messages Blocks', 'woocommerce-paypal-payments' ),
],
]
),
)
);
},
10,
@ -194,17 +199,22 @@ class PayLaterWCBlocksModule implements ModuleInterface {
* @psalm-suppress PossiblyFalseArgument
*/
register_block_type(
dirname( realpath( __FILE__ ), 2) . '/resources/js/CartPayLaterMessagesBlock',
[
dirname( realpath( __FILE__ ), 2 ) . '/resources/js/CartPayLaterMessagesBlock',
array(
'render_callback' => function ( $attributes ) use ( $c ) {
$renderer = $c->get( 'paylater-wc-blocks.renderer' );
ob_start();
// phpcs:ignore -- No need to escape it, the PayLaterWCBlocksRenderer class is responsible for escaping.
echo $renderer->render(
$attributes, 'cart', $c
// phpcs:ignore
$attributes,
'cart',
// phpcs:ignore
$c
);
return ob_get_clean();
}
]
},
)
);
/**
@ -213,17 +223,22 @@ class PayLaterWCBlocksModule implements ModuleInterface {
* @psalm-suppress PossiblyFalseArgument
*/
register_block_type(
dirname( realpath( __FILE__ ), 2) . '/resources/js/CheckoutPayLaterMessagesBlock',
[
dirname( realpath( __FILE__ ), 2 ) . '/resources/js/CheckoutPayLaterMessagesBlock',
array(
'render_callback' => function ( $attributes ) use ( $c ) {
$renderer = $c->get( 'paylater-wc-blocks.renderer' );
ob_start();
// phpcs:ignore -- No need to escape it, the PayLaterWCBlocksRenderer class is responsible for escaping.
echo $renderer->render(
$attributes, 'checkout', $c
// phpcs:ignore
$attributes,
'checkout',
// phpcs:ignore
$c
);
return ob_get_clean();
}
]
},
)
);
}

View file

@ -19,12 +19,12 @@ class PayLaterWCBlocksRenderer {
/**
* Renders the WC Pay Later Messaging blocks.
*
* @param array $attributes
* @param string $location
* @param ContainerInterface $c
* @param array $attributes The block attributes.
* @param string $location The location of the block.
* @param ContainerInterface $c The container.
* @return string|void
*/
public function render( array $attributes, string $location, ContainerInterface $c ) {
public function render( array $attributes, string $location, ContainerInterface $c ) {
if ( PayLaterWCBlocksModule::is_placement_enabled( $c->get( 'wcgateway.settings.status' ), $location ) ) {
return '<div id="' . esc_attr( $attributes['id'] ?? '' ) . '" class="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>';
}