Skip to content

Commit

Permalink
PES-2321: escaping exceptions not required
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-potuznik-z committed Nov 6, 2024
1 parent edf8cdc commit c1cb93f
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 21 deletions.
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<exclude name="Squiz.Commenting.FunctionComment.EmptyThrows"/>
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
<exclude name="PSR2.Classes.ClassDeclaration.CloseBraceAfterBody"/>
<exclude name="WordPress.Security.EscapeOutput.ExceptionNotEscaped"/>
</rule>

<rule ref="WordPress.WP.I18n">
Expand Down
1 change: 0 additions & 1 deletion src/Packetery/Core/Api/Rest/PickupPointValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public function validate( PickupPointValidateRequest $request ): PickupPointVali

return new PickupPointValidateResponse( $resultArray['isValid'], $resultArray['errors'] );
} catch ( \Exception $exception ) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new RestException( $exception->getMessage() );
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/Packetery/Core/Rounder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public static function round( float $amount, int $roundingType, int $precision )
throw new InvalidArgumentException(
sprintf(
'Precision should be non-negative number, roundingType should be one of %s.',
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
implode( ', ', self::ROUNDING_TYPES )
)
);
Expand Down Expand Up @@ -92,7 +91,6 @@ public static function roundToMultipleOfNumber( float $amount, int $roundingType
throw new InvalidArgumentException(
sprintf(
'Divisor should be positive number, roundingType should be one of %s.',
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
implode( ', ', self::ROUNDING_TYPES )
)
);
Expand All @@ -119,7 +117,6 @@ public static function roundByCurrency( float $amount, string $currencyCode, int
throw new InvalidArgumentException(
sprintf(
'RoundingType should should be one of %s.',
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
implode( ', ', self::ROUNDING_TYPES )
)
);
Expand Down
6 changes: 2 additions & 4 deletions src/Packetery/Module/Carrier/PacketaPickupPointsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use Packetery\Core\PickupPointProvider\VendorProvider;
use Packetery\Module\Exception\InvalidCarrierException;
use Packetery\Module\Options\FlagManager\FeatureFlagProvider;
use function esc_html;
use function esc_html__;

/**
* Packeta pickup points configuration.
Expand Down Expand Up @@ -240,8 +238,8 @@ public function getFixedCarrierId( string $carrierId, string $country ): string
throw new InvalidCarrierException(
sprintf(
// translators: %s is country code.
esc_html__( 'Selected carrier does not deliver to country "%s".', 'packeta' ),
esc_html( $country )
__( 'Selected carrier does not deliver to country "%s".', 'packeta' ),
$country
)
);
}
Expand Down
1 change: 0 additions & 1 deletion src/Packetery/Module/Options/OptionsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public function __construct() {
public function getOptionsByName( string $optionsName ): array {
$data = $this->getAllOptions();
if ( ! isset( $data[ $optionsName ] ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new \InvalidArgumentException( sprintf( 'Option name "%s" does not exist.', $optionsName ) );
}

Expand Down
8 changes: 3 additions & 5 deletions src/Packetery/Module/Order/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
use Packetery\Module\WeightCalculator;
use stdClass;
use WC_Order;
use function esc_html;
use function esc_html__;

// phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
/**
Expand Down Expand Up @@ -129,7 +127,7 @@ public function __construct(
public function build( WC_Order $wcOrder, stdClass $result ): Entity\Order {
$country = ModuleHelper::getWcOrderCountry( $wcOrder );
if ( empty( $country ) ) {
throw new InvalidCarrierException( esc_html__( 'Please set the country of the delivery address first.', 'packeta' ) );
throw new InvalidCarrierException( __( 'Please set the country of the delivery address first.', 'packeta' ) );
}

$carrierId = $this->pickupPointsConfig->getFixedCarrierId( $result->carrier_id, $country );
Expand All @@ -138,8 +136,8 @@ public function build( WC_Order $wcOrder, stdClass $result ): Entity\Order {
throw new InvalidCarrierException(
sprintf(
// translators: %s is carrier id.
esc_html__( 'Order carrier is invalid (%s). Please contact Packeta support.', 'packeta' ),
esc_html( $carrierId )
__( 'Order carrier is invalid (%s). Please contact Packeta support.', 'packeta' ),
$carrierId
)
);
}
Expand Down
3 changes: 0 additions & 3 deletions src/Packetery/Module/Order/CarrierModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public function onFormSuccess( Forms\Form $form ): void {
$orderId = $this->detailCommonLogic->getOrderId();
$newCarrierId = (string) $values[ CarrierModalFormFactory::FIELD_CARRIER_ID ];
if ( null === $orderId ) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new RuntimeException( 'Packeta: Failed to process carrier change, new carrier id ' . $newCarrierId );
}

Expand Down Expand Up @@ -194,7 +193,6 @@ public function onFormSuccess( Forms\Form $form ): void {
private function createNewCarrierOrder( int $orderId, string $newCarrierId ): string {
$newCarrier = $this->carrierRepository->getAnyById( $newCarrierId );
if ( null === $newCarrier ) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new RuntimeException( 'Packeta: Failed to get instance of carrier with id ' . $newCarrierId );
}
$this->orderRepository->saveData(
Expand All @@ -206,7 +204,6 @@ private function createNewCarrierOrder( int $orderId, string $newCarrierId ): st

$options = $this->carrierOptionsFactory->createByCarrierId( $newCarrier->getId() );
if ( ! $options->hasOptions() ) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new RuntimeException( 'Missing options for carrier ' . $newCarrier->getId() );
}

Expand Down
1 change: 0 additions & 1 deletion src/Packetery/Module/Order/PacketSubmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ public function submitPacket(
private function preparePacketData( Entity\Order $order ): array {
$validationErrors = $this->orderValidator->validate( $order );
if ( ! empty( $validationErrors ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
throw new InvalidRequestException( 'All required order attributes are not set.', $validationErrors );
}

Expand Down
5 changes: 2 additions & 3 deletions src/Packetery/Module/WebRequestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use Packetery\Core\Api\WebRequestException;
use Packetery\Core\Interfaces\IWebRequestClient;
use function esc_html;

/**
* Class WebRequestClient
Expand All @@ -33,7 +32,7 @@ class WebRequestClient implements IWebRequestClient {
public function post( string $url, array $options ): string {
$resultResponse = wp_remote_post( $url, $options );
if ( is_wp_error( $resultResponse ) ) {
throw new WebRequestException( esc_html( $resultResponse->get_error_message() ) );
throw new WebRequestException( $resultResponse->get_error_message() );
}

return wp_remote_retrieve_body( $resultResponse );
Expand All @@ -54,7 +53,7 @@ public function get( string $url, array $options = [] ): string {
];
$resultResponse = wp_remote_get( $url, $options );
if ( is_wp_error( $resultResponse ) ) {
throw new WebRequestException( esc_html( $resultResponse->get_error_message() ) );
throw new WebRequestException( $resultResponse->get_error_message() );
}

return wp_remote_retrieve_body( $resultResponse );
Expand Down

0 comments on commit c1cb93f

Please sign in to comment.