the second parameter "$query" is very dirty. You should try to remove it if you can. Maybe with an other intermediate protected method.