Coding standard: white space missing after `foreach` (and many other occurrences in your code). Use php-cs-fixer before committing.