Skip to content

Commit

Permalink
Merge branch '2.13.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.13.x:
  PHPStan 1.7.9 (doctrine#9812)
  Remove empty test file (doctrine#9805)
  Remove calls to deprecated MockBuilder::setMethods() (doctrine#9808)
  Deprecate passing null to Query::setFirstResult()
  Rename Abstract*Test to *TestCase (doctrine#9806)
  Add primary key on temp table (doctrine#9770)
  Fix wrong types (doctrine#9802)
  Widen return type
  Update baseline
  Fix
  Add type for AssociationMapping
  • Loading branch information
derrabus committed Jun 3, 2022
2 parents ec03eb3 + ddede40 commit b8299fe
Show file tree
Hide file tree
Showing 59 changed files with 484 additions and 182 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ Use `toIterable()` instead.

# Upgrade to 2.13

## Deprecated passing `null` to `Doctrine\ORM\Query::setFirstResult()`

`$query->setFirstResult(null);` is equivalent to `$query->setFirstResult(0)`.

## Deprecated calling setters without arguments

The following methods will require an argument in 3.0. Pass `null` instead of
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"doctrine/annotations": "^1.13",
"doctrine/coding-standard": "^9.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "1.7.0",
"phpstan/phpstan": "1.7.9",
"phpunit/phpunit": "^9.5",
"psr/log": "^1 || ^2 || ^3",
"squizlabs/php_codesniffer": "3.6.2",
Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,7 @@ public function setParameter($key, $value, $type = null)
*
* @param mixed $value
*
* @return mixed[]|string|int|float|bool|object|null
* @psalm-return array|scalar|object|null
* @return mixed
*
* @throws ORMInvalidArgumentException
*/
Expand Down
43 changes: 39 additions & 4 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,41 @@
* declaredField?: string,
* options?: array<string, mixed>
* }
* @psalm-type AssociationMapping = array{
* cache?: array,
* cascade?: array<string>,
* declared?: class-string,
* fetch?: mixed,
* fieldName: string,
* id?: bool,
* inherited?: class-string,
* indexBy?: string,
* inversedBy?: string|null,
* isCascadeRemove?: bool,
* isCascadePersist?: bool,
* isCascadeRefresh?: bool,
* isCascadeMerge?: bool,
* isCascadeDetach?: bool,
* isOnDeleteCascade?: bool,
* isOwningSide?: bool,
* joinColumns?: array,
* joinColumnFieldNames?: array,
* joinTable?: array,
* joinTableColumns?: list<mixed>,
* mappedBy?: string|null,
* orderBy?: array,
* originalClass?: class-string,
* originalField?: string,
* orphanRemoval?: bool,
* relationToSourceKeyColumns?: array,
* relationToTargetKeyColumns?: array,
* sourceEntity?: class-string,
* sourceToTargetKeyColumns?: array,
* targetEntity: class-string,
* targetToSourceKeyColumns: array,
* type: int,
* unique?: bool,
* }
*/
class ClassMetadataInfo implements ClassMetadata
{
Expand Down Expand Up @@ -578,7 +613,7 @@ class ClassMetadataInfo implements ClassMetadata
* )
* </pre>
*
* @psalm-var array<string, array<string, mixed>>
* @psalm-var array<string, AssociationMapping>
*/
public $associationMappings = [];

Expand Down Expand Up @@ -1317,7 +1352,7 @@ public function getFieldMapping($fieldName)
* the object model.
*
* @return mixed[] The mapping.
* @psalm-return array<string, mixed>
* @psalm-return AssociationMapping
*
* @throws MappingException
*/
Expand All @@ -1333,7 +1368,7 @@ public function getAssociationMapping($fieldName)
/**
* Gets all association mappings of the class.
*
* @psalm-return array<string, array<string, mixed>>
* @psalm-return array<string, AssociationMapping>
*/
public function getAssociationMappings()
{
Expand Down Expand Up @@ -2565,7 +2600,7 @@ public function mapField(array $mapping)
* Adds an association mapping without completing/validating it.
* This is mainly used to add inherited association mappings to derived classes.
*
* @psalm-param array<string, mixed> $mapping
* @psalm-param AssociationMapping $mapping
*
* @return void
*
Expand Down
17 changes: 15 additions & 2 deletions lib/Doctrine/ORM/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use function count;
use function get_debug_type;
use function in_array;
use function is_int;
use function ksort;
use function md5;
use function reset;
Expand Down Expand Up @@ -479,7 +480,7 @@ public function useQueryCache($bool): self
/**
* Defines how long the query cache will be active before expire.
*
* @param int $timeToLive How long the cache entry is valid.
* @param int|null $timeToLive How long the cache entry is valid.
*
* @return $this
*/
Expand Down Expand Up @@ -599,7 +600,19 @@ public function contains($dql): bool
*/
public function setFirstResult($firstResult): self
{
$this->firstResult = (int) $firstResult;
if (! is_int($firstResult)) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/9809',
'Calling %s with %s is deprecated and will result in a TypeError in Doctrine 3.0. Pass an integer.',
__METHOD__,
get_debug_type($firstResult)
);

$firstResult = (int) $firstResult;
}

$this->firstResult = $firstResult;
$this->_state = self::STATE_DIRTY;

return $this;
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function __construct(AST\Node $AST, $sqlWalker)
}

$this->_createTempTableSql = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
. $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
. $platform->getColumnDeclarationListSQL($columnDefinitions) . ', PRIMARY KEY(' . implode(',', $idColumnNames) . '))';
$this->_dropTempTableSql = $platform->getDropTemporaryTableSQL($tempTable);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function __construct(AST\Node $AST, $sqlWalker)
}

$this->_createTempTableSql = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
. $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
. $platform->getColumnDeclarationListSQL($columnDefinitions) . ', PRIMARY KEY(' . implode(',', $idColumnNames) . '))';

$this->_dropTempTableSql = $platform->getDropTemporaryTableSQL($tempTable);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Doctrine\ORM\Internal\CommitOrderCalculator;
use Doctrine\ORM\Internal\HydrationCompleteHandler;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\ORM\Persisters\Collection\CollectionPersister;
use Doctrine\ORM\Persisters\Collection\ManyToManyPersister;
Expand Down Expand Up @@ -71,6 +72,8 @@
* in the correct order.
*
* Internal note: This class contains highly performance-sensitive code.
*
* @psalm-import-type AssociationMapping from ClassMetadataInfo
*/
class UnitOfWork implements PropertyChangedListener
{
Expand Down
Loading

0 comments on commit b8299fe

Please sign in to comment.