I think you should move the assignment of ``$entityKey`` before the condition. Having 2 different assignments in the same condition evaluation makes it hard to read