src/TypesGenerator.php
private function generateField(array $config, array $class, \EasyRdf_Resource $type, $typeName, $propertyName, \EasyRdf_Resource $property = null)
    {
        $typeConfig = $config['types'][$typeName] ?? null;
        $typesDefined = !empty($config['types']);

        // Warn when property are not part of GoodRelations
        if ($config['checkIsGoodRelations']) {
            if (!$this->goodRelationsBridge->exist($propertyName)) {
                $this->logger->warning(sprintf('The property "%s" (type "%s") is not part of GoodRelations.', $propertyName, $type->localName()));
            }
        }

        // Ignore or warn when properties are legacy
        if (!empty($property) && preg_match('/legacy spelling/', (string) $property->get('rdfs:comment'))) {
            if (isset($typeConfig['properties'])) {
                $this->logger->warning(sprintf('The property "%s" (type "%s") is legacy.', $propertyName, $type->localName()));
            } else {
                $this->logger->info(sprintf('The property "%s" (type "%s") is legacy. Ignoring.', $propertyName, $type->localName()));

                return $class;
            }
        }

        $propertyConfig = $typeConfig['properties'][$propertyName] ?? null;

        $ranges = [];
        if (isset($propertyConfig['range']) && $propertyConfig['range']) {
            $ranges[] = $propertyConfig['range'];
        } elseif (!empty($property)) {
            foreach ($property->all(self::SCHEMA_ORG_RANGE) as $range) {
                if (!$typesDefined || $this->isDatatype($range->localName()) || isset($config['types'][$range->localName()])) {
                    $ranges[] = $range->localName();
                }
            }
        }

        $numberOfRanges = count($ranges);
        if (0 === $numberOfRanges) {
            $this->logger->error(sprintf('The property "%s" (type "%s") has an unknown type. Add its type to the config file.', $propertyName, $type->localName()));
        } else {
            if ($numberOfRanges > 1) {
                $this->logger->warning(sprintf('The property "%s" (type "%s") has several types. Using the first one ("%s") or possible options("%s").', $propertyName, $type->localName(), reset($ranges), implode('", "', $ranges)));
            }

            $cardinality = $propertyConfig['cardinality'] ?? false;
            if (!$cardinality || CardinalitiesExtractor::CARDINALITY_UNKNOWN === $cardinality) {
                $cardinality = $property ? $this->cardinalities[$propertyName] : CardinalitiesExtractor::CARDINALITY_1_1;
            }

            $isArray = in_array($cardinality, [
                CardinalitiesExtractor::CARDINALITY_0_N,
                CardinalitiesExtractor::CARDINALITY_1_N,
                CardinalitiesExtractor::CARDINALITY_N_N,
            ], true);

            if (isset($propertyConfig['nullable']) && false === $propertyConfig['nullable']) {
                $isNullable = false;
            } else {
                $isNullable = !in_array($cardinality, [
                    CardinalitiesExtractor::CARDINALITY_1_1,
                    CardinalitiesExtractor::CARDINALITY_1_N,
                ], true);
            }

            $columnPrefix = false;
            $isEmbedded = $propertyConfig['embedded'] ?? false;

            if (true === $isEmbedded) {
                $columnPrefix = $propertyConfig['columnPrefix'] ?? false;
            }

            $class['fields'][$propertyName] = [
                'name' => $isArray ? Inflector::pluralize($propertyName) : Inflector::singularize($propertyName),
                'resource' => $property,
                'range' => $ranges[0],
                'cardinality' => $cardinality,
                'ormColumn' => $propertyConfig['ormColumn'] ?? null,
                'isArray' => $isArray,
                'isReadable' => $propertyConfig['readable'] ?? true,
                'isWritable' => $propertyConfig['writable'] ?? true,
                'isNullable' => $isNullable,
                'isUnique' => isset($propertyConfig['unique']) && $propertyConfig['unique'],
                'isCustom' => empty($property),
                'isEmbedded' => $isEmbedded,
                'columnPrefix' => $columnPrefix,
                'isId' => false,
            ];

            if ($isArray) {
                $class['hasConstructor'] = true;

                if ($config['doctrine']['useCollection'] && !in_array(ArrayCollection::class, $class['uses'], true)) {
                    $class['uses'][] = ArrayCollection::class;
                    $class['uses'][] = Collection::class;
                }
            }
        }

        return $class;
    }
private function generateField(array $config, array $class, \EasyRdf_Resource $type, $typeName, $propertyName, \EasyRdf_Resource $property = null)
    {
        $typeConfig = $config['types'][$typeName] ?? null;
        $typesDefined = !empty($config['types']);

        // Warn when property are not part of GoodRelations
        if ($config['checkIsGoodRelations']) {
            if (!$this->goodRelationsBridge->exist($propertyName)) {
                $this->logger->warning(sprintf('The property "%s" (type "%s") is not part of GoodRelations.', $propertyName, $type->localName()));
            }
        }

        // Ignore or warn when properties are legacy
        if (!empty($property) && preg_match('/legacy spelling/', (string) $property->get('rdfs:comment'))) {
            if (isset($typeConfig['properties'])) {
                $this->logger->warning(sprintf('The property "%s" (type "%s") is legacy.', $propertyName, $type->localName()));
            } else {
                $this->logger->info(sprintf('The property "%s" (type "%s") is legacy. Ignoring.', $propertyName, $type->localName()));

                return $class;
            }
        }

        $propertyConfig = $typeConfig['properties'][$propertyName] ?? null;

        $ranges = [];
        if (isset($propertyConfig['range']) && $propertyConfig['range']) {
            $ranges[] = $propertyConfig['range'];
        } elseif (!empty($property)) {
            foreach ($property->all(self::SCHEMA_ORG_RANGE) as $range) {
                if (!$typesDefined || $this->isDatatype($range->localName()) || isset($config['types'][$range->localName()])) {
                    $ranges[] = $range->localName();
                }
            }
        }

        $numberOfRanges = count($ranges);
        if (0 === $numberOfRanges) {
            $this->logger->error(sprintf('The property "%s" (type "%s") has an unknown type. Add its type to the config file.', $propertyName, $type->localName()));
        } else {
            if ($numberOfRanges > 1) {
                $this->logger->warning(sprintf('The property "%s" (type "%s") has several types. Using the first one ("%s") or possible options("%s").', $propertyName, $type->localName(), reset($ranges), implode('", "', $ranges)));
            }

            $cardinality = $propertyConfig['cardinality'] ?? false;
            if (!$cardinality || CardinalitiesExtractor::CARDINALITY_UNKNOWN === $cardinality) {
                $cardinality = $property ? $this->cardinalities[$propertyName] : CardinalitiesExtractor::CARDINALITY_1_1;
            }

            $isArray = in_array($cardinality, [
                CardinalitiesExtractor::CARDINALITY_0_N,
                CardinalitiesExtractor::CARDINALITY_1_N,
                CardinalitiesExtractor::CARDINALITY_N_N,
            ], true);

            if (isset($propertyConfig['nullable']) && false === $propertyConfig['nullable']) {
                $isNullable = false;
            } else {
                $isNullable = !in_array($cardinality, [
                    CardinalitiesExtractor::CARDINALITY_1_1,
                    CardinalitiesExtractor::CARDINALITY_1_N,
                ], true);
            }

            $columnPrefix = false;
            $isEmbedded = $propertyConfig['embedded'] ?? false;

            if (true === $isEmbedded) {
                $columnPrefix = $propertyConfig['columnPrefix'] ?? false;
            }

            $class['fields'][$propertyName] = [
                'name' => $isArray ? Inflector::pluralize($propertyName) : Inflector::singularize($propertyName),
                'resource' => $property,
                'range' => $ranges[0],
                'cardinality' => $cardinality,
                'ormColumn' => $propertyConfig['ormColumn'] ?? null,
                'isArray' => $isArray,
                'isReadable' => $propertyConfig['readable'] ?? true,
                'isWritable' => $propertyConfig['writable'] ?? true,
                'isNullable' => $isNullable,
                'isUnique' => isset($propertyConfig['unique']) && $propertyConfig['unique'],
                'isCustom' => empty($property),
                'isEmbedded' => $isEmbedded,
                'columnPrefix' => $columnPrefix,
                'isId' => false,
            ];

            if ($isArray) {
                $class['hasConstructor'] = true;

                if ($config['doctrine']['useCollection'] && !in_array(ArrayCollection::class, $class['uses'], true)) {
                    $class['uses'][] = ArrayCollection::class;
                    $class['uses'][] = Collection::class;
                }
            }
        }

        return $class;
    }
Updates generated $class with given field config.

@param array                  $config
@param array                  $class
@param \EasyRdf_Resource      $type
@param string                 $typeName
@param string                 $propertyName
@param \EasyRdf_Resource|null $property

@return array $class