Skip to content

Commit ea6959d

Browse files
authored
Reduce deprecations due to FieldMapping array access
1 parent cfe5a76 commit ea6959d

File tree

22 files changed

+65
-48
lines changed

22 files changed

+65
-48
lines changed

doc/mapping.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class Annotation implements Driver
149149
}
150150
// validate encoding type
151151
$mapping = $meta->getFieldMapping($field);
152-
if ($mapping['type'] != 'string') {
152+
if (($mapping->type ?? $mapping['type']) != 'string') {
153153
throw new \Exception("Only strings can be encoded");
154154
}
155155
// store the metadata

src/Blameable/Mapping/Driver/Xml.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,6 @@ protected function isValidField($meta, $field)
128128
{
129129
$mapping = $meta->getFieldMapping($field);
130130

131-
return $mapping && in_array($mapping['type'], self::VALID_TYPES, true);
131+
return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true);
132132
}
133133
}

src/Blameable/Mapping/Driver/Yaml.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,6 @@ protected function isValidField($meta, $field)
134134
{
135135
$mapping = $meta->getFieldMapping($field);
136136

137-
return $mapping && in_array($mapping['type'], self::VALID_TYPES, true);
137+
return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true);
138138
}
139139
}

src/IpTraceable/Mapping/Driver/Xml.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ protected function isValidField($meta, $field)
130130
{
131131
$mapping = $meta->getFieldMapping($field);
132132

133-
return $mapping && in_array($mapping['type'], self::VALID_TYPES, true);
133+
return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true);
134134
}
135135
}

src/IpTraceable/Mapping/Driver/Yaml.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ protected function isValidField($meta, $field)
130130
{
131131
$mapping = $meta->getFieldMapping($field);
132132

133-
return $mapping && in_array($mapping['type'], self::VALID_TYPES, true);
133+
return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true);
134134
}
135135
}

src/Loggable/Entity/Repository/LogEntryRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ protected function mapValue(ClassMetadata $objectMeta, $field, &$value)
165165
}
166166

167167
$mapping = $objectMeta->getAssociationMapping($field);
168-
$value = $value ? $this->getEntityManager()->getReference($mapping['targetEntity'], $value) : null;
168+
$value = $value ? $this->getEntityManager()->getReference($mapping->targetEntity ?? $mapping['targetEntity'], $value) : null;
169169
}
170170

171171
/**

src/Mapping/Driver/AbstractAnnotationDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected function isValidField($meta, $field)
131131
{
132132
$mapping = $meta->getFieldMapping($field);
133133

134-
return $mapping && in_array($mapping['type'], $this->validTypes, true);
134+
return $mapping && in_array($mapping->type ?? $mapping['type'], $this->validTypes, true);
135135
}
136136

137137
/**

src/ReferenceIntegrity/ReferenceIntegrityListener.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ public function preRemove(EventArgs $args)
8686
throw new InvalidMappingException(sprintf("Reference '%s' on '%s' should have 'mappedBy' option defined", $property, $meta->getName()));
8787
}
8888

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

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

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

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

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

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

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

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

123-
if (!$subMeta->isCollectionValuedReference($fieldMapping['mappedBy'])) {
124-
throw new InvalidMappingException(sprintf('Reference integrity [%s] mapped property in entity - %s should be a Reference Many', $fieldMapping['mappedBy'], $fieldMapping['targetDocument']));
123+
if (!$subMeta->isCollectionValuedReference($fieldMapping->mappedBy ?? $fieldMapping['mappedBy'])) {
124+
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']));
125125
}
126126

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

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

152152
break;

src/Sluggable/Mapping/Driver/Xml.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function isValidField($meta, $field)
7676
{
7777
$mapping = $meta->getFieldMapping($field);
7878

79-
return $mapping && in_array($mapping['type'], self::VALID_TYPES, true);
79+
return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true);
8080
}
8181

8282
/**

src/Sluggable/Mapping/Driver/Yaml.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function isValidField($meta, $field)
8585
{
8686
$mapping = $meta->getFieldMapping($field);
8787

88-
return $mapping && in_array($mapping['type'], self::VALID_TYPES, true);
88+
return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true);
8989
}
9090

9191
/**

0 commit comments

Comments
 (0)