-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Currently it is possible to set a free plan with this config:
shq_features:
...
sets:
....
features:
feature_name:
...
packs:
50: ~
...This causes an empty array in the config that causes a lot of troubles in the code because we have to deal with an empty array.
What to do
Do not allow an empty configuration. Instead, require an explicit configuration set to 0:
shq_features:
...
sets:
....
features:
feature_name:
...
packs:
50:
EUR:
monthly: 0
yearly: 0
...v0.12.0
-
SerendipityHQ\Bundle\FeaturesBundle\DependencyInjection\Configurationnot allow an empty config - Revert changes made in c7b854f
Configuration.php
from
private function validateRecurringPrice(string $set, string $feature, array $price): void
{
// If emmpty, may be because it doesn't exist and the TreeBuilder created it as an empty array, else...
if (false === empty($price)) {
// ... It contains Currency codes: validate each one of them and their subscription periods
foreach ($price as $currency => $subscriptions) {
// Validate the currency
$this->validateCurrency($set, $feature, $currency);
// Validate the subscription periods
$this->validateSubscriptionPeriods($set, $feature, $currency, $subscriptions);
}
}
}to
private function validateRecurringPrice(string $set, string $feature, array $price): void
{
if (empty($price)) {
throw new InvalidConfigurationException(\Safe\sprintf("You MUST set a price for %s.features.%s.", $set, $feature));
}
// ... It contains Currency codes: validate each one of them and their subscription periods
foreach ($price as $currency => $subscriptions) {
// Validate the currency
$this->validateCurrency($set, $feature, $currency);
// Validate the subscription periods
$this->validateSubscriptionPeriods($set, $feature, $currency, $subscriptions);
}
}from
private function processPackages(array $packs, $subscriptionType)
{
$subscriptionHasFreePackage = false;
foreach ($packs as $numOfUnits => $prices) {
switch ($subscriptionType) {
case self::RECURRING:
$packs[$numOfUnits] = $this->processRecurringPrice($prices);
// If this is a free package
if (empty($prices)) {
// We have a free package so we haven't to create it
$subscriptionHasFreePackage = true;
}
break;
case self::UNATANTUM:
$packs[$numOfUnits] = $this->processUnatantumPrice($prices);
break;
}
}
// If we are processing a recurring feature that hasn't a free package...
if (self::RECURRING === $subscriptionType && false === $subscriptionHasFreePackage) {
// ... We have to create it with 0 $numOfUnits as we always need a free package for a subscribed feature
$packs[0] = [];
}
$packs['_pricesType'] = $this->pricesType;
return $packs;to
private function processPackages(array $packs, $subscriptionType)
{
$subscriptionHasFreePackage = false;
foreach ($packs as $numOfUnits => $prices) {
switch ($subscriptionType) {
case self::RECURRING:
$packs[$numOfUnits] = $this->processRecurringPrice($prices);
// If this is a free package
if (empty($prices)) {
// We have a free package so we haven't to create it
$subscriptionHasFreePackage = true;
}
break;
case self::UNATANTUM:
$packs[$numOfUnits] = $this->processUnatantumPrice($prices);
break;
}
}
$packs['_pricesType'] = $this->pricesType;
return $packs;Also, understand why we always need a free package for subscribed features.