You can see that isset($variables[$type][$key]['#theme']) should also be conditional for the second part of the OR operator, so I believe the solution is to put paranthesis and always check the isset :P: