you could just `return $name`

then we also can get rid of the "else" below and just have another if. more compact and easy to read.

and get rid of the top $path = null