本文整理汇总了PHP中Webmozart\Assert\Assert::allInteger方法的典型用法代码示例。如果您正苦于以下问题:PHP Assert::allInteger方法的具体用法?PHP Assert::allInteger怎么用?PHP Assert::allInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Webmozart\Assert\Assert
的用法示例。
在下文中一共展示了Assert::allInteger方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param int $totalSales
* @param int $numberOfNewOrders
* @param int $numberOfNewCustomers
*/
public function __construct($totalSales, $numberOfNewOrders, $numberOfNewCustomers)
{
Assert::allInteger([$totalSales, $numberOfNewCustomers, $numberOfNewOrders]);
$this->totalSales = $totalSales;
$this->numberOfNewOrders = $numberOfNewOrders;
$this->numberOfNewCustomers = $numberOfNewCustomers;
}
示例2: distribute
/**
* {@inheritdoc}
*/
public function distribute(array $integers, $amount)
{
Assert::allInteger($integers);
Assert::integer($amount);
$total = array_sum($integers);
$distributedAmounts = [];
foreach ($integers as $element) {
$distributedAmounts[] = (int) round($element * $amount / $total, 0, PHP_ROUND_HALF_DOWN);
}
$missingAmount = $amount - array_sum($distributedAmounts);
for ($i = 0; $i < abs($missingAmount); $i++) {
$distributedAmounts[$i] += $missingAmount >= 0 ? 1 : -1;
}
return $distributedAmounts;
}