Merge pull request #2909 from woocommerce/PCP-4028-fix-php-notices-related-to-settings-mapping

Fix PHP notices related to settings-mapping (4028)
This commit is contained in:
Philipp Stracker 2024-12-12 14:54:28 +01:00 committed by GitHub
commit 10f251c73f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 144 additions and 46 deletions

View file

@ -5,7 +5,7 @@
* @package WooCommerce\PayPalCommerce\WcGateway\Settings
*/
declare(strict_types=1);
declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\WcGateway\Settings;
@ -18,44 +18,46 @@ use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
*/
class Settings implements ContainerInterface {
const KEY = 'woocommerce-ppcp-settings';
const KEY = 'woocommerce-ppcp-settings';
const CONNECTION_TAB_ID = 'ppcp-connection';
const PAY_LATER_TAB_ID = 'ppcp-pay-later';
const PAY_LATER_TAB_ID = 'ppcp-pay-later';
/**
* The settings.
*
* @var array
*/
private $settings = array();
private array $settings = array();
/**
* The list of selected default button locations.
*
* @var string[]
*/
protected $default_button_locations;
protected array $default_button_locations;
/**
* The list of selected default pay later button locations.
*
* @var string[]
*/
protected $default_pay_later_button_locations;
protected array $default_pay_later_button_locations;
/**
* The list of selected default pay later messaging locations.
*
* @var string[]
*/
protected $default_pay_later_messaging_locations;
protected array $default_pay_later_messaging_locations;
/**
* The default ACDC gateway title.
*
* @var string
*/
protected $default_dcc_gateway_title;
protected string $default_dcc_gateway_title;
/**
* A helper for mapping the new/old settings.
@ -67,11 +69,17 @@ class Settings implements ContainerInterface {
/**
* Settings constructor.
*
* @param string[] $default_button_locations The list of selected default button locations.
* @param string $default_dcc_gateway_title The default ACDC gateway title.
* @param string[] $default_pay_later_button_locations The list of selected default pay later button locations.
* @param string[] $default_pay_later_messaging_locations The list of selected default pay later messaging locations.
* @param SettingsMapHelper $settings_map_helper A helper for mapping the new/old settings.
* @param string[] $default_button_locations The list of selected default
* button locations.
* @param string $default_dcc_gateway_title The default ACDC gateway
* title.
* @param string[] $default_pay_later_button_locations The list of selected default
* pay later button locations.
* @param string[] $default_pay_later_messaging_locations The list of selected default
* pay later messaging
* locations.
* @param SettingsMapHelper $settings_map_helper A helper for mapping the
* new/old settings.
*/
public function __construct(
array $default_button_locations,
@ -90,10 +98,11 @@ class Settings implements ContainerInterface {
/**
* Returns the value for an id.
*
* @param string $id The value identificator.
* @throws NotFoundException When nothing was found.
*
* @param string $id The value identifier.
*
* @return mixed
* @throws NotFoundException When nothing was found.
*/
public function get( $id ) {
if ( ! $this->has( $id ) ) {
@ -106,23 +115,24 @@ class Settings implements ContainerInterface {
/**
* Whether a value exists.
*
* @param string $id The value identificator.
* @param string $id The value identifier.
*
* @return bool
*/
public function has( $id ) {
public function has( string $id ) {
if ( $this->settings_map_helper->has_mapped_key( $id ) ) {
return true;
}
$this->load();
return array_key_exists( $id, $this->settings );
}
/**
* Sets a value.
*
* @param string $id The value identificator.
* @param string $id The value identifier.
* @param mixed $value The value.
*/
public function set( $id, $value ) {
@ -142,7 +152,7 @@ class Settings implements ContainerInterface {
*
* @return bool
*/
private function load(): bool {
private function load() : bool {
if ( $this->settings ) {
return false;
}
@ -175,6 +185,7 @@ class Settings implements ContainerInterface {
}
$this->settings[ $key ] = $value;
}
return true;
}
}