Skip to content

refactor(promo-codes): replace boolval() with filter_var(FILTER_VALIDATE_BOOLEAN) in SummitPromoCodeFactory #527

@coderabbitai

Description

@coderabbitai

Summary

In app/Models/Foundation/Summit/Factories/SummitPromoCodeFactory.php, approximately 8 calls to boolval() are used to coerce boolean fields (e.g. allows_to_delegate, allows_to_reassign, auto_apply) from user/CSV input into boolean values.

Problem

boolval("false") returns true in PHP because any non-empty string (other than "0") casts to true. This means CSV imports that provide auto_apply=false (or similar string values) will be incorrectly persisted as true.

filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) correctly recognises string values like "false", "0", "no", "off" as boolean false.

Proposed Fix

Replace every boolval($data[...] call in SummitPromoCodeFactory::populate() with:

filter_var($data['<field>'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)

Affected fields (approx. lines):

  • allows_to_delegate (~line 172)
  • allows_to_reassign (~line 175)
  • auto_apply in MemberSummitRegistrationPromoCode branch
  • auto_apply in SpeakerSummitRegistrationPromoCode branch
  • auto_apply in MemberSummitRegistrationDiscountCode branch
  • auto_apply in SpeakerSummitRegistrationDiscountCode branch
  • auto_apply in DomainAuthorizedSummitRegistrationDiscountCode branch
  • auto_apply in DomainAuthorizedSummitRegistrationPromoCode branch

Context

Identified during review of PR #525 (#525 (comment)). The fix was deferred from that PR to avoid a partial/inconsistent change — all occurrences should be updated together in a single cleanup PR.

Requested by: @caseylocker

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions