Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve LSP violation #11520

Draft
wants to merge 2 commits into
base: 4.0.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upgrade to 4.0

## Remove `DatabaseDriver`

The class `Doctrine\ORM\Mapping\Driver\DatabaseDriver` is removed.

## Remove the `NotSupported` exception

The class `Doctrine\ORM\Exception\NotSupported` has been removed without replacement.
Expand Down
32 changes: 0 additions & 32 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,9 @@
<code><![CDATA[$mapping]]></code>
<code><![CDATA[$overrideMapping]]></code>
</InvalidArgument>
<InvalidNullableReturnType>
<code><![CDATA[ReflectionClass|null]]></code>
</InvalidNullableReturnType>
<InvalidPropertyAssignmentValue>
<code><![CDATA[$definition]]></code>
</InvalidPropertyAssignmentValue>
<NullableReturnStatement>
<code><![CDATA[$this->reflClass]]></code>
</NullableReturnStatement>
<ParamNameMismatch>
<code><![CDATA[$entity]]></code>
</ParamNameMismatch>
Expand All @@ -312,9 +306,6 @@
<code><![CDATA[$parentReflFields[$embeddedClass->declaredField]]]></code>
</PossiblyNullArgument>
<PossiblyNullReference>
<code><![CDATA[getProperty]]></code>
<code><![CDATA[getProperty]]></code>
<code><![CDATA[getProperty]]></code>
<code><![CDATA[getValue]]></code>
<code><![CDATA[getValue]]></code>
<code><![CDATA[getValue]]></code>
Expand Down Expand Up @@ -436,35 +427,12 @@
* columnDefinition?: string
* }]]></code>
</MoreSpecificReturnType>
<RedundantCondition>
<code><![CDATA[$metadata->getReflectionClass()]]></code>
</RedundantCondition>
<RedundantConditionGivenDocblockType>
<code><![CDATA[assert($cacheAttribute instanceof Mapping\Cache)]]></code>
<code><![CDATA[assert($method instanceof ReflectionMethod)]]></code>
<code><![CDATA[assert($method instanceof ReflectionMethod)]]></code>
<code><![CDATA[assert($property instanceof ReflectionProperty)]]></code>
</RedundantConditionGivenDocblockType>
<TypeDoesNotContainNull>
<code><![CDATA[new ReflectionClass($metadata->name)]]></code>
</TypeDoesNotContainNull>
</file>
<file src="src/Mapping/Driver/DatabaseDriver.php">
<DocblockTypeContradiction>
<code><![CDATA[$metadata instanceof ClassMetadata]]></code>
</DocblockTypeContradiction>
<MoreSpecificImplementedParamType>
<code><![CDATA[$metadata]]></code>
</MoreSpecificImplementedParamType>
<PossiblyNullArrayAccess>
<code><![CDATA[$this->tables[$tableName]]]></code>
<code><![CDATA[$this->tables[$tableName]]]></code>
</PossiblyNullArrayAccess>
<PossiblyNullReference>
<code><![CDATA[getColumns]]></code>
<code><![CDATA[getColumns]]></code>
<code><![CDATA[getIndexes]]></code>
</PossiblyNullReference>
</file>
<file src="src/Mapping/Driver/SimplifiedXmlDriver.php">
<MissingParamType>
Expand Down
12 changes: 0 additions & 12 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,6 @@
<file name="src/Mapping/ClassMetadataFactory.php"/>
</errorLevel>
</InvalidArrayAssignment>
<LessSpecificReturnStatement>
<errorLevel type="suppress">
<!-- In DBAL 4, column precision is nullable. See https://github.com/doctrine/dbal/pull/3511 -->
<file name="src/Mapping/Driver/DatabaseDriver.php"/>
</errorLevel>
</LessSpecificReturnStatement>
<MoreSpecificReturnType>
<errorLevel type="suppress">
<!-- In DBAL 4, the default column value is mixed. See https://github.com/doctrine/dbal/pull/3511 -->
<file name="src/Mapping/Driver/DatabaseDriver.php"/>
</errorLevel>
</MoreSpecificReturnType>
<InvalidReturnType>
<errorLevel type="suppress">
<!-- https://github.com/vimeo/psalm/issues/8819 -->
Expand Down
17 changes: 5 additions & 12 deletions src/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,9 @@
/**
* The ReflectionClass instance of the mapped class.
*
* @var ReflectionClass<T>|null
* @var ReflectionClass<T>
*/
public ReflectionClass|null $reflClass = null;
public ReflectionClass $reflClass;

/**
* Is this entity marked as "read-only"?
Expand Down Expand Up @@ -552,6 +552,7 @@
$this->namingStrategy = $namingStrategy ?? new DefaultNamingStrategy();
$this->instantiator = new Instantiator();
$this->typedFieldMapper = $typedFieldMapper ?? new DefaultTypedFieldMapper();
$this->reflClass = new ReflectionClass($name);
}

/**
Expand Down Expand Up @@ -781,7 +782,7 @@
public function wakeupReflection(ReflectionService $reflService): void
{
// Restore ReflectionClass and properties
$this->reflClass = $reflService->getClass($this->name);

Check failure on line 785 in src/Mapping/ClassMetadata.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm

PossiblyNullPropertyAssignmentValue

src/Mapping/ClassMetadata.php:785:31: PossiblyNullPropertyAssignmentValue: $this->reflClass with non-nullable declared type 'ReflectionClass<T>' cannot be assigned nullable type 'ReflectionClass<T>|null' (see https://psalm.dev/148)
$this->instantiator = $this->instantiator ?: new Instantiator();

$parentReflFields = [];
Expand Down Expand Up @@ -863,7 +864,7 @@
*/
public function initializeReflection(ReflectionService $reflService): void
{
$this->reflClass = $reflService->getClass($this->name);

Check failure on line 867 in src/Mapping/ClassMetadata.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm

PossiblyNullPropertyAssignmentValue

src/Mapping/ClassMetadata.php:867:28: PossiblyNullPropertyAssignmentValue: $this->reflClass with non-nullable declared type 'ReflectionClass<T>' cannot be assigned nullable type 'ReflectionClass<T>|null' (see https://psalm.dev/148)
$this->namespace = $reflService->getClassNamespace($this->name);

if ($this->reflClass) {
Expand Down Expand Up @@ -928,12 +929,7 @@
}
}

/**
* {@inheritDoc}
*
* Can return null when using static reflection, in violation of the LSP
*/
public function getReflectionClass(): ReflectionClass|null
public function getReflectionClass(): ReflectionClass
{
return $this->reflClass;
}
Expand Down Expand Up @@ -1101,8 +1097,7 @@
*/
private function isTypedProperty(string $name): bool
{
return isset($this->reflClass)
&& $this->reflClass->hasProperty($name)
return $this->reflClass->hasProperty($name)
&& $this->reflClass->getProperty($name)->hasType();
}

Expand Down Expand Up @@ -2557,8 +2552,6 @@
if (! empty($this->embeddedClasses[$property]->columnPrefix)) {
$fieldMapping['columnName'] = $this->embeddedClasses[$property]->columnPrefix . $fieldMapping['columnName'];
} elseif ($this->embeddedClasses[$property]->columnPrefix !== false) {
assert($this->reflClass !== null);
assert($embeddable->reflClass !== null);
$fieldMapping['columnName'] = $this->namingStrategy
->embeddedFieldToColumnName(
$property,
Expand Down
5 changes: 0 additions & 5 deletions src/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,6 @@ protected function doLoadMetadata(
*/
protected function validateRuntimeMetadata(ClassMetadata $class, ClassMetadataInterface|null $parent): void
{
if (! $class->reflClass) {
// only validate if there is a reflection class instance
return;
}

$class->validateIdentifier();
$class->validateAssociations();
$class->validateLifecycleCallbacks($this->getReflectionService());
Expand Down
5 changes: 1 addition & 4 deletions src/Mapping/Driver/AttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ public function isTransient(string $className): bool
*/
public function loadMetadataForClass(string $className, PersistenceClassMetadata $metadata): void
{
$reflectionClass = $metadata->getReflectionClass()
// this happens when running attribute driver in combination with
// static reflection services. This is not the nicest fix
?? new ReflectionClass($metadata->name);
$reflectionClass = $metadata->getReflectionClass();

$classAttributes = $this->reader->getClassAttributes($reflectionClass);

Expand Down
Loading
Loading