This ugly as hell. Why not just use `$dir = rtrim($dir, '/')`?