Automattic\WooCommerce\Internal\Api

QueryComplexityRule::add_saturating │ private │ WC 1.0

Add two complexity scores, saturating at {@see self::COMPLEXITY_CEILING}.

Method of the class: QueryComplexityRule{}

No Hooks.

Returns

int. The saturated sum.

Usage

// private - for code of main (parent) class only
$result = $this->add_saturating( $a, $b ): int;
$a(int) (required)
First score.
$b(int) (required)
Second score.

QueryComplexityRule::add_saturating() code WC 11.1.2

private function add_saturating( int $a, int $b ): int {
	$sum = $a + $b;

	// An int overflow turns the sum into a float, which is also above the ceiling.
	return $sum > self::COMPLEXITY_CEILING ? self::COMPLEXITY_CEILING : (int) $sum;
}