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:
  Deprecate QueryBuilder APIs exposing its internal state (doctrine#9945)
  Update branch info in README and .doctrine-project.json (doctrine#9943)
  Psalm 4.25.0, PHPStan 1.8.2 (doctrine#9941)
  Stop passing event manager to constructor (doctrine#9938)
  Use a more precise phpdoc for ClassMetadataInfo::versionField than mixed (doctrine#9937)
  Make EntityManager `@final` and its constructor public
  • Loading branch information
derrabus committed Aug 2, 2022
2 parents 61cc67e + fa63a39 commit c4b06b1
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 50 deletions.
18 changes: 12 additions & 6 deletions .doctrine-project.json
Expand Up @@ -12,21 +12,27 @@
"upcoming": true
},
{
"name": "2.12",
"branchName": "2.12.x",
"slug": "2.12",
"name": "2.13",
"branchName": "2.13.x",
"slug": "2.13",
"upcoming": true
},
{
"name": "2.11",
"branchName": "2.11.x",
"slug": "2.11",
"name": "2.12",
"branchName": "2.12.x",
"slug": "2.12",
"current": true,
"aliases": [
"current",
"stable"
]
},
{
"name": "2.11",
"branchName": "2.11.x",
"slug": "2.11",
"maintained": false
},
{
"name": "2.10",
"branchName": "2.10.x",
Expand Down
14 changes: 7 additions & 7 deletions README.md
@@ -1,7 +1,7 @@
| [3.0.x][3.0] | [2.12.x][2.12] | [2.11.x][2.11] |
| [3.0.x][3.0] | [2.13.x][2.13] | [2.12.x][2.12] |
|:----------------:|:----------------:|:----------:|
| [![Build status][3.0 image]][3.0] | [![Build status][2.12 image]][2.12] | [![Build status][2.11 image]][2.11] |
| [![Coverage Status][3.0 coverage image]][3.0 coverage]| [![Coverage Status][2.12 coverage image]][2.12 coverage] | [![Coverage Status][2.11 coverage image]][2.11 coverage] |
| [![Build status][3.0 image]][3.0] | [![Build status][2.13 image]][2.13] | [![Build status][2.12 image]][2.12] |
| [![Coverage Status][3.0 coverage image]][3.0 coverage]| [![Coverage Status][2.13 coverage image]][2.13 coverage] | [![Coverage Status][2.12 coverage image]][2.12 coverage] |

[<h1 align="center">🇺🇦 UKRAINE NEEDS YOUR HELP NOW!</h1>](https://www.doctrine-project.org/stop-war.html)

Expand All @@ -22,11 +22,11 @@ without requiring unnecessary code duplication.
[3.0]: https://github.com/doctrine/orm/tree/3.0.x
[3.0 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.0.x/graph/badge.svg
[3.0 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.0.x
[2.13 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=2.13.x
[2.13]: https://github.com/doctrine/orm/tree/2.13.x
[2.13 coverage image]: https://codecov.io/gh/doctrine/orm/branch/2.13.x/graph/badge.svg
[2.13 coverage]: https://codecov.io/gh/doctrine/orm/branch/2.13.x
[2.12 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=2.12.x
[2.12]: https://github.com/doctrine/orm/tree/2.12.x
[2.12 coverage image]: https://codecov.io/gh/doctrine/orm/branch/2.12.x/graph/badge.svg
[2.12 coverage]: https://codecov.io/gh/doctrine/orm/branch/2.12.x
[2.11 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=2.11.x
[2.11]: https://github.com/doctrine/orm/tree/2.11.x
[2.11 coverage image]: https://codecov.io/gh/doctrine/orm/branch/2.11.x/graph/badge.svg
[2.11 coverage]: https://codecov.io/gh/doctrine/orm/branch/2.11.x
14 changes: 14 additions & 0 deletions UPGRADE.md
Expand Up @@ -460,6 +460,20 @@ Use `toIterable()` instead.

# Upgrade to 2.13

## Deprecated `QueryBuilder` methods and constants.

1. The `QueryBuilder::getState()` method has been deprecated as the builder state is an internal concern.
2. Relying on the type of the query being built by using `QueryBuilder::getType()` has been deprecated.
If necessary, track the type of the query being built outside of the builder.

The following `QueryBuilder` constants related to the above methods have been deprecated:

1. `SELECT`,
2. `DELETE`,
3. `UPDATE`,
4. `STATE_DIRTY`,
5. `STATE_CLEAN`.

## Deprecated omitting only the alias argument for `QueryBuilder::update` and `QueryBuilder::delete`

When building an UPDATE or DELETE query and when passing a class/type to the function, the alias argument must not be omitted.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -39,12 +39,12 @@
"doctrine/annotations": "^1.13",
"doctrine/coding-standard": "^9.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "1.8.0",
"phpstan/phpstan": "1.8.2",
"phpunit/phpunit": "^9.5",
"psr/log": "^1 || ^2 || ^3",
"squizlabs/php_codesniffer": "3.7.1",
"symfony/cache": "^4.4 || ^5.4 || ^6.0",
"vimeo/psalm": "4.24.0"
"vimeo/psalm": "4.25.0"
},
"conflict": {
"doctrine/annotations": "<1.13 || >= 2.0"
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php
Expand Up @@ -12,6 +12,7 @@
use Doctrine\ORM\Utility\IdentifierFlattener;

use function array_merge;
use function assert;
use function is_array;
use function is_object;
use function reset;
Expand Down Expand Up @@ -41,6 +42,7 @@ public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, ob
if ($metadata->requiresFetchAfterChange) {
if ($metadata->isVersioned) {
assert($metadata->versionField !== null);
$data[$metadata->versionField] = $metadata->getFieldValue($entity, $metadata->versionField);
}

Expand Down
18 changes: 10 additions & 8 deletions lib/Doctrine/ORM/EntityManager.php
Expand Up @@ -59,8 +59,10 @@
* is not a valid extension point for the EntityManager. Instead you
* should take a look at the {@see \Doctrine\ORM\Decorator\EntityManagerDecorator}
* and wrap your entity manager in a decorator.
*
* @final
*/
/* final */class EntityManager implements EntityManagerInterface
class EntityManager implements EntityManagerInterface
{
/**
* The used Configuration.
Expand Down Expand Up @@ -121,11 +123,15 @@
* Creates a new EntityManager that operates on the given database connection
* and uses the given Configuration and EventManager implementations.
*/
protected function __construct(Connection $conn, Configuration $config, EventManager $eventManager)
public function __construct(Connection $conn, Configuration $config)
{
if (! $config->getMetadataDriverImpl()) {
throw MissingMappingDriverImplementation::create();
}

$this->conn = $conn;
$this->config = $config;
$this->eventManager = $eventManager;
$this->eventManager = $conn->getEventManager();

$metadataFactoryClassName = $config->getClassMetadataFactoryName();

Expand Down Expand Up @@ -637,13 +643,9 @@ public function initializeObject(object $obj): void
*/
public static function create(array|Connection $connection, Configuration $config, ?EventManager $eventManager = null): EntityManager
{
if (! $config->getMetadataDriverImpl()) {
throw MissingMappingDriverImplementation::create();
}

$connection = static::createConnection($connection, $config, $eventManager);

return new EntityManager($connection, $config, $connection->getEventManager());
return new EntityManager($connection, $config);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Expand Up @@ -695,7 +695,7 @@ class ClassMetadataInfo implements ClassMetadata
/**
* READ-ONLY: The name of the field which is used for versioning in optimistic locking (if any).
*
* @var mixed
* @var string|null
*/
public $versionField;

Expand Down Expand Up @@ -3213,7 +3213,7 @@ public function setVersioned($bool)
* Sets the name of the field that is to be used for versioning if this class is
* versioned for optimistic locking.
*
* @param string $versionField
* @param string|null $versionField
*
* @return void
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Expand Up @@ -449,7 +449,8 @@ final protected function updateTable(
}

if ($versioned) {
$versionField = $this->class->versionField;
$versionField = $this->class->versionField;
assert($versionField !== null);
$versionFieldType = $this->class->fieldMappings[$versionField]['type'];
$versionColumn = $this->quoteStrategy->getColumnName($versionField, $this->class, $this->platform);

Expand Down
27 changes: 25 additions & 2 deletions lib/Doctrine/ORM/QueryBuilder.php
Expand Up @@ -38,13 +38,19 @@
*/
class QueryBuilder
{
/* The query types. */
/** @deprecated */
public const SELECT = 0;

/** @deprecated */
public const DELETE = 1;

/** @deprecated */
public const UPDATE = 2;

/* The builder states. */
/** @deprecated */
public const STATE_DIRTY = 0;

/** @deprecated */
public const STATE_CLEAN = 1;

/**
Expand Down Expand Up @@ -237,10 +243,19 @@ public function setCacheMode(int $cacheMode): static
/**
* Gets the type of the currently built query.
*
* @deprecated If necessary, track the type of the query being built outside of the builder.
*
* @psalm-return self::SELECT|self::DELETE|self::UPDATE
*/
public function getType(): int
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/orm/pull/9945',
'Relying on the type of the query being built is deprecated.'
. ' If necessary, track the type of the query being built outside of the builder.'
);

return $this->type;
}

Expand All @@ -255,11 +270,19 @@ public function getEntityManager(): EntityManagerInterface
/**
* Gets the state of this query builder instance.
*
* @deprecated The builder state is an internal concern.
*
* @return int Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
* @psalm-return self::STATE_*
*/
public function getState(): int
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/orm/pull/9945',
'Relying on the query builder state is deprecated as it is an internal concern.'
);

return $this->state;
}

Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/ORM/UnitOfWork.php
Expand Up @@ -55,6 +55,7 @@
use function array_pop;
use function array_sum;
use function array_values;
use function assert;
use function count;
use function current;
use function get_debug_type;
Expand Down Expand Up @@ -1455,6 +1456,8 @@ public function getEntityState(object $entity, ?int $assume = null): int
case $class->isIdentifierNatural():
// Check for a version field, if available, to avoid a db lookup.
if ($class->isVersioned) {
assert($class->versionField !== null);

return $class->getFieldValue($entity, $class->versionField)
? self::STATE_DETACHED
: self::STATE_NEW;
Expand Down Expand Up @@ -2035,6 +2038,7 @@ public function lock(object $entity, int $lockMode, $lockVersion = null): void
$entity->__load();
}

assert($class->versionField !== null);
$entityVersion = $class->reflFields[$class->versionField]->getValue($entity);

// phpcs:ignore SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedNotEqualOperator
Expand Down
20 changes: 7 additions & 13 deletions psalm-baseline.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.24.0@06dd975cb55d36af80f242561738f16c5f58264f">
<files psalm-version="v4.25.0@d7cd84c4ebca74ba3419b9601f81d177bcbe2aac">
<file src="lib/Doctrine/ORM/AbstractQuery.php">
<FalsableReturnStatement occurrences="1">
<code>! $filteredParameters-&gt;isEmpty() ? $filteredParameters-&gt;first() : null</code>
Expand Down Expand Up @@ -179,12 +179,9 @@
</ArgumentTypeCoercion>
</file>
<file src="lib/Doctrine/ORM/EntityManager.php">
<ArgumentTypeCoercion occurrences="5">
<ArgumentTypeCoercion occurrences="2">
<code>$className</code>
<code>$connection</code>
<code>ltrim($className, '\\')</code>
<code>ltrim($entityName, '\\')</code>
<code>ltrim($entityName, '\\')</code>
</ArgumentTypeCoercion>
<InvalidReturnStatement occurrences="10">
<code>$entity</code>
Expand Down Expand Up @@ -498,10 +495,9 @@
<code>$sequenceGeneratorDefinition</code>
<code>$table</code>
</PropertyNotSetInConstructor>
<PropertyTypeCoercion occurrences="13">
<PropertyTypeCoercion occurrences="12">
<code>$this-&gt;associationMappings</code>
<code>$this-&gt;associationMappings</code>
<code>$this-&gt;discriminatorMap</code>
<code>$this-&gt;entityListeners</code>
<code>$this-&gt;fieldMappings</code>
<code>$this-&gt;fullyQualifiedClassName($repositoryClassName)</code>
Expand Down Expand Up @@ -743,6 +739,10 @@
</MissingParamType>
</file>
<file src="lib/Doctrine/ORM/Mapping/MappingException.php">
<ArgumentTypeCoercion occurrences="2">
<code>$className</code>
<code>$entityName</code>
</ArgumentTypeCoercion>
<MissingParamType occurrences="4">
<code>$className</code>
<code>$className</code>
Expand Down Expand Up @@ -2244,16 +2244,10 @@
<code>$collectionToUpdate</code>
<code>$commitOrder[$i]</code>
</ArgumentTypeCoercion>
<InvalidNullableReturnType occurrences="1">
<code>object</code>
</InvalidNullableReturnType>
<InvalidPropertyAssignmentValue occurrences="2">
<code>$this-&gt;entityChangeSets</code>
<code>$this-&gt;entityChangeSets</code>
</InvalidPropertyAssignmentValue>
<NullableReturnStatement occurrences="1">
<code>$this-&gt;identityMap[$rootClassName][$idHash]</code>
</NullableReturnStatement>
<PossiblyInvalidArrayOffset occurrences="1">
<code>$this-&gt;identityMap[$rootClassName]</code>
</PossiblyInvalidArrayOffset>
Expand Down
6 changes: 6 additions & 0 deletions psalm.xml
Expand Up @@ -32,6 +32,12 @@
<referencedClass name="Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets"/>
</errorLevel>
</DeprecatedClass>
<DeprecatedConstant>
<errorLevel type="suppress">
<file name="lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php"/>
<file name="lib/Doctrine/ORM/QueryBuilder.php"/>
</errorLevel>
</DeprecatedConstant>
<DeprecatedMethod>
<errorLevel type="suppress">
<!-- We're calling the deprecated method for BC here. -->
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Performance/EntityManagerFactory.php
Expand Up @@ -71,6 +71,6 @@ public function executeQuery(string $sql, array $params = [], $types = [], ?Quer
}
};

return EntityManager::create($connection, $config);
return EntityManager::create($connection, $config, $connection->getEventManager());
}
}
4 changes: 1 addition & 3 deletions tests/Doctrine/Tests/Mocks/EntityManagerMock.php
Expand Up @@ -58,8 +58,6 @@ public static function create($conn, ?Configuration $config = null, ?EventManage
$config->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver());
}

$eventManager ??= new EventManager();

return new EntityManagerMock($conn, $config, $eventManager);
return new EntityManagerMock($conn, $config);
}
}
7 changes: 6 additions & 1 deletion tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\Tests\ORM\Functional;

use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Configuration;
Expand Down Expand Up @@ -208,7 +209,11 @@ private function configureFilters(EntityManagerInterface $em): void
*/
private function getMockConnection(): Connection
{
return $this->createMock(Connection::class);
$connection = $this->createMock(Connection::class);
$connection->method('getEventManager')
->willReturn(new EventManager());

return $connection;
}

/**
Expand Down

0 comments on commit c4b06b1

Please sign in to comment.