Use the new normalizeBoolean helper (#3406)

* Use the new normalizeBoolean helper and fix a bug

* Also normalize `$convert`
This commit is contained in:
Yağızhan Burak Yakar authored and GitHub committed 2026-04-08 18:54:53 +03:00
1 parent 649e41e950
commit 049a1bd4d9
6 files changed
+17 -11

No files matched your search

+3 -2
View File
@@ -13,6 +13,7 @@ declare(strict_types=1);
namespace Box\Mod\Currency\Api;
use Box\Mod\Currency\Entity\Currency;
use FOSSBilling\Tools;
class Guest extends \Api_Abstract
{
@@ -75,8 +76,8 @@ class Guest extends \Api_Abstract
$c = $this->get($data);
$price = $data['price'] ?? 0;
$convert = $data['convert'] ?? true;
$without_currency = (bool) ($data['without_currency'] ?? false);
$convert = Tools::normalizeBoolean($data['convert'] ?? true, true);
$without_currency = Tools::normalizeBoolean($data['without_currency'] ?? false);
$p = floatval($price);
if ($convert) {
+3 -2
View File
@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Box\Mod\Extension\Api;
use FOSSBilling\Tools;
use FOSSBilling\Validation\Api\RequiredParams;
class Admin extends \Api_Abstract
@@ -87,8 +88,8 @@ class Admin extends \Api_Abstract
*/
public function languages(array $data): array
{
$data['disabled'] = (bool) ($data['disabled'] ?? false);
$data['details'] = (bool) ($data['details'] ?? true);
$data['disabled'] = Tools::normalizeBoolean($data['disabled'] ?? false);
$data['details'] = Tools::normalizeBoolean($data['details'] ?? true, true);
return \FOSSBilling\i18n::getLocales($data['details'], $data['disabled']);
}
+2 -1
View File
@@ -14,6 +14,7 @@ namespace Box\Mod\Invoice;
use FOSSBilling\Environment;
use FOSSBilling\InjectionAwareInterface;
use FOSSBilling\Tools;
class ServiceTransaction implements InjectionAwareInterface
{
@@ -81,7 +82,7 @@ class ServiceTransaction implements InjectionAwareInterface
{
$this->di['events_manager']->fire(['event' => 'onBeforeAdminTransactionCreate', 'params' => $data]);
$skip_validation = isset($data['skip_validation']) && (bool) $data['skip_validation'];
$skip_validation = Tools::normalizeBoolean($data['skip_validation'] ?? false);
if (!empty($data['gateway_id'])) {
try {
$this->di['db']->getExistingModelById('PayGateway', $data['gateway_id'], 'Gateway was not found');
+6 -5
View File
@@ -16,6 +16,7 @@ declare(strict_types=1);
namespace Box\Mod\Order\Api;
use FOSSBilling\Tools;
use FOSSBilling\Validation\Api\RequiredParams;
class Admin extends \Api_Abstract
@@ -149,7 +150,7 @@ class Admin extends \Api_Abstract
public function suspend($data)
{
$order = $this->_getOrder($data);
$skip_event = isset($data['skip_event']) && (bool) $data['skip_event'];
$skip_event = Tools::normalizeBoolean($data['skip_event'] ?? false);
$reason = $data['reason'] ?? null;
@@ -181,7 +182,7 @@ class Admin extends \Api_Abstract
public function cancel($data)
{
$order = $this->_getOrder($data);
$skip_event = isset($data['skip_event']) && (bool) $data['skip_event'];
$skip_event = Tools::normalizeBoolean($data['skip_event'] ?? false);
$reason = $data['reason'] ?? null;
@@ -213,8 +214,8 @@ class Admin extends \Api_Abstract
public function delete($data)
{
$order = $this->_getOrder($data);
$delete_addons = isset($data['delete_addons']) && (bool) $data['delete_addons'];
$forceDelete = (bool) ($data['force_delete'] ?? false);
$delete_addons = Tools::normalizeBoolean($data['delete_addons'] ?? false);
$forceDelete = Tools::normalizeBoolean($data['force_delete'] ?? false);
if ($delete_addons) {
$list = $this->getService()->getOrderAddonsList($order);
@@ -388,7 +389,7 @@ class Admin extends \Api_Abstract
#[RequiredParams(['ids' => 'Order IDs were not passed'])]
public function batch_delete($data): bool
{
$delete_addons = isset($data['delete_addons']) && (bool) $data['delete_addons'];
$delete_addons = Tools::normalizeBoolean($data['delete_addons'] ?? false);
foreach ($data['ids'] as $id) {
$this->delete(['id' => $id, 'delete_addons' => $delete_addons]);
+2 -1
View File
@@ -14,6 +14,7 @@ namespace Box\Mod\Servicedownloadable;
use FOSSBilling\Environment;
use FOSSBilling\InjectionAwareInterface;
use FOSSBilling\Tools;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;
use Symfony\Component\HttpFoundation\HeaderUtils;
@@ -408,7 +409,7 @@ class Service implements InjectionAwareInterface
public function saveProductConfig(\Model_Product $productModel, $data): bool
{
$config = json_decode($productModel->config ?? '', true) ?: [];
$config['update_orders'] = isset($data['update_orders']) && (bool) $data['update_orders'];
$config['update_orders'] = Tools::normalizeBoolean($data['update_orders'] ?? false);
$productModel->config = json_encode($config);
$productModel->updated_at = date('Y-m-d H:i:s');
$this->di['db']->store($productModel);
+1
View File
@@ -289,6 +289,7 @@ class Admin extends \Api_Abstract
$existingConfig = json_decode($model->config ?? '', true) ?? [];
$data['config'] = $existingConfig;
$data['config']['userprefix'] = $data['userprefix'] ?? ($existingConfig['userprefix'] ?? null);
$data['config']['tls_verify'] = Tools::normalizeBoolean($data['tls_verify'] ?? ($existingConfig['tls_verify'] ?? true), true);
return (bool) $service->updateServer($model, $data);