You are here

public function CouponCodeGenerator::validatePattern in Commerce Core 8.2

Validates the given pattern for the specified quantity.

Parameters

\Drupal\commerce_promotion\CouponCodePattern $pattern: The pattern.

int $quantity: The quantity.

Return value

bool TRUE if the pattern is valid, FALSE otherwise.

Overrides CouponCodeGeneratorInterface::validatePattern

File

modules/promotion/src/CouponCodeGenerator.php, line 29

Class

CouponCodeGenerator

Namespace

Drupal\commerce_promotion

Code

public function validatePattern(CouponCodePattern $pattern, $quantity = 1) {
  $character_set = $this
    ->getCharacterSet($pattern
    ->getType());
  $combinations = pow(count($character_set), $pattern
    ->getLength());
  return !($quantity > $combinations);
}