/**
  * @param AttributeMetadataInterface $attributeMetadata
  *
  * @return mixed
  */
 public function guess(AttributeMetadataInterface $attributeMetadata)
 {
     $value = null;
     $type = null;
     if (true === ($isDoctrine = isset($attributeMetadata->getTypes()[0]))) {
         $type = $attributeMetadata->getTypes()[0];
     }
     // Guess associations
     if ($isDoctrine && 'object' === $type->getType() && 'DateTime' !== $type->getClass()) {
         $class = $type->isCollection() ? $type->getCollectionType()->getClass() : $type->getClass();
         $resource = $this->resourceCollection->getResourceForEntity($class);
         $classMetadata = $this->classMetadataFactory->getMetadataFor($resource->getEntityClass(), $resource->getNormalizationGroups(), $resource->getDenormalizationGroups(), $resource->getValidationGroups());
         $id = $this->guess($classMetadata->getIdentifier());
         $value = $this->iriConverter->getIriFromResource($resource) . '/' . $id;
         if ($type->isCollection()) {
             $value = [$value];
         }
     }
     // Guess by faker
     if (null === $value) {
         try {
             $value = call_user_func([$this->generator, $attributeMetadata->getName()]);
         } catch (\InvalidArgumentException $e) {
         }
     }
     // Guess by field name
     if (null === $value) {
         $value = $this->guessFormat(Inflector::tableize($attributeMetadata->getName()));
     }
     // Guess by Doctrine type
     if (null === $value && $isDoctrine) {
         switch ($type->getType()) {
             case 'string':
                 $value = $this->generator->sentence;
                 break;
             case 'int':
                 $value = $this->generator->numberBetween;
                 break;
             case 'bool':
                 $value = $this->generator->boolean;
                 break;
             case 'object':
                 if ('DateTime' !== $type->getClass()) {
                     throw new \InvalidArgumentException(sprintf('Unknown Doctrine object type %s in field %s', $type->getClass(), $attributeMetadata->getName()));
                 }
                 $value = $this->generator->dateTime;
                 break;
         }
     }
     return $this->clean($value);
 }
 /**
  * Parses an attribute.
  *
  * @param ResourceInterface          $resource
  * @param AttributeMetadataInterface $attributeMetadata
  * @param string                     $io
  * @param Type|null                  $type
  *
  * @return array
  */
 private function parseAttribute(ResourceInterface $resource, AttributeMetadataInterface $attributeMetadata, $io, Type $type = null)
 {
     $data = array('dataType' => null, 'required' => $attributeMetadata->isRequired(), 'description' => $attributeMetadata->getDescription(), 'readonly' => !$attributeMetadata->isWritable());
     if (null == $type) {
         if (!isset($attributeMetadata->getTypes()[0])) {
             // Default to string
             $data['dataType'] = DataTypes::STRING;
             return $data;
         }
         // Use the first type found as primary
         $type = $attributeMetadata->getTypes()[0];
     }
     if ($type->isCollection()) {
         $data['actualType'] = DataTypes::COLLECTION;
         if ($collectionType = $type->getCollectionType()) {
             $subAttribute = $this->parseAttribute($resource, $attributeMetadata, $io, $collectionType);
             if (self::IRI === $subAttribute['dataType']) {
                 $data['dataType'] = 'array of IRIs';
                 $data['subType'] = DataTypes::STRING;
                 return $data;
             }
             $data['subType'] = $subAttribute['subType'];
             $data['children'] = $subAttribute['children'];
         }
         return $data;
     }
     $phpType = $type->getType();
     if ('object' === $phpType) {
         $class = $type->getClass();
         if ('DateTime' === $class) {
             $data['dataType'] = DataTypes::DATETIME;
             $data['format'] = sprintf('{DateTime %s}', \DateTime::ATOM);
             return $data;
         }
         if (self::OUT_PREFIX === $io && $attributeMetadata->isNormalizationLink() || self::IN_PREFIX === $io && $attributeMetadata->isDenormalizationLink()) {
             $data['dataType'] = self::IRI;
             $data['actualType'] = DataTypes::STRING;
             return $data;
         }
         $data['actualType'] = DataTypes::MODEL;
         $data['subType'] = $class;
         $data['children'] = $resource->getEntityClass() === $class ? [] : $this->parseClass($resource, $class, $io);
         return $data;
     }
     $data['dataType'] = isset(self::$typeMap[$type->getType()]) ? self::$typeMap[$type->getType()] : DataTypes::STRING;
     return $data;
 }
 /**
  * Gets the range of the property.
  *
  * @param AttributeMetadataInterface $attributeMetadata
  *
  * @return string|null
  */
 private function getRange(AttributeMetadataInterface $attributeMetadata)
 {
     if (isset($attributeMetadata->getTypes()[0])) {
         $type = $attributeMetadata->getTypes()[0];
         if ($type->isCollection() && ($collectionType = $type->getCollectionType())) {
             $type = $collectionType;
         }
         switch ($type->getType()) {
             case 'string':
                 return 'xmls:string';
             case 'int':
                 return 'xmls:integer';
             case 'float':
                 return 'xmls:double';
             case 'bool':
                 return 'xmls:boolean';
             case 'object':
                 $class = $type->getClass();
                 if ($class) {
                     if ('DateTime' === $class) {
                         return 'xmls:dateTime';
                     }
                     if ($resource = $this->resourceCollection->getResourceForEntity($type->getClass())) {
                         return sprintf('#%s', $resource->getShortName());
                     }
                 }
                 break;
         }
     }
 }