$options The plugin options. * @return string The configured score, or the shipped default when the * stored value is missing, blank, or not a number. */ public static function forDisplay(array $options): string { $shippedDefault = self::shippedDefault(); if (!array_key_exists('auto_score', $options)) { return $shippedDefault; } $configured = $options['auto_score']; if (!is_scalar($configured)) { return $shippedDefault; } $configured = (string)$configured; if (!is_numeric($configured)) { return $shippedDefault; } return $configured; } /** * The same number as a float, for comparing a match score against the bar. * * @param array $options The plugin options. * @return float */ public static function asFloat(array $options): float { return (float)self::forDisplay($options); } /** * The auto_score value the plugin ships with, read from the defaults * rather than repeated as a literal so a change to the shipped bar does * not have to be made in three places. * * @return string */ private static function shippedDefault(): string { $defaults = ABJ_404_Solution_PluginLogicDefaults::defaults(); if (isset($defaults['auto_score']) && is_scalar($defaults['auto_score'])) { return (string)$defaults['auto_score']; } return '90'; } }