Skip to content

Commit 6b7c1bc

Browse files
authored
Bug Fixes
1 parent 4bea43b commit 6b7c1bc

4 files changed

Lines changed: 35 additions & 24 deletions

File tree

.github/workflows/update-pot-file.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ on:
77
- '**.php'
88
- '**.js'
99
- '.github/workflows/update-pot-file.yml'
10-
paths-ignore:
11-
- 'README.md'
12-
- 'CHANGELOG.md'
13-
- 'GEMINI.md'
1410
workflow_dispatch:
1511

1612
permissions:

includes/class-fgcbg-coupon-generator.php

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class FGCBG_Coupon_Generator {
5353
* Generate coupons.
5454
*
5555
* @since 1.0.0
56-
* @param array $product_ids Array of product IDs to generate coupons for.
56+
* @param array<int> $product_ids Array of product IDs to generate coupons for.
5757
* @param int $number_of_coupons Number of coupons to generate.
5858
* @param string $prefix Coupon prefix.
5959
* @param string $discount_type Type of discount.
@@ -81,8 +81,8 @@ public function generate_coupons( $product_ids, $number_of_coupons, $prefix = ''
8181
* Validate products for coupon generation.
8282
*
8383
* @since 1.0.0
84-
* @param array|int $product_ids Product IDs to validate.
85-
* @return array Array of valid product objects keyed by ID.
84+
* @param array<int>|int $product_ids Product IDs to validate.
85+
* @return array<int, WC_Product> Array of valid product objects keyed by ID.
8686
*/
8787
private function validate_products( $product_ids ) {
8888
if ( ! is_array( $product_ids ) ) {
@@ -107,14 +107,17 @@ private function validate_products( $product_ids ) {
107107
* @param int $number_of_coupons Number of coupons to generate.
108108
* @param string $prefix Coupon prefix.
109109
* @param string $discount_type Type of discount.
110-
* @return array Generation parameters array.
110+
* @return array{count:int, prefix:string, discount_type:string, expiry_days:int, max_attempts:int} Generation parameters array.
111111
*/
112112
private function prepare_generation_params( $number_of_coupons, $prefix, $discount_type ) {
113+
$count = (int) apply_filters( 'fgcbg_max_coupons_per_batch', $number_of_coupons );
114+
$expiry_days = (int) apply_filters( 'fgcbg_coupon_expiry_days', self::DEFAULT_EXPIRY_DAYS );
115+
113116
return array(
114-
'count' => apply_filters( 'fgcbg_max_coupons_per_batch', $number_of_coupons ),
117+
'count' => $count,
115118
'prefix' => $prefix,
116119
'discount_type' => $discount_type,
117-
'expiry_days' => apply_filters( 'fgcbg_coupon_expiry_days', self::DEFAULT_EXPIRY_DAYS ),
120+
'expiry_days' => $expiry_days,
118121
'max_attempts' => $number_of_coupons * 2,
119122
);
120123
}
@@ -123,8 +126,8 @@ private function prepare_generation_params( $number_of_coupons, $prefix, $discou
123126
* Prepare gift information for coupons.
124127
*
125128
* @since 1.0.0
126-
* @param array $valid_products Array of valid product objects.
127-
* @return array Gift information array.
129+
* @param array<int, WC_Product> $valid_products Array of valid product objects.
130+
* @return array<int, array{product_id:int, variation_id:int, quantity:int}> Gift information array.
128131
*/
129132
private function prepare_gift_info( $valid_products ) {
130133
$gift_info = array();
@@ -142,9 +145,9 @@ private function prepare_gift_info( $valid_products ) {
142145
* Execute the coupon generation process.
143146
*
144147
* @since 1.0.0
145-
* @param array $valid_products Array of valid product objects.
146-
* @param array $gift_info Gift information array.
147-
* @param array $params Generation parameters.
148+
* @param array<int, WC_Product> $valid_products Array of valid product objects.
149+
* @param array<int, array{product_id:int, variation_id:int, quantity:int}> $gift_info Gift information array.
150+
* @param array{count:int, prefix:string, discount_type:string, expiry_days:int, max_attempts:int} $params Generation parameters.
148151
* @return int Number of coupons generated.
149152
*/
150153
private function execute_coupon_generation( $valid_products, $gift_info, $params ) {
@@ -174,9 +177,9 @@ private function execute_coupon_generation( $valid_products, $gift_info, $params
174177
* Create a single coupon.
175178
*
176179
* @since 1.0.0
177-
* @param array $valid_products Array of valid product objects.
178-
* @param array $gift_info Gift information array.
179-
* @param array $params Generation parameters.
180+
* @param array<int, WC_Product> $valid_products Array of valid product objects.
181+
* @param array<int, array{product_id:int, variation_id:int, quantity:int}> $gift_info Gift information array.
182+
* @param array{count:int, prefix:string, discount_type:string, expiry_days:int, max_attempts:int} $params Generation parameters.
180183
* @param int $current_number Current coupon number in batch.
181184
* @return bool True if coupon was created successfully, false otherwise.
182185
*/
@@ -205,8 +208,8 @@ private function create_single_coupon( $valid_products, $gift_info, $params, $cu
205208
* @since 1.0.0
206209
* @param WC_Coupon $coupon The coupon object.
207210
* @param string $code The coupon code.
208-
* @param array $valid_products Array of valid product objects.
209-
* @param array $params Generation parameters.
211+
* @param array<int, WC_Product> $valid_products Array of valid product objects.
212+
* @param array{count:int, prefix:string, discount_type:string, expiry_days:int, max_attempts:int} $params Generation parameters.
210213
* @param int $current_number Current coupon number in batch.
211214
* @return void
212215
*/
@@ -238,8 +241,8 @@ private function set_coupon_properties( $coupon, $code, $valid_products, $params
238241
*
239242
* @since 1.0.0
240243
* @param WC_Coupon $coupon The coupon object.
241-
* @param array $gift_info Gift information array.
242-
* @param array $params Generation parameters.
244+
* @param array<int, array{product_id:int, variation_id:int, quantity:int}> $gift_info Gift information array.
245+
* @param array{count:int, prefix:string, discount_type:string, expiry_days:int, max_attempts:int} $params Generation parameters.
243246
* @return void
244247
*/
245248
private function set_coupon_metadata( $coupon, $gift_info, $params ) {

includes/class-fgcbg-plugin.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,20 @@ public function enqueue_admin_scripts( $hook ) {
191191
'fgcbg_i18n',
192192
array(
193193
'ajax_url' => admin_url( 'admin-ajax.php' ),
194-
'nonce' => wp_create_nonce( 'fgcbg_ajax_nonce' ), /* translators: %d is the number of coupons to be generated */ 'confirm_large_batch' => __( 'You are about to generate %d coupons. This may take a while and could potentially timeout depending on your server settings. Do you want to continue?', 'free-gift-coupons-bulk-coupons-generator' ),
194+
'nonce' => wp_create_nonce( 'fgcbg_ajax_nonce' ),
195+
/* translators: %d is the number of coupons to be generated. */
196+
'confirm_large_batch' => __( 'You are about to generate %d coupons. This may take a while and could potentially timeout depending on your server settings. Do you want to continue?', 'free-gift-coupons-bulk-coupons-generator' ),
195197
'max_coupons_warning' => __( 'Maximum 100 coupons allowed', 'free-gift-coupons-bulk-coupons-generator' ),
196198
'many_coupons_warning' => __( 'Generating many coupons may take some time and could timeout', 'free-gift-coupons-bulk-coupons-generator' ),
197199
'select_product' => __( 'Please select at least one product.', 'free-gift-coupons-bulk-coupons-generator' ),
198200
'invalid_coupon_count' => __( 'Please enter a valid number of coupons (minimum 1).', 'free-gift-coupons-bulk-coupons-generator' ),
199201
'max_coupon_count' => __( 'Maximum number of coupons is 100.', 'free-gift-coupons-bulk-coupons-generator' ),
200202
'prefix_too_long' => __( 'Coupon prefix must be 10 characters or less.', 'free-gift-coupons-bulk-coupons-generator' ),
201-
'generation_in_progress' => __( 'Coupon generation is in progress. Are you sure you want to leave this page?', 'free-gift-coupons-bulk-coupons-generator' ), /* translators: %1$d is the current coupon count, %2$d is the total number of coupons to generate */ 'generating_progress' => __( 'Generating coupons: %1$d of %2$d', 'free-gift-coupons-bulk-coupons-generator' ), /* translators: %d is the number of successfully generated coupons */ 'generation_complete' => __( 'Successfully generated %d coupons.', 'free-gift-coupons-bulk-coupons-generator' ),
203+
'generation_in_progress' => __( 'Coupon generation is in progress. Are you sure you want to leave this page?', 'free-gift-coupons-bulk-coupons-generator' ),
204+
/* translators: %1$d is the current coupon count, %2$d is the total number of coupons to generate. */
205+
'generating_progress' => __( 'Generating coupons: %1$d of %2$d', 'free-gift-coupons-bulk-coupons-generator' ),
206+
/* translators: %d is the number of successfully generated coupons. */
207+
'generation_complete' => __( 'Successfully generated %d coupons.', 'free-gift-coupons-bulk-coupons-generator' ),
202208
'generation_failed' => __( 'Failed to generate coupons. Please try again.', 'free-gift-coupons-bulk-coupons-generator' ),
203209
)
204210
);

phpstan.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ parameters:
1313

1414
bootstrapFiles:
1515
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
16+
17+
dynamicConstantNames:
18+
- FGCBG_PLUGIN_URL
19+
- FGCBG_PLUGIN_VERSION
1620

1721
treatPhpDocTypesAsCertain: false
22+
23+
reportUnmatchedIgnoredErrors: false
1824

1925
ignoreErrors:
2026
# Ignore WordPress global variables that might not be defined in test context

0 commit comments

Comments
 (0)