diff --git a/lib/Doctrine/ORM/Cache/Lock.php b/lib/Doctrine/ORM/Cache/Lock.php index fc48d508ebe..efa57303c15 100644 --- a/lib/Doctrine/ORM/Cache/Lock.php +++ b/lib/Doctrine/ORM/Cache/Lock.php @@ -24,6 +24,6 @@ public function __construct(string $value, ?int $time = null) */ public static function createLockRead() { - return new self(uniqid(time(), true)); + return new self(uniqid((string) time(), true)); } } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 2ac9b43ff33..562290337f0 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -614,7 +614,7 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class): void $sequenceGenerator = new SequenceGenerator( $this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $this->getTargetPlatform()), - $definition['allocationSize'] + (int) $definition['allocationSize'] ); $class->setIdGenerator($sequenceGenerator); break; diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index d22e845a745..c5de857065c 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -610,13 +610,13 @@ class ClassMetadataInfo implements ClassMetadata * * array( * 'sequenceName' => 'name', - * 'allocationSize' => 20, - * 'initialValue' => 1 + * 'allocationSize' => '20', + * 'initialValue' => '1' * ) * * * @var mixed[] - * @psalm-var array{sequenceName: string, allocationSize: int, initialValue: int} + * @psalm-var array{sequenceName: string, allocationSize: string, initialValue: string, quoted?: mixed} * @todo Merge with tableGeneratorDefinition into generic generatorDefinition */ public $sequenceGeneratorDefinition; @@ -3289,7 +3289,7 @@ public function setCustomGeneratorDefinition(array $definition) * ) * * - * @psalm-param array $definition + * @psalm-param array{sequenceName?: string, allocationSize?: int|string, initialValue?: int|string, quoted?: mixed} $definition * * @return void * @@ -3306,14 +3306,17 @@ public function setSequenceGeneratorDefinition(array $definition) $definition['quoted'] = true; } - if (! isset($definition['allocationSize']) || trim($definition['allocationSize']) === '') { + if (! isset($definition['allocationSize']) || trim((string) $definition['allocationSize']) === '') { $definition['allocationSize'] = '1'; } - if (! isset($definition['initialValue']) || trim($definition['initialValue']) === '') { + if (! isset($definition['initialValue']) || trim((string) $definition['initialValue']) === '') { $definition['initialValue'] = '1'; } + $definition['allocationSize'] = (string) $definition['allocationSize']; + $definition['initialValue'] = (string) $definition['initialValue']; + $this->sequenceGeneratorDefinition = $definition; } diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 4b7c94635cd..fb2dd22a43e 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -863,7 +863,7 @@ private function columnToArray(SimpleXMLElement $fieldMapping): array private function cacheToArray(SimpleXMLElement $cacheMapping): array { $region = isset($cacheMapping['region']) ? (string) $cacheMapping['region'] : null; - $usage = isset($cacheMapping['usage']) ? strtoupper($cacheMapping['usage']) : null; + $usage = isset($cacheMapping['usage']) ? strtoupper((string) $cacheMapping['usage']) : null; if ($usage && ! defined('Doctrine\ORM\Mapping\ClassMetadata::CACHE_USAGE_' . $usage)) { throw new InvalidArgumentException(sprintf('Invalid cache usage "%s"', $usage)); diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index bf43ee7c434..9903c41428e 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -179,7 +179,7 @@ public function containsKey(PersistentCollection $collection, $key) [$quotedJoinTable, $whereClauses, $params, $types] = $this->getJoinTableRestrictionsWithKey( $collection, - $key, + (string) $key, true ); diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 9cc53f2a98a..720b4b63940 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -493,7 +493,7 @@ public function syntaxError($expected = '', $token = null) $message .= $expected !== '' ? sprintf('Expected %s, got ', $expected) : 'Unexpected '; $message .= $this->lexer->lookahead === null ? 'end of string.' : sprintf("'%s'", $token['value']); - throw QueryException::syntaxError($message, QueryException::dqlError($this->query->getDQL())); + throw QueryException::syntaxError($message, QueryException::dqlError($this->query->getDQL() ?? '')); } /** @@ -524,7 +524,7 @@ public function semanticalError($message = '', $token = null) $length = $pos !== false ? $pos - $token['position'] : $distance; $tokenPos = isset($token['position']) && $token['position'] > 0 ? $token['position'] : '-1'; - $tokenStr = substr($dql, $token['position'], $length); + $tokenStr = substr($dql, (int) $token['position'], $length); // Building informative message $message = 'line 0, col ' . $tokenPos . " near '" . $tokenStr . "': Error: " . $message; diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 846ef4e1646..5e41ff23757 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -2120,7 +2120,7 @@ public function walkLiteral($literal) return $this->conn->getDatabasePlatform()->convertBooleans(strtolower($literal->value) === 'true'); case AST\Literal::NUMERIC: - return $literal->value; + return (string) $literal->value; default: throw QueryException::invalidLiteral($literal); diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index 8feaece2567..251b4b9ee81 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -976,7 +976,7 @@ public function join($join, $alias, $conditionType = null, $condition = null, $i */ public function innerJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null) { - $parentAlias = substr($join, 0, strpos($join, '.')); + $parentAlias = substr($join, 0, (int) strpos($join, '.')); $rootAlias = $this->findRootAlias($alias, $parentAlias); diff --git a/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php b/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php index f34bd9426f3..a82cfbceadf 100644 --- a/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php +++ b/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php @@ -230,15 +230,15 @@ private function convertColumn( $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE); $definition = [ - 'sequenceName' => is_array($column['sequence']) ? $column['sequence']['name'] : $column['sequence'], + 'sequenceName' => (string) (is_array($column['sequence']) ? $column['sequence']['name'] : $column['sequence']), ]; if (isset($column['sequence']['size'])) { - $definition['allocationSize'] = $column['sequence']['size']; + $definition['allocationSize'] = (int) $column['sequence']['size']; } if (isset($column['sequence']['value'])) { - $definition['initialValue'] = $column['sequence']['value']; + $definition['initialValue'] = (int) $column['sequence']['value']; } $metadata->setSequenceGeneratorDefinition($definition); diff --git a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php index 08a171d02bc..562b2b41b98 100644 --- a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php @@ -82,7 +82,7 @@ public function generateEntityRepositoryClass($fullClassName) */ private function getClassNamespace(string $fullClassName): string { - return substr($fullClassName, 0, strrpos($fullClassName, '\\')); + return substr($fullClassName, 0, (int) strrpos($fullClassName, '\\')); } /** diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index 2afa4d8e15d..fbd0207e1a9 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -182,7 +182,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) } if (isset($field['length'])) { - $fieldXml->addAttribute('length', $field['length']); + $fieldXml->addAttribute('length', (string) $field['length']); } if (isset($field['precision'])) { @@ -200,7 +200,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) if (isset($field['options'])) { $optionsXml = $fieldXml->addChild('options'); foreach ($field['options'] as $key => $value) { - $optionXml = $optionsXml->addChild('option', $value); + $optionXml = $optionsXml->addChild('option', (string) $value); $optionXml->addAttribute('name', $key); } } @@ -230,7 +230,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) $a1 = array_search($m1['type'], $orderMap); $a2 = array_search($m2['type'], $orderMap); - return strcmp($a1, $a2); + return strcmp((string) $a1, (string) $a2); }); foreach ($metadata->associationMappings as $associationMapping) { diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 7e628afe8db..4684ca75234 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -378,8 +378,8 @@ static function (ClassMetadata $class) use ($idMapping): bool { if (! $schema->hasSequence($quotedName)) { $schema->createSequence( $quotedName, - $seqDef['allocationSize'], - $seqDef['initialValue'] + (int) $seqDef['allocationSize'], + (int) $seqDef['initialValue'] ); } } diff --git a/lib/Doctrine/ORM/Tools/ToolsException.php b/lib/Doctrine/ORM/Tools/ToolsException.php index 7ba762015ce..2da38e4c5fb 100644 --- a/lib/Doctrine/ORM/Tools/ToolsException.php +++ b/lib/Doctrine/ORM/Tools/ToolsException.php @@ -15,7 +15,11 @@ class ToolsException extends ORMException { public static function schemaToolFailure(string $sql, Throwable $e): self { - return new self("Schema-Tool failed with Error '" . $e->getMessage() . "' while executing DDL: " . $sql, '0', $e); + return new self( + "Schema-Tool failed with Error '" . $e->getMessage() . "' while executing DDL: " . $sql, + 0, + $e + ); } /** diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 502c379da8d..38d4c8d2dd4 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -45,11 +45,6 @@ parameters: count: 1 path: lib/Doctrine/ORM/Cache/DefaultQueryCache.php - - - message: "#^Parameter \\#1 \\$prefix of function uniqid expects string, int given\\.$#" - count: 1 - path: lib/Doctrine/ORM/Cache/Lock.php - - message: "#^Access to an undefined property Doctrine\\\\ORM\\\\Cache\\\\CacheEntry\\:\\:\\$identifiers\\.$#" count: 1 @@ -450,16 +445,6 @@ parameters: count: 1 path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php - - - message: "#^Parameter \\#1 \\$definition of method Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\\\:\\:setSequenceGeneratorDefinition\\(\\) expects array\\, array\\ given\\.$#" - count: 1 - path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php - - - - message: "#^Parameter \\#1 \\$definition of method Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\\\:\\:setSequenceGeneratorDefinition\\(\\) expects array\\, array\\ given\\.$#" - count: 1 - path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php - - message: "#^Parameter \\#1 \\$subClass of method Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataFactory\\:\\:addInheritedEmbeddedClasses\\(\\) expects Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata, Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata given\\.$#" count: 1 @@ -590,11 +575,6 @@ parameters: count: 1 path: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php - - - message: "#^Property Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\\\:\\:\\$sequenceGeneratorDefinition \\(array\\('sequenceName' \\=\\> string, 'allocationSize' \\=\\> int, 'initialValue' \\=\\> int\\)\\) does not accept array\\\\.$#" - count: 1 - path: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php - - message: "#^Result of && is always false\\.$#" count: 2 @@ -795,11 +775,6 @@ parameters: count: 2 path: lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php - - - message: "#^Parameter \\#1 \\$definition of method Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo\\\\:\\:setSequenceGeneratorDefinition\\(\\) expects array\\, array\\ given\\.$#" - count: 1 - path: lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php - - message: "#^Parameter \\#1 \\$metadata of static method Doctrine\\\\ORM\\\\Mapping\\\\Builder\\\\EntityListenerBuilder\\:\\:bindEntityListener\\(\\) expects Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata, Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo&Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\ given\\.$#" count: 1 @@ -2161,24 +2136,14 @@ parameters: count: 1 path: lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php - - - message: "#^Parameter \\#1 \\$str1 of function strcmp expects string, int\\|false given\\.$#" - count: 1 - path: lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php - - message: "#^Parameter \\#1 \\$type of method Doctrine\\\\ORM\\\\Tools\\\\Export\\\\Driver\\\\AbstractExporter\\:\\:_getIdGeneratorTypeString\\(\\) expects 1\\|2\\|3\\|4\\|5\\|6\\|7, int given\\.$#" count: 2 path: lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php - - - message: "#^Parameter \\#2 \\$str2 of function strcmp expects string, int\\|false given\\.$#" - count: 1 - path: lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php - - message: "#^Parameter \\#2 \\$value of method SimpleXMLElement\\:\\:addAttribute\\(\\) expects string, int given\\.$#" - count: 6 + count: 3 path: lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php - @@ -2236,11 +2201,6 @@ parameters: count: 1 path: lib/Doctrine/ORM/Tools/SchemaTool.php - - - message: "#^Parameter \\#2 \\$code of class Doctrine\\\\ORM\\\\Tools\\\\ToolsException constructor expects int, string given\\.$#" - count: 1 - path: lib/Doctrine/ORM/Tools/ToolsException.php - - message: "#^Binary operation \"&\" between string and 3 results in an error\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index febc179f0f5..55a79b4939c 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -175,11 +175,6 @@ loadCacheEntry - - - time() - - collectionCacheHit @@ -911,10 +906,6 @@ $subClass->table[$indexType][$indexName] - - $definition - $parent->sequenceGeneratorDefinition - $driver $evm @@ -1025,9 +1016,6 @@ ReflectionProperty ReflectionProperty - - $definition - $type @@ -1262,7 +1250,6 @@ $value[1] $value[1] - $entityAnnotationClasses @@ -1351,9 +1338,6 @@ $metadata - - $cacheMapping['usage'] - $fileExtension @@ -2643,7 +2627,7 @@ $this->ConditionalExpression() $this->ConditionalExpression() - + $aliasIdentVariable $dql $dql @@ -3196,7 +3180,7 @@ $this->cacheMode - + $spacePos $spacePos strpos($join, '.') @@ -3604,9 +3588,6 @@ EntityRepository::class - - strrpos($fullClassName, '\\') - strrpos($fullClassName, '\\') @@ -3686,13 +3667,11 @@ AbstractExporter - + $field['length'] $field['length'] $field['precision'] $field['scale'] - $sequenceDefinition['allocationSize'] - $sequenceDefinition['initialValue'] $m1 @@ -3862,11 +3841,6 @@ require_once $directory . '/Doctrine/Common/ClassLoader.php' - - - '0' - - $class diff --git a/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php b/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php index 3caceea7a1f..00aaef7c443 100644 --- a/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php @@ -282,9 +282,9 @@ private function cleanTestDirectory(?string $path): void foreach ($directoryIterator as $file) { if ($file->isFile()) { - @unlink($file->getRealPath()); + @unlink((string) $file->getRealPath()); } else { - @rmdir($file->getRealPath()); + @rmdir((string) $file->getRealPath()); } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php index 62cc432cc4f..bd29361da80 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php @@ -251,7 +251,10 @@ public function testOptimisticTimestampLockFailureThrowsException(OptimisticTime $caughtException = null; try { - $expectedVersionExpired = DateTime::createFromFormat('U', $test->version->getTimestamp() - 3600); + $expectedVersionExpired = DateTime::createFromFormat( + 'U', + (string) ($test->version->getTimestamp() - 3600) + ); $this->_em->lock($test, LockMode::OPTIMISTIC, $expectedVersionExpired); } catch (OptimisticLockException $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5887Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5887Test.php index 078902c46c1..debd75072c8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5887Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5887Test.php @@ -187,7 +187,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - return new GH5887CustomIdObject($value); + return new GH5887CustomIdObject((int) $value); } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php index 3256e6e9815..bce3b638b24 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php @@ -84,9 +84,9 @@ protected function tearDown(): void foreach ($iterator as $path) { if ($path->isDir()) { - @rmdir($path); + @rmdir((string) $path); } else { - @unlink($path); + @unlink((string) $path); } } diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index edcfb6971e9..e666186112d 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -516,7 +516,7 @@ public function testNonExistentExecutor(): void $this->expectException(QueryException::class); $this->expectExceptionMessage('[Syntax Error] line 0, col -1: Error: Expected SELECT, UPDATE or DELETE, got end of string.'); - $query = $this->entityManager->createQuery('0')->execute(); + $this->entityManager->createQuery('0')->execute(); } /**