JavaScript date format string to php date format string convert
I don't see the need to do so much dynamic work.  I would establish a lookup array to access.  This will be clean, direct, and easy to maintain.  If the incoming format is not found, just fallback to m-d-Y using the null coalescing operator.
private $formatLookup = [
    'YYYY-MM-DD' =&gt; 'Y-m-d',
    'YYYY/MM/DD' =&gt; 'Y/m/d',
];

public function dateFormatStringConvert(string $format) : string
{
    return $this-&gt;formatLookup[$format] ?? 'm-d-Y';
}

With this setup, you never need to touch the processing method, you only need to maintain the lookup array.