fabpot/PHP-CS-Fixer — pull request #611 by bgotink (2014-09-30 15:43:40+00:00)
Title: implemented YodaConditions fixer

See #598.

I know the code is missing comments, but I wanted feedback on the code first.

Modus operandi:

The documentation on operator precedence ([here][precedense_doc]) shows PHP has two different levels of comparison:
- `<`, `<=`, `>`, `>=`
- `==`, `!=`, `===`, `!==`, `<>`
The latter of the two has a lower precedence.

The fixer does the following for both kinds of comparison, with the higher precedence coming first:
- iterate backwards over the tokens until a comparison is found
- find the left-hand side and right-hand side of the comparison
- run the entire process over both left-hand and right-hand sides
- if the left-hand isn't a "simple" expression and the right-hand is, switch sides
- skip all tokens that were part of this comparison

It looks for the left-hand and right-hand sides by going backward/forward starting at the comparison itself, using:
- define `$level` as the level of parentheses the current token is in, with the comparison token being at `0`
- if `$level` is below zero, we've found the end
- if `$level` isn't zero, we haven't found the end
- if the current token has a lower precedence, we've found the end
- if the current token is a `,` or `;`, we've found the end
- if the current token is a keyword like `return`, `case`, `throw`, `goto`, we've found the end

Deciding whether or not a side is "simple" is currently implemented as checking whether the side is an integer (`T_LNUMBER`), a floating point number (`T_DNUMBER`), a string( `T_CONSTANT_ENCAPSED_STRING`) or any keyword (`T_STRING`).

[precedense_doc]: http://php.net/manual/en/language.operators.precedence.php