input === '') { return self::RESPONSE_SAY_NOTHING; } if ($this->isQuestion() && $this->isYelling()) { return self::RESPONSE_YELLING_QUESTION; } if ($this->isQuestion()) { return self::RESPONSE_QUESTION; } if ($this->isYelling()) { return self::RESPONSE_YELLING; } return self::RESPONSE_DEFAULT; } final private function __construct(string $input) { $this->input = $input; } private function isQuestion(): bool { return (bool) preg_match('/.+\?/', $this->input); } private function isYelling(): bool { return (bool) preg_match('/.+!/', $this->input); } }