Skip to content

Commit 88dc22e

Browse files
fix phpstan errors
1 parent b35be8d commit 88dc22e

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/Mapping/ClassMetadata.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ final class ClassMetadata implements BaseClassMetadata
487487

488488
/**
489489
* The name of the mongo collection the document is mapped to.
490-
* */
491-
public private(set) string $collection = '';
490+
*/
491+
public private(set) ?string $collection = null;
492492

493493
/**
494494
* The name of the GridFS bucket the document is mapped to.
@@ -576,18 +576,18 @@ final class ClassMetadata implements BaseClassMetadata
576576
/**
577577
* The name of the document class.
578578
*
579-
* @var class-string<T>
579+
* @var class-string<T>|null
580580
*/
581-
public private(set) string $name = '';
581+
public private(set) ?string $name = null;
582582

583583
/**
584584
* The name of the document class that is at the root of the mapped document inheritance
585585
* hierarchy. If the document is not part of a mapped inheritance hierarchy this is the same
586586
* as {@link $documentName}.
587587
*
588-
* @var class-string
588+
* @var class-string|null
589589
*/
590-
public private(set) string $rootDocumentName = '';
590+
public private(set) ?string $rootDocumentName = null;
591591

592592
/**
593593
* The name of the custom repository class used for the document class.
@@ -972,7 +972,7 @@ public function invokeLifecycleCallbacks(string $event, object $document, ?array
972972
return;
973973
}
974974

975-
if (! $document instanceof $this->name) {
975+
if ($this->name !== null && ! $document instanceof $this->name) {
976976
throw new InvalidArgumentException(sprintf('Expected document class "%s"; found: "%s"', $this->name, $document::class));
977977
}
978978

src/Persisters/DocumentPersister.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ private function prepareQueryExpression(array $expression, ClassMetadata $class)
13541354
// Process query operators whose argument arrays need type conversion
13551355
if (in_array($k, ['$in', '$nin', '$all']) && is_array($v)) {
13561356
foreach ($v as $k2 => $v2) {
1357-
if ($v2 instanceof $class->name) {
1357+
if ($class->name !== null && $v2 instanceof $class->name) {
13581358
// If a value in a query is a target document, e.g. ['referenceField' => $targetDocument],
13591359
// retreive id from target document and convert this id using it's type
13601360
$expression[$k][$k2] = $class->getDatabaseIdentifierValue($class->getIdentifierValue($v2));
@@ -1381,7 +1381,7 @@ private function prepareQueryExpression(array $expression, ClassMetadata $class)
13811381
continue;
13821382
}
13831383

1384-
if ($v instanceof $class->name) {
1384+
if ($class->name !== null && $v instanceof $class->name) {
13851385
$expression[$k] = $class->getDatabaseIdentifierValue($class->getIdentifierValue($v));
13861386
} else {
13871387
$expression[$k] = $class->getDatabaseIdentifierValue($v);

tests/Tests/Functional/VectorSearchTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use MongoDB\Driver\WriteConcern;
1212
use PHPUnit\Framework\Attributes\Group;
1313
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
14+
use ReflectionProperty;
1415

1516
#[Group('atlas')]
1617
class VectorSearchTest extends BaseTestCase
@@ -105,8 +106,11 @@ public function testAtlasVectorSearchWithBinaryType(): void
105106
{
106107
$cm = $this->dm->getClassMetadata(VectorEmbedding::class);
107108

108-
$cm->fieldMappings['vectorFloat']['type'] = Type::VECTOR_FLOAT32;
109-
$cm->fieldMappings['vectorInt']['type'] = Type::VECTOR_INT8;
109+
$fieldMappings = $cm->fieldMappings;
110+
$fieldMappings['vectorFloat']['type'] = Type::VECTOR_FLOAT32;
111+
$fieldMappings['vectorInt']['type'] = Type::VECTOR_INT8;
112+
113+
new ReflectionProperty($cm, 'fieldMappings')->setValue($cm, $fieldMappings);
110114

111115
// Change the collection name to avoid conflicts with asynchronous index building
112116
$cm->collection .= '_binary_type';

0 commit comments

Comments
 (0)