You can replace by:
return ($magentoCategoryId = $this->getMagentoCategoryId($category, $magentoUrl)) !== null && isset($magentoCategories[$magentoCategoryId]