this is not the message matching the check you do. if $child must be NodeInterface, you could typehint it. if you want to check for parent, you should change the if condition.