Skip to content

Commit

Permalink
Code style & Notices
Browse files Browse the repository at this point in the history
  • Loading branch information
inpsyde-maticluznar committed Oct 3, 2024
1 parent 6ce5187 commit d39fa16
Show file tree
Hide file tree
Showing 14 changed files with 277 additions and 935 deletions.
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<file>./src</file>
<exclude-pattern>./tests/</exclude-pattern>

<config name="testVersion" value="7.2"/>
<config name="testVersion" value="7.4"/>
<config name="ignore_warnings_on_exit" value="1"/>
<rule ref="Inpsyde">
<exclude name="NeutronStandard.StrictTypes.RequireStrictTypes.StrictTypes"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Buttons/ApplePayButton/ApplePayDataObjectHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ protected function addressHasRequiredFieldsValues(
sprintf('ApplePay Data Error: Missing value for %s', $requiredField)
);
$this->errors[]
= [
= [
'errorCode' => $errorCode,
'contactField' => $errorValue,
];
Expand Down
1 change: 1 addition & 0 deletions src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ public function buildPaymentMethod(
Surcharge $surchargeService,
array $apiMethod
) {

$transformedId = ucfirst($id);
$paymentMethodClassName = 'Mollie\\WooCommerce\\PaymentMethods\\' . $transformedId;
$paymentMethod = new $paymentMethodClassName(
Expand Down
10 changes: 8 additions & 2 deletions src/PaymentMethods/PaymentMethodsIconUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ public function svgUrlForPaymentMethod($paymentMethodName)
$svgUrl = $this->pluginUrl . '/' . sprintf('public/images/%s', $paymentMethodName) . self::SVG_FILE_EXTENSION;
}

return $this->generateIconHtml($svgUrl);
return wp_kses($this->generateIconHtml($svgUrl), [
'img' => [
'src' => [],
'class' => [],
'alt' => [],
],
]);
}

public function generateIconHtml($svgUrl)
public function generateIconHtml(string $svgUrl): string
{

return '<img src="' . esc_url($svgUrl)
Expand Down
56 changes: 8 additions & 48 deletions src/Settings/MollieSettingsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ public function registerContentFieldType(): void
<th scope="row" class="titledesc">
<label for="<?php
echo esc_attr($value['id']); ?>"><?php
echo esc_html($value['title']); ?></label>
echo esc_html($value['title']); ?></label>
</th>
<td class="forminp">
<?php
if (!empty($value['value'])) : ?>
<?= $value['value']; ?>
<?= $value['value']; // WPCS: XSS ok. ?>
<?php
endif; ?>

<?php
if (!empty($value['desc'])) : ?>
<p class="description"><?= $value['desc']; ?></p>
<p class="description"><?= $value['desc']; // WPCS: XSS ok. ?></p>
<?php
endif; ?>
</td>
Expand All @@ -77,7 +77,7 @@ public function registerContentFieldType(): void

add_action('woocommerce_admin_field_mollie_content', static function ($value): void {
if (!empty($value['value'])) {
echo $value['value'];
echo $value['value']; // WPCS: XSS ok.
}
});
}
Expand Down Expand Up @@ -151,8 +151,8 @@ protected function checkDirectDebitStatus($content): string
$sepaGatewayAllowed = !empty($this->registeredGateways["mollie_wc_gateway_directdebit"]);
if ($sepaGatewayAllowed && !$isSepaEnabled) {
$warning_message = __(
"You have WooCommerce Subscriptions activated, but not SEPA Direct Debit. Enable SEPA Direct Debit if you want to allow customers to pay subscriptions with iDEAL and/or other 'first' payment methods.",
'mollie-payments-for-woocommerce'
"You have WooCommerce Subscriptions activated, but not SEPA Direct Debit. Enable SEPA Direct Debit if you want to allow customers to pay subscriptions with iDEAL and/or other 'first' payment methods.",
'mollie-payments-for-woocommerce'
);

$content .= '<div class="notice notice-warning is-dismissible"><p>';
Expand All @@ -177,8 +177,8 @@ protected function checkMollieBankTransferNotBACS($content): string
if ($woocommerce_banktransfer_gateway->is_available()) {
$content .= '<div class="notice notice-warning is-dismissible"><p>';
$content .= __(
'You have the WooCommerce default Direct Bank Transfer (BACS) payment gateway enabled in WooCommerce. Mollie strongly advices only using Bank Transfer via Mollie and disabling the default WooCommerce BACS payment gateway to prevent possible conflicts.',
'mollie-payments-for-woocommerce'
'You have the WooCommerce default Direct Bank Transfer (BACS) payment gateway enabled in WooCommerce. Mollie strongly advices only using Bank Transfer via Mollie and disabling the default WooCommerce BACS payment gateway to prevent possible conflicts.',
'mollie-payments-for-woocommerce'
);
$content .= '</p></div> ';

Expand All @@ -193,44 +193,4 @@ protected function checkMollieBankTransferNotBACS($content): string
*
* @return string
*/
protected function warnAboutRequiredCheckoutFieldForKlarna($content): string
{
$isKlarnaEnabled = $this->isKlarnaEnabled();
if ($isKlarnaEnabled) {
$content .= '<div class="notice notice-warning is-dismissible"><p>';
$content .= sprintf(
/* translators: Placeholder 1: Opening link tag. Placeholder 2: Closing link tag. Placeholder 3: Opening link tag. Placeholder 4: Closing link tag. */
__(
'You have activated Klarna. To accept payments, please make sure all default WooCommerce checkout fields are enabled and required. For more information, go to %1$sKlarna Pay Later documentation%2$s or %3$sKlarna Slice it documentation%4$s',
'mollie-payments-for-woocommerce'
),
'<a href="https://github.com/mollie/WooCommerce/wiki/Setting-up-Klarna-Pay-later-gateway">',
'</a>',
'<a href=" https://github.com/mollie/WooCommerce/wiki/Setting-up-Klarna-Slice-it-gateway">',
'</a>'
);
$content .= '</p></div> ';

return $content;
}

return $content;
}

protected function isKlarnaEnabled(): bool
{
$klarnaGateways = [Constants::KLARNAPAYLATER, Constants::KLARNASLICEIT, Constants::KLARNAPAYNOW, Constants::KLARNA];
$isKlarnaEnabled = false;
foreach ($klarnaGateways as $klarnaGateway) {
if (
array_key_exists('mollie_wc_gateway_' . $klarnaGateway, $this->mollieGateways)
&& array_key_exists($klarnaGateway, $this->paymentMethods)
&& $this->paymentMethods[$klarnaGateway]->getProperty('enabled') === 'yes'
) {
$isKlarnaEnabled = true;
break;
}
}
return $isKlarnaEnabled;
}
}
Loading

0 comments on commit d39fa16

Please sign in to comment.