Rewrite to decrease number of nested levels.

Signed-off-by: Hugues Peccatte <hugues.peccatte@gmail.com>
Merge pull request #781 from Tithugues/phpcs

Rewrite to decrease number of nested levels.