I've been having a lot of trouble finding a decent free formatter for PHP as well, there are many online and command-line tools but they just don't seem to work for some reason, the results are all still full of bad indenting with combinations of tabs and spaces, and they never get the braces the way you want them!
I tried the snippet above and that didn't work for me either, indenting still full of spaces and tabs all mixed up.
So I've had a go at writing a simple one too, this one just uses all regex, no fancy compiler magic, so it's possible that it could break things, and is still very beta and being tested on various messy code. The interface is very basic at the moment too, but should improve over the next few days.
It's hardwired for MediaWiki's conventions, but you can modify it pretty easily (I may add options later).
https://www.organicdesign.co.nz/Special:CodeTidy