I just refactored the code as you suggested: https://github.com/yiisoft/yii2/commit/3cc7fcb510e464cd5e2d3bbd20b4344534540aa5