= 0). * @param int $high_below Scaled high boundary. * @param int $warning_below Scaled warning boundary (= Safe floor). */ public function __construct( $critical_below, $high_below, $warning_below ) { $critical_below = (int) $critical_below; $high_below = (int) $high_below; $warning_below = (int) $warning_below; if ( $critical_below < 0 ) { throw new InvalidArgumentException( 'critical_below must be >= 0' ); } if ( $high_below <= $critical_below ) { throw new InvalidArgumentException( 'high_below must be > critical_below' ); } if ( $warning_below <= $high_below ) { throw new InvalidArgumentException( 'warning_below must be > high_below' ); } $this->critical_below = $critical_below; $this->high_below = $high_below; $this->warning_below = $warning_below; } /** * Default Free/Pro global profile. * * @return ThresholdProfile */ public static function defaults() { $d = Constants::default_thresholds(); return new self( $d['critical_below'], $d['high_below'], $d['warning_below'] ); } /** * Parse percent string with max 4 decimal places into scaled int. * * @param string $percent e.g. "10" or "3.5". * @return int */ public static function percent_to_scaled( $percent ) { $percent = trim( (string) $percent ); if ( ! preg_match( '/^\d+(\.\d{1,4})?$/', $percent ) ) { throw new InvalidArgumentException( 'threshold percent accepts max 4 decimal places' ); } $parts = explode( '.', $percent, 2 ); $whole = (int) $parts[0]; $frac = isset( $parts[1] ) ? str_pad( $parts[1], 4, '0', STR_PAD_RIGHT ) : '0000'; return ( $whole * Constants::THRESHOLD_SCALE ) + (int) $frac; } /** * @return array{critical_below:int,high_below:int,warning_below:int} */ public function to_array() { return array( 'critical_below' => $this->critical_below, 'high_below' => $this->high_below, 'warning_below' => $this->warning_below, ); } /** * @return int */ public function critical_below() { return $this->critical_below; } /** * @return int */ public function high_below() { return $this->high_below; } /** * @return int */ public function warning_below() { return $this->warning_below; } }