You can replace these 5 lines by:
$this->globalContext['create'] = !$this->magentoAttributeExists($attribute, $magentoAttributes)