public function ensureEnd(string $suffix) : static { if (!$this->endsWith($suffix)) { return $this->append($suffix); } $suffix = preg_quote($suffix); $regex = '{(' . $suffix . ')(?:' . $suffix . ')++$}D'; return $this->replaceMatches($regex . ($this->ignoreCase ? 'i' : ''), '$1'); }