mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
Fix lint
This commit is contained in:
parent
a87ca32a12
commit
b5b8502997
2 changed files with 50 additions and 2 deletions
|
@ -89,6 +89,11 @@ class SaveConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the config into the old settings.
|
||||||
|
*
|
||||||
|
* @param array $config The configurator config.
|
||||||
|
*/
|
||||||
private function save_config( array $config ): void {
|
private function save_config( array $config ): void {
|
||||||
$this->settings->set( 'pay_later_enable_styling_per_messaging_location', true );
|
$this->settings->set( 'pay_later_enable_styling_per_messaging_location', true );
|
||||||
|
|
||||||
|
@ -109,6 +114,12 @@ class SaveConfig {
|
||||||
$this->settings->persist();
|
$this->settings->persist();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the config for a location into the old settings.
|
||||||
|
*
|
||||||
|
* @param array $config The configurator config for a location.
|
||||||
|
* @param string $location The location name in the old settings.
|
||||||
|
*/
|
||||||
private function save_config_for_location( array $config, string $location ): void {
|
private function save_config_for_location( array $config, string $location ): void {
|
||||||
$this->set_value_if_present( $config, 'layout', "pay_later_{$location}_message_layout" );
|
$this->set_value_if_present( $config, 'layout', "pay_later_{$location}_message_layout" );
|
||||||
|
|
||||||
|
@ -121,12 +132,24 @@ class SaveConfig {
|
||||||
$this->set_value_if_present( $config, 'text-size', "pay_later_{$location}_message_text_size" );
|
$this->set_value_if_present( $config, 'text-size', "pay_later_{$location}_message_text_size" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value in the settings if it is available in the config.
|
||||||
|
*
|
||||||
|
* @param array $config The configurator config.
|
||||||
|
* @param string $key The key in the config.
|
||||||
|
* @param string $settings_key The key in the settings.
|
||||||
|
*/
|
||||||
private function set_value_if_present( array $config, string $key, string $settings_key ): void {
|
private function set_value_if_present( array $config, string $key, string $settings_key ): void {
|
||||||
if ( isset( $config[ $key ] ) ) {
|
if ( isset( $config[ $key ] ) ) {
|
||||||
$this->settings->set( $settings_key, $config[ $key ] );
|
$this->settings->set( $settings_key, $config[ $key ] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the configurator placement into location in the old settings.
|
||||||
|
*
|
||||||
|
* @param string $placement The configurator placement.
|
||||||
|
*/
|
||||||
private function configurator_placement_to_location( string $placement ): string {
|
private function configurator_placement_to_location( string $placement ): string {
|
||||||
switch ( $placement ) {
|
switch ( $placement ) {
|
||||||
case 'cart':
|
case 'cart':
|
||||||
|
|
|
@ -15,6 +15,11 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||||
* Class ConfigFactory.
|
* Class ConfigFactory.
|
||||||
*/
|
*/
|
||||||
class ConfigFactory {
|
class ConfigFactory {
|
||||||
|
/**
|
||||||
|
* Returns the configurator config for the given old settings.
|
||||||
|
*
|
||||||
|
* @param Settings $settings The settings.
|
||||||
|
*/
|
||||||
public function from_settings( Settings $settings ): array {
|
public function from_settings( Settings $settings ): array {
|
||||||
return array(
|
return array(
|
||||||
$this->location_to_configurator_placement( 'cart' ) => $this->for_location( $settings, 'cart' ),
|
$this->location_to_configurator_placement( 'cart' ) => $this->for_location( $settings, 'cart' ),
|
||||||
|
@ -25,11 +30,17 @@ class ConfigFactory {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the configurator config for a location.
|
||||||
|
*
|
||||||
|
* @param Settings $settings The settings.
|
||||||
|
* @param string $location The location name in the old settings.
|
||||||
|
*/
|
||||||
private function for_location( Settings $settings, string $location ): array {
|
private function for_location( Settings $settings, string $location ): array {
|
||||||
$selected_locations = $settings->has( 'pay_later_messaging_locations' ) ? $settings->get( 'pay_later_messaging_locations' ) : array();
|
$selected_locations = $settings->has( 'pay_later_messaging_locations' ) ? $settings->get( 'pay_later_messaging_locations' ) : array();
|
||||||
|
|
||||||
$placement = $this->location_to_configurator_placement( $location );
|
$placement = $this->location_to_configurator_placement( $location );
|
||||||
if ( in_array( $placement, array( 'category', 'homepage' ) ) ) {
|
if ( in_array( $placement, array( 'category', 'homepage' ), true ) ) {
|
||||||
$config = array(
|
$config = array(
|
||||||
'layout' => 'flex',
|
'layout' => 'flex',
|
||||||
'color' => $this->get_or_default( $settings, "pay_later_{$location}_message_flex_color", 'black', array( 'black', 'blue', 'white', 'white-no-border' ) ),
|
'color' => $this->get_or_default( $settings, "pay_later_{$location}_message_flex_color", 'black', array( 'black', 'blue', 'white', 'white-no-border' ) ),
|
||||||
|
@ -48,13 +59,18 @@ class ConfigFactory {
|
||||||
|
|
||||||
return array_merge(
|
return array_merge(
|
||||||
array(
|
array(
|
||||||
'status' => in_array( $location, $selected_locations ) ? 'enabled' : 'disabled',
|
'status' => in_array( $location, $selected_locations, true ) ? 'enabled' : 'disabled',
|
||||||
'placement' => $placement,
|
'placement' => $placement,
|
||||||
),
|
),
|
||||||
$config
|
$config
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the location name from the old settings into the configurator placement.
|
||||||
|
*
|
||||||
|
* @param string $location The location name in the old settings.
|
||||||
|
*/
|
||||||
private function location_to_configurator_placement( string $location ): string {
|
private function location_to_configurator_placement( string $location ): string {
|
||||||
switch ( $location ) {
|
switch ( $location ) {
|
||||||
case 'cart':
|
case 'cart':
|
||||||
|
@ -70,6 +86,15 @@ class ConfigFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the settings value or default, if does not exist or not allowed value.
|
||||||
|
*
|
||||||
|
* @param Settings $settings The settings.
|
||||||
|
* @param string $key The key.
|
||||||
|
* @param mixed $default The default value.
|
||||||
|
* @param array|null $allowed_values The list of allowed values, or null if all values are allowed.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
private function get_or_default( Settings $settings, string $key, $default, ?array $allowed_values = null ) {
|
private function get_or_default( Settings $settings, string $key, $default, ?array $allowed_values = null ) {
|
||||||
if ( $settings->has( $key ) ) {
|
if ( $settings->has( $key ) ) {
|
||||||
$value = $settings->get( $key );
|
$value = $settings->get( $key );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue