You are here

public function SensorResult::toNumber in Monitoring 7

Same name and namespace in other branches
  1. 8 src/Result/SensorResult.php \Drupal\monitoring\Result\SensorResult::toNumber()

Casts/processes the sensor value into numeric representation.

Return value

number Numeric sensor value.

Overrides SensorResultInterface::toNumber

1 call to SensorResult::toNumber()
SensorResult::toArray in lib/Drupal/monitoring/Result/SensorResult.php
Returns sensor result data as array.

File

lib/Drupal/monitoring/Result/SensorResult.php, line 376
Contains \Drupal\monitoring\Result\SensorResult.

Class

SensorResult
Generic container for the sensor result.

Namespace

Drupal\monitoring\Result

Code

public function toNumber() {
  $sensor_value = $this
    ->getValue();
  if (is_numeric($sensor_value)) {
    return $sensor_value;
  }

  // Casting to int should be good enough as boolean will get casted to 0/1
  // and string as well.
  return (int) $sensor_value;
}