Okay, so I still think we can replace this `if` condition with a regex:

`$path = preg_replace('/\' . DIRECTORY_SEPARATOR . '$/', '', $path);`