diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index f8ed3d82920..9ecae4c885c 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -26,12 +26,8 @@ */ class MappingException extends Exception implements ORMException { - /** - * @param class-string $entityName - * - * @return MappingException - */ - public static function identifierRequired($entityName) + /** @param class-string $entityName */ + public static function identifierRequired(string $entityName): self { $parent = get_parent_class($entityName); if ($parent !== false) { @@ -48,29 +44,17 @@ public static function identifierRequired($entityName) )); } - /** - * @param string $entityName - * @param int $type - * - * @return MappingException - */ - public static function invalidInheritanceType($entityName, $type) + public static function invalidInheritanceType(string $entityName, int $type): self { return new self(sprintf("The inheritance type '%s' specified for '%s' does not exist.", $type, $entityName)); } - /** @return MappingException */ - public static function generatorNotAllowedWithCompositeId() + public static function generatorNotAllowedWithCompositeId(): self { return new self("Id generators can't be used with a composite id."); } - /** - * @param string $entity - * - * @return MappingException - */ - public static function missingFieldName($entity) + public static function missingFieldName(string $entity): self { return new self(sprintf( "The field or association mapping misses the 'fieldName' attribute in entity '%s'.", @@ -78,43 +62,22 @@ public static function missingFieldName($entity) )); } - /** - * @param string $fieldName - * - * @return MappingException - */ - public static function missingTargetEntity($fieldName) + public static function missingTargetEntity(string $fieldName): self { return new self(sprintf("The association mapping '%s' misses the 'targetEntity' attribute.", $fieldName)); } - /** - * @param string $fieldName - * - * @return MappingException - */ - public static function missingSourceEntity($fieldName) + public static function missingSourceEntity(string $fieldName): self { return new self(sprintf("The association mapping '%s' misses the 'sourceEntity' attribute.", $fieldName)); } - /** - * @param string $fieldName - * - * @return MappingException - */ - public static function missingEmbeddedClass($fieldName) + public static function missingEmbeddedClass(string $fieldName): self { return new self(sprintf("The embed mapping '%s' misses the 'class' attribute.", $fieldName)); } - /** - * @param string $entityName - * @param string $fileName - * - * @return MappingException - */ - public static function mappingFileNotFound($entityName, $fileName) + public static function mappingFileNotFound(string $entityName, string $fileName): self { return new self(sprintf("No mapping file found named '%s' for class '%s'.", $fileName, $entityName)); } @@ -123,11 +86,8 @@ public static function mappingFileNotFound($entityName, $fileName) * Exception for invalid property name override. * * @param string $className The entity's name. - * @param string $fieldName - * - * @return MappingException */ - public static function invalidOverrideFieldName($className, $fieldName) + public static function invalidOverrideFieldName(string $className, string $fieldName): self { return new self(sprintf("Invalid field override named '%s' for class '%s'.", $fieldName, $className)); } @@ -136,11 +96,8 @@ public static function invalidOverrideFieldName($className, $fieldName) * Exception for invalid property type override. * * @param string $className The entity's name. - * @param string $fieldName - * - * @return MappingException */ - public static function invalidOverrideFieldType($className, $fieldName) + public static function invalidOverrideFieldType(string $className, string $fieldName): self { return new self(sprintf( "The column type of attribute '%s' on class '%s' could not be changed.", @@ -149,67 +106,32 @@ public static function invalidOverrideFieldType($className, $fieldName) )); } - /** - * @param string $className - * @param string $fieldName - * - * @return MappingException - */ - public static function mappingNotFound($className, $fieldName) + public static function mappingNotFound(string $className, string $fieldName): self { return new self(sprintf("No mapping found for field '%s' on class '%s'.", $fieldName, $className)); } - /** - * @param string $className - * @param string $queryName - * - * @return MappingException - */ - public static function queryNotFound($className, $queryName) + public static function queryNotFound(string $className, string $queryName): self { return new self(sprintf("No query found named '%s' on class '%s'.", $queryName, $className)); } - /** - * @param string $className - * @param string $resultName - * - * @return MappingException - */ - public static function resultMappingNotFound($className, $resultName) + public static function resultMappingNotFound(string $className, string $resultName): self { return new self(sprintf("No result set mapping found named '%s' on class '%s'.", $resultName, $className)); } - /** - * @param string $entity - * @param string $queryName - * - * @return MappingException - */ - public static function emptyQueryMapping($entity, $queryName) + public static function emptyQueryMapping(string $entity, string $queryName): self { return new self(sprintf('Query named "%s" in "%s" could not be empty.', $queryName, $entity)); } - /** - * @param string $className - * - * @return MappingException - */ - public static function nameIsMandatoryForQueryMapping($className) + public static function nameIsMandatoryForQueryMapping(string $className): self { return new self(sprintf("Query name on entity class '%s' is not defined.", $className)); } - /** - * @param string $entity - * @param string $queryName - * - * @return MappingException - */ - public static function missingQueryMapping($entity, $queryName) + public static function missingQueryMapping(string $entity, string $queryName): self { return new self(sprintf( 'Query named "%s" in "%s requires a result class or result set mapping.', @@ -218,13 +140,7 @@ public static function missingQueryMapping($entity, $queryName) )); } - /** - * @param string $entity - * @param string $resultName - * - * @return MappingException - */ - public static function missingResultSetMappingEntity($entity, $resultName) + public static function missingResultSetMappingEntity(string $entity, string $resultName): self { return new self(sprintf( 'Result set mapping named "%s" in "%s requires a entity class name.', @@ -233,13 +149,7 @@ public static function missingResultSetMappingEntity($entity, $resultName) )); } - /** - * @param string $entity - * @param string $resultName - * - * @return MappingException - */ - public static function missingResultSetMappingFieldName($entity, $resultName) + public static function missingResultSetMappingFieldName(string $entity, string $resultName): self { return new self(sprintf( 'Result set mapping named "%s" in "%s requires a field name.', @@ -257,12 +167,7 @@ public static function oneToManyRequiresMappedBy(string $entityName, string $fie )); } - /** - * @param string $fieldName - * - * @return MappingException - */ - public static function joinTableRequired($fieldName) + public static function joinTableRequired(string $fieldName): self { return new self(sprintf("The mapping of field '%s' requires an the 'joinTable' attribute.", $fieldName)); } @@ -274,10 +179,8 @@ public static function joinTableRequired($fieldName) * @param string $expectedOption Which option is required * @param string $hint Can optionally be used to supply a tip for common mistakes, * e.g. "Did you think of the plural s?" - * - * @return MappingException */ - public static function missingRequiredOption($field, $expectedOption, $hint = '') + public static function missingRequiredOption(string $field, string $expectedOption, string $hint = ''): self { $message = "The mapping of field '" . $field . "' is invalid: The option '" . $expectedOption . "' is required."; @@ -290,12 +193,8 @@ public static function missingRequiredOption($field, $expectedOption, $hint = '' /** * Generic exception for invalid mappings. - * - * @param string $fieldName - * - * @return MappingException */ - public static function invalidMapping($fieldName) + public static function invalidMapping(string $fieldName): self { return new self(sprintf("The mapping of field '%s' is invalid.", $fieldName)); } @@ -306,21 +205,13 @@ public static function invalidMapping($fieldName) * within the stacktrace * * @param string $entity The entity's name - * - * @return MappingException */ - public static function reflectionFailure($entity, ReflectionException $previousException) + public static function reflectionFailure(string $entity, ReflectionException $previousException): self { return new self(sprintf('An error occurred in %s', $entity), 0, $previousException); } - /** - * @param string $className - * @param string $joinColumn - * - * @return MappingException - */ - public static function joinColumnMustPointToMappedField($className, $joinColumn) + public static function joinColumnMustPointToMappedField(string $className, string $joinColumn): self { return new self(sprintf( 'The column %s must be mapped to a field in class %s since it is referenced by a join column of another class.', @@ -329,12 +220,8 @@ public static function joinColumnMustPointToMappedField($className, $joinColumn) )); } - /** - * @param class-string $className - * - * @return MappingException - */ - public static function classIsNotAValidEntityOrMappedSuperClass($className) + /** @param class-string $className */ + public static function classIsNotAValidEntityOrMappedSuperClass(string $className): self { $parent = get_parent_class($className); if ($parent !== false) { @@ -354,10 +241,8 @@ public static function classIsNotAValidEntityOrMappedSuperClass($className) /** * @param string $entity The entity's name. * @param string $fieldName The name of the field that was already declared. - * - * @return MappingException */ - public static function duplicateFieldMapping($entity, $fieldName) + public static function duplicateFieldMapping(string $entity, string $fieldName): self { return new self(sprintf( 'Property "%s" in "%s" was already declared, but it must be declared only once', @@ -366,13 +251,7 @@ public static function duplicateFieldMapping($entity, $fieldName) )); } - /** - * @param string $entity - * @param string $fieldName - * - * @return MappingException - */ - public static function duplicateAssociationMapping($entity, $fieldName) + public static function duplicateAssociationMapping(string $entity, string $fieldName): self { return new self(sprintf( 'Property "%s" in "%s" was already declared, but it must be declared only once', @@ -381,13 +260,7 @@ public static function duplicateAssociationMapping($entity, $fieldName) )); } - /** - * @param string $entity - * @param string $queryName - * - * @return MappingException - */ - public static function duplicateQueryMapping($entity, $queryName) + public static function duplicateQueryMapping(string $entity, string $queryName): self { return new self(sprintf( 'Query named "%s" in "%s" was already declared, but it must be declared only once', @@ -396,13 +269,7 @@ public static function duplicateQueryMapping($entity, $queryName) )); } - /** - * @param string $entity - * @param string $resultName - * - * @return MappingException - */ - public static function duplicateResultSetMapping($entity, $resultName) + public static function duplicateResultSetMapping(string $entity, string $resultName): self { return new self(sprintf( 'Result set mapping named "%s" in "%s" was already declared, but it must be declared only once', @@ -411,34 +278,17 @@ public static function duplicateResultSetMapping($entity, $resultName) )); } - /** - * @param string $entity - * - * @return MappingException - */ - public static function singleIdNotAllowedOnCompositePrimaryKey($entity) + public static function singleIdNotAllowedOnCompositePrimaryKey(string $entity): self { return new self('Single id is not allowed on composite primary key in entity ' . $entity); } - /** - * @param string $entity - * - * @return MappingException - */ - public static function noIdDefined($entity) + public static function noIdDefined(string $entity): self { return new self('No ID defined for entity ' . $entity); } - /** - * @param string $entity - * @param string $fieldName - * @param string $unsupportedType - * - * @return MappingException - */ - public static function unsupportedOptimisticLockingType($entity, $fieldName, $unsupportedType) + public static function unsupportedOptimisticLockingType(string $entity, string $fieldName, string $unsupportedType): self { return new self(sprintf( 'Locking type "%s" (specified in "%s", field "%s") is not supported by Doctrine.', @@ -448,12 +298,7 @@ public static function unsupportedOptimisticLockingType($entity, $fieldName, $un )); } - /** - * @param string|null $path - * - * @return MappingException - */ - public static function fileMappingDriversRequireConfiguredDirectoryPath($path = null) + public static function fileMappingDriversRequireConfiguredDirectoryPath(string|null $path = null): self { if (! empty($path)) { $path = '[' . $path . ']'; @@ -471,10 +316,8 @@ public static function fileMappingDriversRequireConfiguredDirectoryPath($path = * * @param string $className The class that could not be found * @param string $owningClass The class that declares the discriminator map. - * - * @return MappingException */ - public static function invalidClassInDiscriminatorMap($className, $owningClass) + public static function invalidClassInDiscriminatorMap(string $className, string $owningClass): self { return new self(sprintf( "Entity class '%s' used in the discriminator map of class '%s' " . @@ -485,33 +328,23 @@ public static function invalidClassInDiscriminatorMap($className, $owningClass) } /** - * @param string $className * @param string[] $entries * @param array $map - * - * @return MappingException */ - public static function duplicateDiscriminatorEntry($className, array $entries, array $map) + public static function duplicateDiscriminatorEntry(string $className, array $entries, array $map): self { return new self( 'The entries ' . implode(', ', $entries) . " in discriminator map of class '" . $className . "' is duplicated. " . 'If the discriminator map is automatically generated you have to convert it to an explicit discriminator map now. ' . 'The entries of the current map are: @DiscriminatorMap({' . implode(', ', array_map( - static function ($a, $b) { - return sprintf("'%s': '%s'", $a, $b); - }, + static fn ($a, $b) => sprintf("'%s': '%s'", $a, $b), array_keys($map), array_values($map), )) . '})', ); } - /** - * @param string $className - * - * @return MappingException - */ - public static function missingDiscriminatorMap($className) + public static function missingDiscriminatorMap(string $className): self { return new self(sprintf( "Entity class '%s' is using inheritance but no discriminator map was defined.", @@ -519,12 +352,7 @@ public static function missingDiscriminatorMap($className) )); } - /** - * @param string $className - * - * @return MappingException - */ - public static function missingDiscriminatorColumn($className) + public static function missingDiscriminatorColumn(string $className): self { return new self(sprintf( "Entity class '%s' is using inheritance but no discriminator column was defined.", @@ -532,13 +360,7 @@ public static function missingDiscriminatorColumn($className) )); } - /** - * @param string $className - * @param string $type - * - * @return MappingException - */ - public static function invalidDiscriminatorColumnType($className, $type) + public static function invalidDiscriminatorColumnType(string $className, string $type): self { return new self(sprintf( "Discriminator column type on entity class '%s' is not allowed to be '%s'. 'string' or 'integer' type variables are suggested!", @@ -547,23 +369,12 @@ public static function invalidDiscriminatorColumnType($className, $type) )); } - /** - * @param string $className - * - * @return MappingException - */ - public static function nameIsMandatoryForDiscriminatorColumns($className) + public static function nameIsMandatoryForDiscriminatorColumns(string $className): self { return new self(sprintf("Discriminator column name on entity class '%s' is not defined.", $className)); } - /** - * @param string $className - * @param string $fieldName - * - * @return MappingException - */ - public static function cannotVersionIdField($className, $fieldName) + public static function cannotVersionIdField(string $className, string $fieldName): self { return new self(sprintf( "Setting Id field '%s' as versionable in entity class '%s' is not supported.", @@ -572,59 +383,28 @@ public static function cannotVersionIdField($className, $fieldName) )); } - /** - * @param string $className - * @param string $columnName - * - * @return MappingException - */ - public static function duplicateColumnName($className, $columnName) + public static function duplicateColumnName(string $className, string $columnName): self { return new self("Duplicate definition of column '" . $columnName . "' on entity '" . $className . "' in a field or discriminator column mapping."); } - /** - * @param string $className - * @param string $field - * - * @return MappingException - */ - public static function illegalToManyAssociationOnMappedSuperclass($className, $field) + public static function illegalToManyAssociationOnMappedSuperclass(string $className, string $field): self { return new self("It is illegal to put an inverse side one-to-many or many-to-many association on mapped superclass '" . $className . '#' . $field . "'."); } - /** - * @param string $className - * @param string $targetEntity - * @param string $targetField - * - * @return MappingException - */ - public static function cannotMapCompositePrimaryKeyEntitiesAsForeignId($className, $targetEntity, $targetField) + public static function cannotMapCompositePrimaryKeyEntitiesAsForeignId(string $className, string $targetEntity, string $targetField): self { return new self("It is not possible to map entity '" . $className . "' with a composite primary key " . "as part of the primary key of another entity '" . $targetEntity . '#' . $targetField . "'."); } - /** - * @param string $className - * @param string $field - * - * @return MappingException - */ - public static function noSingleAssociationJoinColumnFound($className, $field) + public static function noSingleAssociationJoinColumnFound(string $className, string $field): self { return new self(sprintf("'%s#%s' is not an association with a single join column.", $className, $field)); } - /** - * @param string $className - * @param string $column - * - * @return MappingException - */ - public static function noFieldNameFoundForColumn($className, $column) + public static function noFieldNameFoundForColumn(string $className, string $column): self { return new self(sprintf( "Cannot find a field on '%s' that is mapped to column '%s'. Either the " . @@ -634,13 +414,7 @@ public static function noFieldNameFoundForColumn($className, $column) )); } - /** - * @param string $className - * @param string $field - * - * @return MappingException - */ - public static function illegalOrphanRemovalOnIdentifierAssociation($className, $field) + public static function illegalOrphanRemovalOnIdentifierAssociation(string $className, string $field): self { return new self(sprintf( "The orphan removal option is not allowed on an association that is part of the identifier in '%s#%s'.", @@ -649,25 +423,13 @@ public static function illegalOrphanRemovalOnIdentifierAssociation($className, $ )); } - /** - * @param string $className - * @param string $field - * - * @return MappingException - */ - public static function illegalOrphanRemoval($className, $field) + public static function illegalOrphanRemoval(string $className, string $field): self { return new self('Orphan removal is only allowed on one-to-one and one-to-many ' . 'associations, but ' . $className . '#' . $field . ' is not.'); } - /** - * @param string $className - * @param string $field - * - * @return MappingException - */ - public static function illegalInverseIdentifierAssociation($className, $field) + public static function illegalInverseIdentifierAssociation(string $className, string $field): self { return new self(sprintf( "An inverse association is not allowed to be identifier in '%s#%s'.", @@ -676,13 +438,7 @@ public static function illegalInverseIdentifierAssociation($className, $field) )); } - /** - * @param string $className - * @param string $field - * - * @return MappingException - */ - public static function illegalToManyIdentifierAssociation($className, $field) + public static function illegalToManyIdentifierAssociation(string $className, string $field): self { return new self(sprintf( "Many-to-many or one-to-many associations are not allowed to be identifier in '%s#%s'.", @@ -691,23 +447,12 @@ public static function illegalToManyIdentifierAssociation($className, $field) )); } - /** - * @param string $className - * - * @return MappingException - */ - public static function noInheritanceOnMappedSuperClass($className) + public static function noInheritanceOnMappedSuperClass(string $className): self { return new self("It is not supported to define inheritance information on a mapped superclass '" . $className . "'."); } - /** - * @param string $className - * @param string $rootClassName - * - * @return MappingException - */ - public static function mappedClassNotPartOfDiscriminatorMap($className, $rootClassName) + public static function mappedClassNotPartOfDiscriminatorMap(string $className, string $rootClassName): self { return new self( "Entity '" . $className . "' has to be part of the discriminator map of '" . $rootClassName . "' " . @@ -716,48 +461,22 @@ public static function mappedClassNotPartOfDiscriminatorMap($className, $rootCla ); } - /** - * @param string $className - * @param string $methodName - * - * @return MappingException - */ - public static function lifecycleCallbackMethodNotFound($className, $methodName) + public static function lifecycleCallbackMethodNotFound(string $className, string $methodName): self { return new self("Entity '" . $className . "' has no method '" . $methodName . "' to be registered as lifecycle callback."); } - /** - * @param string $listenerName - * @param string $className - * - * @return MappingException - */ - public static function entityListenerClassNotFound($listenerName, $className) + public static function entityListenerClassNotFound(string $listenerName, string $className): self { return new self(sprintf('Entity Listener "%s" declared on "%s" not found.', $listenerName, $className)); } - /** - * @param string $listenerName - * @param string $methodName - * @param string $className - * - * @return MappingException - */ - public static function entityListenerMethodNotFound($listenerName, $methodName, $className) + public static function entityListenerMethodNotFound(string $listenerName, string $methodName, string $className): self { return new self(sprintf('Entity Listener "%s" declared on "%s" has no method "%s".', $listenerName, $className, $methodName)); } - /** - * @param string $listenerName - * @param string $methodName - * @param string $className - * - * @return MappingException - */ - public static function duplicateEntityListener($listenerName, $methodName, $className) + public static function duplicateEntityListener(string $listenerName, string $methodName, string $className): self { return new self(sprintf('Entity Listener "%s#%s()" in "%s" was already declared, but it must be declared only once.', $listenerName, $methodName, $className)); } @@ -768,46 +487,25 @@ public static function invalidFetchMode(string $className, string $fetchMode): s return new self("Entity '" . $className . "' has a mapping with invalid fetch mode '" . $fetchMode . "'"); } - /** @param int|string $generatedMode */ - public static function invalidGeneratedMode($generatedMode): self + public static function invalidGeneratedMode(int|string $generatedMode): self { return new self("Invalid generated mode '" . $generatedMode . "'"); } - /** - * @param string $className - * - * @return MappingException - */ - public static function compositeKeyAssignedIdGeneratorRequired($className) + public static function compositeKeyAssignedIdGeneratorRequired(string $className): self { return new self("Entity '" . $className . "' has a composite identifier but uses an ID generator other than manually assigning (Identity, Sequence). This is not supported."); } - /** - * @param string $targetEntity - * @param string $sourceEntity - * @param string $associationName - * - * @return MappingException - */ - public static function invalidTargetEntityClass($targetEntity, $sourceEntity, $associationName) + public static function invalidTargetEntityClass(string $targetEntity, string $sourceEntity, string $associationName): self { return new self('The target-entity ' . $targetEntity . " cannot be found in '" . $sourceEntity . '#' . $associationName . "'."); } - /** - * @param string[] $cascades - * @param string $className - * @param string $propertyName - * - * @return MappingException - */ - public static function invalidCascadeOption(array $cascades, $className, $propertyName) + /** @param string[] $cascades */ + public static function invalidCascadeOption(array $cascades, string $className, string $propertyName): self { - $cascades = implode(', ', array_map(static function ($e) { - return "'" . $e . "'"; - }, $cascades)); + $cascades = implode(', ', array_map(static fn (string $e): string => "'" . $e . "'", $cascades)); return new self(sprintf( "You have specified invalid cascade options for %s::$%s: %s; available options: 'remove', 'persist', 'refresh', 'merge', and 'detach'", @@ -817,25 +515,14 @@ public static function invalidCascadeOption(array $cascades, $className, $proper )); } - /** - * @param string $className - * - * @return MappingException - */ - public static function missingSequenceName($className) + public static function missingSequenceName(string $className): self { return new self( sprintf('Missing "sequenceName" attribute for sequence id generator definition on class "%s".', $className), ); } - /** - * @param string $className - * @param string $propertyName - * - * @return MappingException - */ - public static function infiniteEmbeddableNesting($className, $propertyName) + public static function infiniteEmbeddableNesting(string $className, string $propertyName): self { return new self( sprintf( @@ -847,13 +534,7 @@ public static function infiniteEmbeddableNesting($className, $propertyName) ); } - /** - * @param string $className - * @param string $propertyName - * - * @return self - */ - public static function illegalOverrideOfInheritedProperty($className, $propertyName) + public static function illegalOverrideOfInheritedProperty(string $className, string $propertyName): self { return new self( sprintf( @@ -865,8 +546,7 @@ public static function illegalOverrideOfInheritedProperty($className, $propertyN ); } - /** @return self */ - public static function invalidIndexConfiguration($className, $indexName) + public static function invalidIndexConfiguration(string $className, string $indexName): self { return new self( sprintf( @@ -877,8 +557,7 @@ public static function invalidIndexConfiguration($className, $indexName) ); } - /** @return self */ - public static function invalidUniqueConstraintConfiguration($className, $indexName) + public static function invalidUniqueConstraintConfiguration(string $className, string $indexName): self { return new self( sprintf( @@ -889,8 +568,7 @@ public static function invalidUniqueConstraintConfiguration($className, $indexNa ); } - /** @param mixed $givenValue */ - public static function invalidOverrideType(string $expectdType, $givenValue): self + public static function invalidOverrideType(string $expectdType, mixed $givenValue): self { return new self(sprintf( 'Expected %s, but %s was given.', @@ -937,14 +615,12 @@ public static function invalidEnumValue( /** @param LibXMLError[] $errors */ public static function fromLibXmlErrors(array $errors): self { - $formatter = static function (LibXMLError $error): string { - return sprintf( - 'libxml error: %s in %s at line %d', - $error->message, - $error->file, - $error->line, - ); - }; + $formatter = static fn (LibXMLError $error): string => sprintf( + 'libxml error: %s in %s at line %d', + $error->message, + $error->file, + $error->line, + ); return new self(implode(PHP_EOL, array_map($formatter, $errors))); } diff --git a/lib/Doctrine/ORM/Query/QueryException.php b/lib/Doctrine/ORM/Query/QueryException.php index d1140931c59..98dc6e52c85 100644 --- a/lib/Doctrine/ORM/Query/QueryException.php +++ b/lib/Doctrine/ORM/Query/QueryException.php @@ -8,112 +8,61 @@ use Doctrine\ORM\Query\AST\PathExpression; use Exception; use Stringable; +use Throwable; class QueryException extends Exception implements ORMException { - /** - * @param string $dql - * - * @return QueryException - */ - public static function dqlError($dql) + public static function dqlError(string $dql): self { return new self($dql); } - /** - * @param string $message - * @param Exception|null $previous - * - * @return QueryException - */ - public static function syntaxError($message, $previous = null) + public static function syntaxError(string $message, Throwable|null $previous = null): self { return new self('[Syntax Error] ' . $message, 0, $previous); } - /** - * @param string $message - * @param Exception|null $previous - * - * @return QueryException - */ - public static function semanticalError($message, $previous = null) + public static function semanticalError(string $message, Throwable|null $previous = null): self { return new self('[Semantical Error] ' . $message, 0, $previous); } - /** @return QueryException */ - public static function invalidLockMode() + public static function invalidLockMode(): self { return new self('Invalid lock mode hint provided.'); } - /** - * @param string $expected - * @param string $received - * - * @return QueryException - */ - public static function invalidParameterType($expected, $received) + public static function invalidParameterType(string $expected, string $received): self { return new self('Invalid parameter type, ' . $received . ' given, but ' . $expected . ' expected.'); } - /** - * @param string $pos - * - * @return QueryException - */ - public static function invalidParameterPosition($pos) + public static function invalidParameterPosition(string $pos): self { return new self('Invalid parameter position: ' . $pos); } - /** - * @param int $expected - * @param int $received - * - * @return QueryException - */ - public static function tooManyParameters($expected, $received) + public static function tooManyParameters(int $expected, int $received): self { return new self('Too many parameters: the query defines ' . $expected . ' parameters and you bound ' . $received); } - /** - * @param int $expected - * @param int $received - * - * @return QueryException - */ - public static function tooFewParameters($expected, $received) + public static function tooFewParameters(int $expected, int $received): self { return new self('Too few parameters: the query defines ' . $expected . ' parameters but you only bound ' . $received); } - /** - * @param string $value - * - * @return QueryException - */ - public static function invalidParameterFormat($value) + public static function invalidParameterFormat(string $value): self { return new self('Invalid parameter format, ' . $value . ' given, but : or ? expected.'); } - /** - * @param string $key - * - * @return QueryException - */ - public static function unknownParameter($key) + public static function unknownParameter(string $key): self { return new self('Invalid parameter: token ' . $key . ' is not defined in the query.'); } - /** @return QueryException */ - public static function parameterTypeMismatch() + public static function parameterTypeMismatch(): self { return new self('DQL Query parameter and type numbers mismatch, but have to be exactly equal.'); } @@ -133,10 +82,8 @@ public static function invalidLiteral(string|Stringable $literal): self /** * @param string[] $assoc * @psalm-param array $assoc - * - * @return QueryException */ - public static function iterateWithFetchJoinCollectionNotAllowed($assoc) + public static function iterateWithFetchJoinCollectionNotAllowed(array $assoc): self { return new self( 'Invalid query operation: Not allowed to iterate over fetch join collections ' . @@ -144,8 +91,7 @@ public static function iterateWithFetchJoinCollectionNotAllowed($assoc) ); } - /** @return QueryException */ - public static function partialObjectsAreDangerous() + public static function partialObjectsAreDangerous(): self { return new self( 'Loading partial objects is dangerous. Fetch full objects or consider ' . @@ -157,10 +103,8 @@ public static function partialObjectsAreDangerous() /** * @param string[] $assoc * @psalm-param array $assoc - * - * @return QueryException */ - public static function overwritingJoinConditionsNotYetSupported($assoc) + public static function overwritingJoinConditionsNotYetSupported(array $assoc): self { return new self( 'Unsupported query operation: It is not yet possible to overwrite the join ' . @@ -169,8 +113,7 @@ public static function overwritingJoinConditionsNotYetSupported($assoc) ); } - /** @return QueryException */ - public static function associationPathInverseSideNotSupported(PathExpression $pathExpr) + public static function associationPathInverseSideNotSupported(PathExpression $pathExpr): self { return new self( 'A single-valued association path expression to an inverse side is not supported in DQL queries. ' . @@ -181,10 +124,8 @@ public static function associationPathInverseSideNotSupported(PathExpression $pa /** * @param string[] $assoc * @psalm-param array $assoc - * - * @return QueryException */ - public static function iterateWithFetchJoinNotAllowed($assoc) + public static function iterateWithFetchJoinNotAllowed(array $assoc): self { return new self( 'Iterate with fetch join in class ' . $assoc['sourceEntity'] . @@ -192,13 +133,12 @@ public static function iterateWithFetchJoinNotAllowed($assoc) ); } - public static function iterateWithMixedResultNotAllowed(): QueryException + public static function iterateWithMixedResultNotAllowed(): self { return new self('Iterating a query with mixed results (using scalars) is not supported.'); } - /** @return QueryException */ - public static function associationPathCompositeKeyNotSupported() + public static function associationPathCompositeKeyNotSupported(): self { return new self( 'A single-valued association path expression to an entity with a composite primary ' . @@ -207,24 +147,13 @@ public static function associationPathCompositeKeyNotSupported() ); } - /** - * @param string $className - * @param string $rootClass - * - * @return QueryException - */ - public static function instanceOfUnrelatedClass($className, $rootClass) + public static function instanceOfUnrelatedClass(string $className, string $rootClass): self { return new self("Cannot check if a child of '" . $rootClass . "' is instanceof '" . $className . "', " . 'inheritance hierarchy does not exists between these two classes.'); } - /** - * @param string $dqlAlias - * - * @return QueryException - */ - public static function invalidQueryComponent($dqlAlias) + public static function invalidQueryComponent(string $dqlAlias): self { return new self( "Invalid query component given for DQL alias '" . $dqlAlias . "', " . diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 2733dc0e97d..cbcd6c74fa8 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -136,7 +136,7 @@ private function getIndexColumns(ClassMetadata $class, array $indexData): array ) ) { throw MappingException::invalidIndexConfiguration( - $class, + (string) $class, $indexData['name'] ?? 'unnamed', ); } diff --git a/psalm-baseline.xml b/psalm-baseline.xml index de2880487bf..21d535dc458 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -623,14 +623,6 @@ $xmlRoot->getName() === 'mapped-superclass' - - - $className - $className - $indexName - $indexName - - $object