Guard against "HEAD only" formulae

Some formulae are "HEAD only". They are in a [separate repository](https://github.com/Homebrew/homebrew-headonly) but can easily be added using `brew tap homebrew/headonly`. This solves an issue where `Formula#stable` returns `nil` for these formulae.

Also replaces the deprecated `Formula.factory` method with `Formula[]`.