Skip to content

Commit 63fe724

Browse files
committed
fix deprecations
1 parent 2c33f36 commit 63fe724

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Changelog
44
2.x
55
===
66

7+
2.1.1
8+
-----
9+
10+
* Test with PHP 8.5 and fix deprecations.
11+
712
2.1.0
813
-----
914

lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ public function wakeupReflection(ReflectionService $reflService): void
315315
$reflField = array_key_exists('declared', $this->mappings[$fieldName])
316316
? new \ReflectionProperty($this->mappings[$fieldName]['declared'], $fieldName)
317317
: $this->reflClass->getProperty($fieldName);
318-
$reflField->setAccessible(true);
319318
$this->reflFields[$fieldName] = $reflField;
320319
}
321320
}
@@ -888,7 +887,7 @@ private function validateAndCompleteFieldMapping(array $mapping, ?self $inherite
888887
$mapping['assocNulls'] = $mapping['property'].'Nulls';
889888
}
890889

891-
if (array_key_exists($mapping['fieldName'], $this->mappings)) {
890+
if ($mapping['fieldName'] && array_key_exists($mapping['fieldName'], $this->mappings)) {
892891
if (!$isField
893892
|| empty($mapping['type'])
894893
|| empty($this->mappings[$mapping['fieldName']])
@@ -909,7 +908,6 @@ private function validateAndCompleteFieldMapping(array $mapping, ?self $inherite
909908
}
910909

911910
$reflProp = $this->reflClass->getProperty($mapping['fieldName']);
912-
$reflProp->setAccessible(true);
913911
$this->reflFields[$mapping['fieldName']] = $reflProp;
914912
$this->mappings[$mapping['fieldName']] = $mapping;
915913

@@ -1212,7 +1210,7 @@ public function hasField($fieldName): bool
12121210
|| $this->versionCreatedField === $fieldName;
12131211
}
12141212

1215-
public function hasAssociation($fieldName): bool
1213+
public function hasAssociation(string $fieldName): bool
12161214
{
12171215
return array_key_exists($fieldName, $this->mappings)
12181216
&& in_array($this->mappings[$fieldName]['type'], [self::MANY_TO_ONE, self::MANY_TO_MANY, 'referrers', 'mixedreferrers', 'children', 'child', 'parent'], true);
@@ -1232,14 +1230,14 @@ public function getAssociation(string $fieldName): array
12321230
return $this->mappings[$fieldName];
12331231
}
12341232

1235-
public function isSingleValuedAssociation($fieldName): bool
1233+
public function isSingleValuedAssociation(string $fieldName): bool
12361234
{
12371235
return array_key_exists($fieldName, $this->childMappings)
12381236
|| $fieldName === $this->parentMapping
12391237
|| array_key_exists($fieldName, $this->referenceMappings) && self::MANY_TO_ONE === $this->mappings[$fieldName]['type'];
12401238
}
12411239

1242-
public function isCollectionValuedAssociation($fieldName): bool
1240+
public function isCollectionValuedAssociation(string $fieldName): bool
12431241
{
12441242
return array_key_exists($fieldName, $this->referenceMappings) && self::MANY_TO_MANY === $this->mappings[$fieldName]['type']
12451243
|| array_key_exists($fieldName, $this->referrersMappings)
@@ -1362,7 +1360,7 @@ public function isNullable(string $fieldName): bool
13621360
*/
13631361
public function mapField(array $mapping, ?self $inherited = null): void
13641362
{
1365-
$parentMapping = array_key_exists('fieldName', $mapping) && array_key_exists($mapping['fieldName'], $this->mappings)
1363+
$parentMapping = array_key_exists('fieldName', $mapping) && null !== $mapping['fieldName'] && array_key_exists($mapping['fieldName'], $this->mappings)
13661364
? $this->mappings[$mapping['fieldName']]
13671365
: null;
13681366

@@ -1547,7 +1545,7 @@ public function newInstance(): object
15471545

15481546
public function setIdentifierValue(object $document, string $id): void
15491547
{
1550-
if (array_key_exists($this->identifier, $this->reflFields)) {
1548+
if (null !== $this->identifier && array_key_exists($this->identifier, $this->reflFields)) {
15511549
$this->reflFields[$this->identifier]->setValue($document, $id);
15521550
}
15531551
}

lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ private function createCloner(PhpcrClassMetadata $classMetadata, ?\ReflectionPro
169169
$propertyName = $reflectionProperty->getName();
170170

171171
if ($classMetadata->hasField($propertyName) || $classMetadata->hasAssociation($propertyName)) {
172-
$reflectionProperty->setAccessible(true);
173172
$reflectionProperty->setValue($cloned, $reflectionProperty->getValue($original));
174173
}
175174
}

lib/Doctrine/ODM/PHPCR/Query/Builder/ConverterPhpcr.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ protected function walkOperandStaticLiteral(OperandStaticLiteral $node): Literal
307307
'uuid' => 'string',
308308
];
309309

310-
if (array_key_exists($type, $typeMapping)) {
310+
if ($type && array_key_exists($type, $typeMapping)) {
311311
settype($value, $typeMapping[$type]);
312312
}
313313
}

lib/Doctrine/ODM/PHPCR/UnitOfWork.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public function getOrCreateDocuments(?string $className, iterable $nodes, array
376376

377377
foreach ($class->fieldMappings as $fieldName) {
378378
$mapping = $class->mappings[$fieldName];
379-
if (array_key_exists($mapping['property'], $properties)) {
379+
if (null !== $mapping['property'] && array_key_exists($mapping['property'], $properties)) {
380380
if (true === $mapping['multivalue']) {
381381
if (array_key_exists('assoc', $mapping) && null !== $mapping['assoc']) {
382382
$documentState[$fieldName] = $this->createAssoc($properties, $mapping);
@@ -580,7 +580,8 @@ public function getOrCreateProxy(string $targetId, string $className, ?string $l
580580
}
581581

582582
$metadata = $this->dm->getClassMetadata($className);
583-
$proxyDocument = $this->dm->getProxyFactory()->getProxy($className, [$metadata->identifier => $targetId]);
583+
// TODO: what should happen when identifier is null?
584+
$proxyDocument = $this->dm->getProxyFactory()->getProxy($className, [(string) $metadata->identifier => $targetId]);
584585

585586
// register the document under its own id
586587
$this->registerDocument($proxyDocument, $targetId);
@@ -1378,6 +1379,7 @@ public function computeChangeSet(ClassMetadata $class, object $document): void
13781379
$destPath = $destName = false;
13791380

13801381
if (array_key_exists($oid, $this->originalData)
1382+
&& null !== $class->parentMapping
13811383
&& array_key_exists($class->parentMapping, $this->originalData[$oid])
13821384
&& array_key_exists($class->parentMapping, $changeSet)
13831385
&& $this->originalData[$oid][$class->parentMapping] !== $changeSet[$class->parentMapping]
@@ -1386,6 +1388,7 @@ public function computeChangeSet(ClassMetadata $class, object $document): void
13861388
}
13871389

13881390
if (array_key_exists($oid, $this->originalData)
1391+
&& null !== $class->nodename
13891392
&& array_key_exists($class->nodename, $this->originalData[$oid])
13901393
&& array_key_exists($class->nodename, $changeSet)
13911394
&& $this->originalData[$oid][$class->nodename] !== $changeSet[$class->nodename]
@@ -1397,7 +1400,7 @@ public function computeChangeSet(ClassMetadata $class, object $document): void
13971400
if ($destPath || $destName) {
13981401
// add the other field if only one was changed
13991402
if (false === $destPath) {
1400-
$destPath = array_key_exists($class->parentMapping, $changeSet)
1403+
$destPath = null !== $class->parentMapping && array_key_exists($class->parentMapping, $changeSet)
14011404
? $this->getDocumentId($changeSet[$class->parentMapping])
14021405
: PathHelper::getParentPath($this->getDocumentId($document));
14031406
}
@@ -1419,6 +1422,7 @@ public function computeChangeSet(ClassMetadata $class, object $document): void
14191422
}
14201423

14211424
if (array_key_exists($oid, $this->originalData)
1425+
&& null !== $class->identifier
14221426
&& array_key_exists($class->identifier, $this->originalData[$oid])
14231427
&& array_key_exists($class->identifier, $changeSet)
14241428
&& $this->originalData[$oid][$class->identifier] !== $changeSet[$class->identifier]
@@ -2926,7 +2930,7 @@ public function getDocumentById(string $id): ?object
29262930
public function getDocumentId($document, bool $throw = true): ?string
29272931
{
29282932
$oid = is_object($document) ? \spl_object_hash($document) : $document;
2929-
if (empty($this->documentIds[$oid])) {
2933+
if (null === $oid || empty($this->documentIds[$oid])) {
29302934
if (!$throw) {
29312935
return null;
29322936
}
@@ -3195,6 +3199,7 @@ public function doLoadTranslation(object $document, ClassMetadata $metadata, ?st
31953199
// current locale is already loaded and not removed
31963200
if (!$refresh
31973201
&& array_key_exists($oid, $this->documentTranslations)
3202+
&& null !== $currentLocale
31983203
&& array_key_exists($currentLocale, $this->documentTranslations[$oid])
31993204
) {
32003205
return;

0 commit comments

Comments
 (0)