Skip to content

Commit 4e3407a

Browse files
authored
Updates
1 parent 4a24d92 commit 4e3407a

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- **Code Style and Documentation**: Addressed multiple code style issues, including whitespace, alignment, and indentation, to improve readability and maintainability.
12+
- **PHPDoc Blocks**: Added comprehensive PHPDoc blocks to all functions, ensuring all parameters and return values are clearly documented.
13+
1014
### Fixed
1115
- Fixed WordPress coding standards violations in function formatting
1216
- Fixed anonymous function spacing and indentation issues

free-gift-bulk-coupon-generator.php

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Domain Path: /languages
1515
*
1616
* @package wc-free-gift-coupons-bulk-coupons-generator
17-
*
17+
*
1818
* Note: This is the main plugin file and follows WordPress plugin naming conventions.
1919
* The filename free-gift-bulk-coupon-generator.php is intentionally different from
2020
* the class name to follow WordPress plugin standards.
@@ -180,7 +180,9 @@ function () {
180180
$product_ids = isset( $_POST['product_id'] ) ? array_map( 'absint', (array) wp_unslash( $_POST['product_id'] ) ) : array();
181181
$number_of_coupons = isset( $_POST['number_of_coupons'] ) ? absint( wp_unslash( $_POST['number_of_coupons'] ) ) : 0;
182182
$coupon_prefix = isset( $_POST['coupon_prefix'] ) ? sanitize_text_field( wp_unslash( $_POST['coupon_prefix'] ) ) : '';
183-
$discount_type = isset( $_POST['discount_type'] ) ? sanitize_text_field( wp_unslash( $_POST['discount_type'] ) ) : 'free_gift'; // Validate discount type against allowed values.
183+
$discount_type = isset( $_POST['discount_type'] ) ? sanitize_text_field( wp_unslash( $_POST['discount_type'] ) ) : 'free_gift';
184+
185+
// Validate discount type against allowed values.
184186
$allowed_discount_types = array( 'free_gift', 'percent', 'fixed_cart', 'fixed_product' );
185187
if ( ! in_array( $discount_type, $allowed_discount_types, true ) ) {
186188
$discount_type = 'free_gift'; // Default to safe value.
@@ -246,11 +248,11 @@ function () {
246248
'admin_notices',
247249
function () use ( $generated_coupons ) {
248250
echo '<div class="notice notice-success is-dismissible"><p>' .
249-
sprintf(
250-
/* translators: %d: Number of coupons generated */
251-
esc_html__( 'Successfully generated %d coupons.', 'wc-free-gift-coupons-bulk-coupons-generator' ),
252-
esc_html( $generated_coupons )
253-
) .
251+
sprintf(
252+
/* translators: %d: Number of coupons generated */
253+
esc_html__( 'Successfully generated %d coupons.', 'wc-free-gift-coupons-bulk-coupons-generator' ),
254+
esc_html( $generated_coupons )
255+
) .
254256
'</p></div>';
255257
}
256258
);
@@ -321,6 +323,11 @@ private function validate_products( $product_ids ) {
321323

322324
/**
323325
* Prepare generation parameters
326+
*
327+
* @param int $number_of_coupons Number of coupons to generate.
328+
* @param string $prefix Coupon prefix.
329+
* @param string $discount_type Type of discount.
330+
* @return array Generation parameters array.
324331
*/
325332
private function prepare_generation_params( $number_of_coupons, $prefix, $discount_type ) {
326333
return array(
@@ -334,6 +341,9 @@ private function prepare_generation_params( $number_of_coupons, $prefix, $discou
334341

335342
/**
336343
* Prepare gift information for coupons
344+
*
345+
* @param array $valid_products Array of valid product objects.
346+
* @return array Gift information array.
337347
*/
338348
private function prepare_gift_info( $valid_products ) {
339349
$gift_info = array();
@@ -350,6 +360,11 @@ private function prepare_gift_info( $valid_products ) {
350360

351361
/**
352362
* Execute the coupon generation process
363+
*
364+
* @param array $valid_products Array of valid product objects.
365+
* @param array $gift_info Gift information array.
366+
* @param array $params Generation parameters.
367+
* @return int Number of coupons generated.
353368
*/
354369
private function execute_coupon_generation( $valid_products, $gift_info, $params ) {
355370
$generated_count = 0;
@@ -377,6 +392,12 @@ private function execute_coupon_generation( $valid_products, $gift_info, $params
377392

378393
/**
379394
* Create a single coupon
395+
*
396+
* @param array $valid_products Array of valid product objects.
397+
* @param array $gift_info Gift information array.
398+
* @param array $params Generation parameters.
399+
* @param int $current_number Current coupon number in batch.
400+
* @return bool True if coupon was created successfully, false otherwise.
380401
*/
381402
private function create_single_coupon( $valid_products, $gift_info, $params, $current_number ) {
382403
try {
@@ -409,6 +430,12 @@ private function create_single_coupon( $valid_products, $gift_info, $params, $cu
409430

410431
/**
411432
* Set coupon properties
433+
*
434+
* @param WC_Coupon $coupon The coupon object.
435+
* @param string $code The coupon code.
436+
* @param array $valid_products Array of valid product objects.
437+
* @param array $params Generation parameters.
438+
* @param int $current_number Current coupon number in batch.
412439
*/
413440
private function set_coupon_properties( $coupon, $code, $valid_products, $params, $current_number ) {
414441
// Create product names list for description.
@@ -438,6 +465,10 @@ private function set_coupon_properties( $coupon, $code, $valid_products, $params
438465

439466
/**
440467
* Set coupon metadata
468+
*
469+
* @param WC_Coupon $coupon The coupon object.
470+
* @param array $gift_info Gift information array.
471+
* @param array $params Generation parameters.
441472
*/
442473
private function set_coupon_metadata( $coupon, $gift_info, $params ) {
443474
// For free gift coupons, add the gift data.
@@ -468,6 +499,8 @@ private function handle_generation_delay( $current_number ) {
468499

469500
/**
470501
* Log coupon generation errors
502+
*
503+
* @param Exception $exception The exception that occurred.
471504
*/
472505
private function log_coupon_error( $exception ) {
473506
// Only log in debug mode.
@@ -485,6 +518,9 @@ private function log_coupon_error( $exception ) {
485518

486519
/**
487520
* Generate unique coupon code
521+
*
522+
* @param string $prefix Optional prefix for the coupon code.
523+
* @return string Generated coupon code.
488524
*/
489525
private function generate_coupon_code( $prefix = '' ) {
490526
$code_length = 12;
@@ -506,6 +542,8 @@ private function generate_coupon_code( $prefix = '' ) {
506542

507543
/**
508544
* Get products for dropdown
545+
*
546+
* @return array Array of product options for dropdown.
509547
*/
510548
private function get_products_for_dropdown() {
511549
// Use transient caching for performance.
@@ -568,6 +606,8 @@ public function admin_page() {
568606

569607
/**
570608
* Render admin form
609+
*
610+
* @param array $products Array of products for the dropdown.
571611
*/
572612
private function render_admin_form( $products ) {
573613
?>
@@ -591,6 +631,8 @@ private function render_admin_form( $products ) {
591631

592632
/**
593633
* Render product selection field
634+
*
635+
* @param array $products Array of products for the dropdown.
594636
*/
595637
private function render_product_selection_field( $products ) {
596638
?>

readme.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
114114
* **Improvement**: Removed deprecated load_plugin_textdomain() call as WordPress automatically handles translations for plugins hosted on WordPress.org.
115115
* **Improvement**: Updated all repository links to use lowercase format.
116116
* **Testing**: Added helper function for plugin load testing to improve compatibility with testing frameworks.
117+
* **Code Style and Documentation**: Addressed multiple code style issues, including whitespace, alignment, and indentation, to improve readability and maintainability.
118+
* **PHPDoc Blocks**: Added comprehensive PHPDoc blocks to all functions, ensuring all parameters and return values are clearly documented.
117119

118120
= 1.3.0 =
119121
* **Security Enhancement**: Replaced `wp_rand()` with `random_int()` for cryptographically secure coupon code generation.

0 commit comments

Comments
 (0)