Fixes #6835 and remove some phpstorm warnings