* @license MIT */ class Greeting { private array $greetings; public function __construct() { $this->greetings = [ 03 => 'morning', 12 => 'afternoon', 16 => 'evening', 19 => 'night' ]; } /** * Select the appropriate greeting word based on the time of day and * what has been defined in $this->greetings. * * @return string The greeting word selected. */ public function get_greeting(): string { krsort($this->greetings); foreach ($this->greetings as $key => $value) { if (date('H', time()) >= $key) { return $value; } } } }