/**
  * Create AttributeMetadata Data object from the Attribute Model
  *
  * @param \Magento\Customer\Model\Attribute $attribute
  * @return \Magento\Customer\Api\Data\AttributeMetadataInterface
  */
 public function createMetadataAttribute($attribute)
 {
     $options = [];
     if ($attribute->usesSource()) {
         foreach ($attribute->getSource()->getAllOptions() as $option) {
             $optionDataObject = $this->optionFactory->create();
             if (!is_array($option['value'])) {
                 $optionDataObject->setValue($option['value']);
             } else {
                 $optionArray = [];
                 foreach ($option['value'] as $optionArrayValues) {
                     $optionObject = $this->optionFactory->create();
                     $this->dataObjectHelper->populateWithArray($optionObject, $optionArrayValues, '\\Magento\\Customer\\Api\\Data\\OptionInterface');
                     $optionArray[] = $optionObject;
                 }
                 $optionDataObject->setOptions($optionArray);
             }
             $optionDataObject->setLabel($option['label']);
             $options[] = $optionDataObject;
         }
     }
     $validationRules = [];
     foreach ($attribute->getValidateRules() as $name => $value) {
         $validationRule = $this->validationRuleFactory->create()->setName($name)->setValue($value);
         $validationRules[] = $validationRule;
     }
     return $this->attributeMetadataFactory->create()->setAttributeCode($attribute->getAttributeCode())->setFrontendInput($attribute->getFrontendInput())->setInputFilter((string) $attribute->getInputFilter())->setStoreLabel($attribute->getStoreLabel())->setValidationRules($validationRules)->setIsVisible((bool) $attribute->getIsVisible())->setIsRequired((bool) $attribute->getIsRequired())->setMultilineCount((int) $attribute->getMultilineCount())->setDataModel((string) $attribute->getDataModel())->setOptions($options)->setFrontendClass($attribute->getFrontend()->getClass())->setFrontendLabel($attribute->getFrontendLabel())->setNote((string) $attribute->getNote())->setIsSystem((bool) $attribute->getIsSystem())->setIsUserDefined((bool) $attribute->getIsUserDefined())->setBackendType($attribute->getBackendType())->setSortOrder((int) $attribute->getSortOrder())->setIsUsedInGrid($attribute->getIsUsedInGrid())->setIsVisibleInGrid($attribute->getIsVisibleInGrid())->setIsFilterableInGrid($attribute->getIsFilterableInGrid())->setIsSearchableInGrid($attribute->getIsSearchableInGrid());
 }