Skip to content

Commit

Permalink
Reduce deprecations due to FieldMapping array access (for properties …
Browse files Browse the repository at this point in the history
…named $fieldMapping)
  • Loading branch information
Jean85 committed Oct 18, 2024
1 parent df96939 commit 4347cff
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 57 deletions.
4 changes: 2 additions & 2 deletions src/Blameable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function readExtendedMetadata($meta, array &$config)
if (isset($mapping['fields'])) {
foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) {
if (isset($fieldMapping['gedmo']['blameable'])) {
$mappingProperty = $fieldMapping['gedmo']['blameable'];
$mappingProperty = $fieldMapping->gedmo->blameable ?? $fieldMapping['gedmo']['blameable'];
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'string' or a reference in class - {$meta->getName()}");
}
Expand Down Expand Up @@ -86,7 +86,7 @@ public function readExtendedMetadata($meta, array &$config)
if (isset($mapping['manyToOne'])) {
foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $fieldMapping) {
if (isset($fieldMapping['gedmo']['blameable'])) {
$mappingProperty = $fieldMapping['gedmo']['blameable'];
$mappingProperty = $fieldMapping->gedmo->blameable ?? $fieldMapping['gedmo']['blameable'];
if (!$meta->isSingleValuedAssociation($field)) {
throw new InvalidMappingException("Association - [{$field}] is not valid, it must be a one-to-many relation or a string field - {$meta->getName()}");
}
Expand Down
4 changes: 2 additions & 2 deletions src/IpTraceable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function readExtendedMetadata($meta, array &$config)
if (isset($mapping['fields'])) {
foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) {
if (isset($fieldMapping['gedmo']['ipTraceable'])) {
$mappingProperty = $fieldMapping['gedmo']['ipTraceable'];
$mappingProperty = $fieldMapping->gedmo->ipTraceable ?? $fieldMapping['gedmo']['ipTraceable'];
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'string' in class - {$meta->getName()}");
}
Expand Down Expand Up @@ -82,7 +82,7 @@ public function readExtendedMetadata($meta, array &$config)
if (isset($mapping['manyToOne'])) {
foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $fieldMapping) {
if (isset($fieldMapping['gedmo']['ipTraceable'])) {
$mappingProperty = $fieldMapping['gedmo']['ipTraceable'];
$mappingProperty = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['ipTraceable'];
if (!$meta->isSingleValuedAssociation($field)) {
throw new InvalidMappingException("Association - [{$field}] is not valid, it must be a one-to-many relation or a string field - {$meta->getName()}");
}
Expand Down
12 changes: 6 additions & 6 deletions src/Loggable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function readExtendedMetadata($meta, array &$config)
if (isset($mapping['fields'])) {
foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) {
if (isset($fieldMapping['gedmo'])) {
if (in_array('versioned', $fieldMapping['gedmo'], true)) {
if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) {
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}");
}
Expand All @@ -70,7 +70,7 @@ public function readExtendedMetadata($meta, array &$config)
if (isset($mapping['attributeOverride'])) {
foreach (($mapping->attributeOverride ?? $mapping['attributeOverride']) as $field => $fieldMapping) {
if (isset($fieldMapping['gedmo'])) {
if (in_array('versioned', $fieldMapping['gedmo'], true)) {
if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) {
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}");
}
Expand All @@ -84,7 +84,7 @@ public function readExtendedMetadata($meta, array &$config)
if (isset($mapping['manyToOne'])) {
foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $fieldMapping) {
if (isset($fieldMapping['gedmo'])) {
if (in_array('versioned', $fieldMapping['gedmo'], true)) {
if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) {
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}");
}
Expand All @@ -98,7 +98,7 @@ public function readExtendedMetadata($meta, array &$config)
if (isset($mapping['oneToOne'])) {
foreach (($mapping->oneToOne ?? $mapping['oneToOne']) as $field => $fieldMapping) {
if (isset($fieldMapping['gedmo'])) {
if (in_array('versioned', $fieldMapping['gedmo'], true)) {
if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) {
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}");
}
Expand All @@ -112,12 +112,12 @@ public function readExtendedMetadata($meta, array &$config)
if (isset($mapping['embedded'])) {
foreach (($mapping->embedded ?? $mapping['embedded']) as $field => $fieldMapping) {
if (isset($fieldMapping['gedmo'])) {
if (in_array('versioned', $fieldMapping['gedmo'], true)) {
if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) {
if ($meta->isCollectionValuedAssociation($field)) {
throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}");
}
// fields cannot be overrided and throws mapping exception
$mapping = $this->_getMapping($fieldMapping['class']);
$mapping = $this->_getMapping($fieldMapping->class ?? $fieldMapping['class']);
$config = $this->inspectEmbeddedForVersioned($field, $mapping, $config);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ReferenceIntegrity/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public function readExtendedMetadata($meta, array &$config)
throw new InvalidMappingException(sprintf("'mappedBy' should be set on '%s' in '%s'", $property, $meta->getName()));
}

if (!in_array($fieldMapping['gedmo']['referenceIntegrity'], $validator->getIntegrityActions(), true)) {
if (!in_array(($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['referenceIntegrity'], $validator->getIntegrityActions(), true)) {
throw new InvalidMappingException(sprintf('Field - [%s] does not have a valid integrity option, [%s] in class - %s', $property, implode(', ', $validator->getIntegrityActions()), $meta->getName()));
}

$config['referenceIntegrity'][$property][($mapping->fields ?? $mapping['fields'])[$property]['mappedBy']] =
$fieldMapping['gedmo']['referenceIntegrity'];
($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['referenceIntegrity'];
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/ReferenceIntegrity/ReferenceIntegrityListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ public function preRemove(EventArgs $args)
throw new InvalidMappingException(sprintf("Reference '%s' on '%s' should have 'mappedBy' option defined", $property, $meta->getName()));
}

assert(class_exists($fieldMapping['targetDocument']));
assert(class_exists($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']));

$subMeta = $om->getClassMetadata($fieldMapping['targetDocument']);
$subMeta = $om->getClassMetadata($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']);

if (!$subMeta->hasField($fieldMapping['mappedBy'])) {
throw new InvalidMappingException(sprintf('Unable to find reference integrity [%s] as mapped property in entity - %s', $fieldMapping['mappedBy'], $fieldMapping['targetDocument']));
if (!$subMeta->hasField($fieldMapping->mappedBy ?? $fieldMapping['mappedBy'])) {
throw new InvalidMappingException(sprintf('Unable to find reference integrity [%s] as mapped property in entity - %s', ($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']), ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument'])));
}

$refReflProp = $subMeta->getReflectionProperty($fieldMapping['mappedBy']);
$refReflProp = $subMeta->getReflectionProperty($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']);

if ($meta->isCollectionValuedReference($property)) {
foreach ($refDoc as $refObj) {
Expand All @@ -112,19 +112,19 @@ public function preRemove(EventArgs $args)
throw new InvalidMappingException(sprintf("Reference '%s' on '%s' should have 'mappedBy' option defined", $property, $meta->getName()));
}

assert(class_exists($fieldMapping['targetDocument']));
assert(class_exists($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']));

$subMeta = $om->getClassMetadata($fieldMapping['targetDocument']);
$subMeta = $om->getClassMetadata($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']);

if (!$subMeta->hasField($fieldMapping['mappedBy'])) {
throw new InvalidMappingException(sprintf('Unable to find reference integrity [%s] as mapped property in entity - %s', $fieldMapping['mappedBy'], $fieldMapping['targetDocument']));
if (!$subMeta->hasField($fieldMapping->mappedBy ?? $fieldMapping['mappedBy'])) {
throw new InvalidMappingException(sprintf('Unable to find reference integrity [%s] as mapped property in entity - %s', ($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']), ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument'])));
}

if (!$subMeta->isCollectionValuedReference($fieldMapping['mappedBy'])) {
throw new InvalidMappingException(sprintf('Reference integrity [%s] mapped property in entity - %s should be a Reference Many', $fieldMapping['mappedBy'], $fieldMapping['targetDocument']));
if (!$subMeta->isCollectionValuedReference($fieldMapping->mappedBy ?? $fieldMapping['mappedBy'])) {
throw new InvalidMappingException(sprintf('Reference integrity [%s] mapped property in entity - %s should be a Reference Many', ($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']), ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument'])));
}

$refReflProp = $subMeta->getReflectionProperty($fieldMapping['mappedBy']);
$refReflProp = $subMeta->getReflectionProperty($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']);

if ($meta->isCollectionValuedReference($property)) {
foreach ($refDoc as $refObj) {
Expand All @@ -143,10 +143,10 @@ public function preRemove(EventArgs $args)
break;
case Validator::RESTRICT:
if ($meta->isCollectionValuedReference($property) && $refDoc->count() > 0) {
throw new ReferenceIntegrityStrictException(sprintf("The reference integrity for the '%s' collection is restricted", $fieldMapping['targetDocument']));
throw new ReferenceIntegrityStrictException(sprintf("The reference integrity for the '%s' collection is restricted", ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument'])));
}
if ($meta->isSingleValuedReference($property) && null !== $refDoc) {
throw new ReferenceIntegrityStrictException(sprintf("The reference integrity for the '%s' document is restricted", $fieldMapping['targetDocument']));
throw new ReferenceIntegrityStrictException(sprintf("The reference integrity for the '%s' document is restricted", ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument'])));
}

break;
Expand Down
12 changes: 6 additions & 6 deletions src/References/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,28 @@ public function readExtendedMetadata($meta, array &$config)

if (isset($mapping['gedmo'], ($mapping->gedmo ?? $mapping['gedmo'])['reference'])) {
foreach (($mapping->gedmo ?? $mapping['gedmo'])['reference'] as $field => $fieldMapping) {
$reference = $fieldMapping['reference'];
$reference = ($fieldMapping->reference ?? $fieldMapping['reference']);

if (!in_array($reference, array_keys($this->validReferences), true)) {
throw new InvalidMappingException($reference.' is not a valid reference, valid references are: '.implode(', ', array_keys($this->validReferences)));
}

$config[$reference][$field] = [
'field' => $field,
'type' => $fieldMapping['type'],
'class' => $fieldMapping['class'],
'type' => $fieldMapping->type ?? $fieldMapping['type'],
'class' => $fieldMapping->class ?? $fieldMapping['class'],
];

if (array_key_exists('mappedBy', $fieldMapping)) {
$config[$reference][$field]['mappedBy'] = $fieldMapping['mappedBy'];
$config[$reference][$field]['mappedBy'] = ($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']);
}

if (array_key_exists('identifier', $fieldMapping)) {
$config[$reference][$field]['identifier'] = $fieldMapping['identifier'];
$config[$reference][$field]['identifier'] = ($fieldMapping->identifier ?? $fieldMapping['identifier']);
}

if (array_key_exists('inversedBy', $fieldMapping)) {
$config[$reference][$field]['inversedBy'] = $fieldMapping['inversedBy'];
$config[$reference][$field]['inversedBy'] = ($fieldMapping->inversedBy ?? $fieldMapping['inversedBy']);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sluggable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function buildFieldConfiguration(string $field, array $fieldMapping, Cla
{
if (isset($fieldMapping['gedmo'])) {
if (isset($fieldMapping['gedmo']['slug'])) {
$slug = $fieldMapping['gedmo']['slug'];
$slug = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['slug'];
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Cannot use field - [{$field}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->getName()}");
}
Expand Down
4 changes: 2 additions & 2 deletions src/SoftDeleteable/Mapping/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public static function validateField(ClassMetadata $meta, $field)

$fieldMapping = $meta->getFieldMapping($field);

if (!in_array($fieldMapping['type'], self::$validTypes, true)) {
throw new InvalidMappingException(sprintf('Field "%s" (type "%s") must be of one of the following types: "%s" in entity %s', $field, $fieldMapping['type'], implode(', ', self::$validTypes), $meta->getName()));
if (!in_array(($fieldMapping->type ?? $fieldMapping['type']), self::$validTypes, true)) {
throw new InvalidMappingException(sprintf('Field "%s" (type "%s") must be of one of the following types: "%s" in entity %s', $field, ($fieldMapping->type ?? $fieldMapping['type']), implode(', ', self::$validTypes), $meta->getName()));
}
}
}
4 changes: 2 additions & 2 deletions src/Sortable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function readExtendedMetadata($meta, array &$config)
if (isset($mapping['fields'])) {
foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) {
if (isset($fieldMapping['gedmo'])) {
if (in_array('sortablePosition', $fieldMapping['gedmo'], true)) {
if (in_array('sortablePosition', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) {
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Sortable position field - [{$field}] type is not valid and must be 'integer' in class - {$meta->getName()}");
}
Expand Down Expand Up @@ -110,7 +110,7 @@ private function readSortableGroups(iterable $mapping, array $config): array
{
foreach ($mapping as $field => $fieldMapping) {
if (isset($fieldMapping['gedmo'])) {
if (in_array('sortableGroup', $fieldMapping['gedmo'], true)) {
if (in_array('sortableGroup', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) {
if (!isset($config['groups'])) {
$config['groups'] = [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Timestampable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function readExtendedMetadata($meta, array &$config)
if (isset($mapping['fields'])) {
foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) {
if (isset($fieldMapping['gedmo']['timestampable'])) {
$mappingProperty = $fieldMapping['gedmo']['timestampable'];
$mappingProperty = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['timestampable'];
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'date', 'datetime' or 'time' in class - {$meta->getName()}");
}
Expand Down
4 changes: 2 additions & 2 deletions src/Translatable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ protected function _loadMappingFile($file)
private function buildFieldConfiguration(string $field, array $fieldMapping, array $config): array
{
if (isset($fieldMapping['gedmo'])) {
if (in_array('translatable', $fieldMapping['gedmo'], true) || isset($fieldMapping['gedmo']['translatable'])) {
if (in_array('translatable', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true) || isset($fieldMapping['gedmo']['translatable'])) {
// fields cannot be overrided and throws mapping exception
$config['fields'][] = $field;
if (isset($fieldMapping['gedmo']['translatable']['fallback'])) {
$config['fallback'][$field] = $fieldMapping['gedmo']['translatable']['fallback'];
$config['fallback'][$field] = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['translatable']['fallback'];
}
}
}
Expand Down
Loading

0 comments on commit 4347cff

Please sign in to comment.