Cyclomatic complexity

Many of the PHPMD warnings have been dealt with in this pull request.

There are many rather large refactorings here, touching almost all of the PHP code, so it's possible that something subtle will be broken.

The PHP file audit fails now because BMAttack has no classes. However, it has an abstract class. Can we change the audit please to allow this?