Skip to content

Commit

Permalink
psalm improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
michnovka committed Dec 15, 2022
1 parent a044685 commit 25fbeca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
10 changes: 6 additions & 4 deletions lib/Doctrine/ORM/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Doctrine\ORM\Exception\UnknownEntityNamespace;
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\DefaultEntityListenerResolver;
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
use Doctrine\ORM\Mapping\DefaultQuoteStrategy;
Expand Down Expand Up @@ -64,6 +65,7 @@
* Internal note: When adding a new configuration option just write a getter/setter pair.
*
* @psalm-import-type AutogenerateMode from ProxyFactory
* @psalm-import-type ScalarName from ClassMetadataInfo
*/
class Configuration extends \Doctrine\DBAL\Configuration
{
Expand Down Expand Up @@ -756,7 +758,7 @@ public function setCustomDatetimeFunctions(array $functions)
* Values are either FQCNs of DBAL Type or their name
*
* @param array $mappings The map of custom DQL date/time functions.
* @psalm-param array<class-string|string, class-string<Type>|string> $mappings
* @psalm-param array<class-string|ScalarName, class-string<Type>|string> $mappings
*/
public function setTypedFieldMappings(array $mappings): void
{
Expand All @@ -770,7 +772,7 @@ public function setTypedFieldMappings(array $mappings): void
* With this configuration option used there is no need to specify the Column::type
* for given explicitly typed field.
*
* @psalm-param class-string|string $phpType the FQCN of PHP type to be mapped
* @psalm-param class-string|ScalarName $phpType the FQCN of PHP type to be mapped
* @psalm-param class-string<Type>|string $dbalType either FQCN of DBAL Type or its name
*/
public function addTypedFieldMapping(string $phpType, string $dbalType): void
Expand All @@ -781,7 +783,7 @@ public function addTypedFieldMapping(string $phpType, string $dbalType): void
/**
* Gets the mapped DBAL Type for given PHP type
*
* @psalm-param class-string $phpType the FQCN of PHP type to be mapped
* @psalm-param class-string|ScalarName $phpType the FQCN of PHP type to be mapped
*
* @psalm-return class-string<Type>|string|null either FQCN of DBAL Type or its name
*/
Expand All @@ -793,7 +795,7 @@ public function getTypedFieldMapping($phpType): ?string
/**
* Gets the array of all the PHP type => DBAL Type mappings
*
* @psalm-return array<class-string,class-string<Type>|string>
* @psalm-return array<class-string|ScalarName,class-string<Type>|string>
*/
public function getTypedFieldMappings(): array
{
Expand Down
5 changes: 3 additions & 2 deletions lib/Doctrine/ORM/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/**
* {@inheritDoc}
*
* @psalm-import-type ScalarName from ClassMetadataInfo
* @todo remove or rename ClassMetadataInfo to ClassMetadata
* @template-covariant T of object
* @template-extends ClassMetadataInfo<T>
Expand All @@ -20,8 +21,8 @@ class ClassMetadata extends ClassMetadataInfo
*
* @see https://github.com/doctrine/orm/issues/8709
*
* @param string $entityName The name of the entity class the new instance is used for.
* @param array<class-string|string, class-string<Type>|string> $typedFieldMappings
* @param string $entityName The name of the entity class the new instance is used for.
* @param array<class-string|ScalarName, class-string<Type>|string> $typedFieldMappings
* @psalm-param class-string<T> $entityName
*/
public function __construct($entityName, ?NamingStrategy $namingStrategy = null, array $typedFieldMappings = [])
Expand Down
7 changes: 4 additions & 3 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
* type: int,
* unique?: bool,
* }
* @psalm-type ScalarName = 'array'|'bool'|'float'|'int'|'string'
*/
class ClassMetadataInfo implements ClassMetadata
{
Expand Down Expand Up @@ -800,15 +801,15 @@ class ClassMetadataInfo implements ClassMetadata
/** @var InstantiatorInterface|null */
private $instantiator;

/** @var array<class-string|string,class-string<Type>|string> $typedFieldMappings */
/** @var array<class-string|ScalarName,class-string<Type>|string> $typedFieldMappings */
private $typedFieldMappings;

/**
* Initializes a new ClassMetadata instance that will hold the object-relational mapping
* metadata of the class with the given name.
*
* @param string $entityName The name of the entity class the new instance is used for.
* @param array<class-string|string, class-string<Type>|string> $typedFieldMappings
* @param string $entityName The name of the entity class the new instance is used for.
* @param array<class-string|ScalarName, class-string<Type>|string> $typedFieldMappings
* @psalm-param class-string<T> $entityName
*/
public function __construct($entityName, ?NamingStrategy $namingStrategy = null, array $typedFieldMappings = [])
Expand Down

0 comments on commit 25fbeca

Please sign in to comment.