Skip to content

Commit

Permalink
Merge branch '2.14.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.14.x:
  Add a constructor to CacheKey (doctrine#10212)
  Psalm 4.30.0, PHPStan 1.9.2 (doctrine#10213)
  Allow "Expr\Func" as condition in join (doctrine#10202)
  refactor: use list type in SchemaTool (doctrine#10199)
  • Loading branch information
derrabus committed Nov 11, 2022
2 parents a8445c9 + 953e42d commit 46b8e20
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 28 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Expand Up @@ -515,6 +515,11 @@ Use `toIterable()` instead.

# Upgrade to 2.14

## Deprecated constructing a `CacheKey` without `$hash`

The `Doctrine\ORM\Cache\CacheKey` class has an explicit constructor now with
an optional parameter `$hash`. That parameter will become mandatory in 3.0.

## Deprecated `AttributeDriver::$entityAnnotationClasses`

If you need to change the behavior of `AttributeDriver::isTransient()`,
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -38,12 +38,12 @@
"require-dev": {
"doctrine/coding-standard": "^10.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "1.9.0",
"phpstan/phpstan": "1.9.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.29.0"
"vimeo/psalm": "4.30.0"
},
"suggest": {
"ext-dom": "Provides support for XSD validation for XML mapping files",
Expand Down
5 changes: 3 additions & 2 deletions lib/Doctrine/ORM/Query/Expr/Base.php
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\ORM\Query\Expr;

use InvalidArgumentException;
use Stringable;

use function count;
use function get_class;
Expand All @@ -30,10 +31,10 @@ abstract class Base
/** @var string */
protected $postSeparator = ')';

/** @psalm-var list<class-string> */
/** @var list<class-string> */
protected $allowedClasses = [];

/** @psalm-var list<string|object> */
/** @var list<string|Stringable> */
protected $parts = [];

/** @param mixed $args */
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Query/Expr/Join.php
Expand Up @@ -28,7 +28,7 @@ public function __construct(
protected string $join,
protected string|null $alias = null,
protected string|null $conditionType = null,
protected string|Comparison|Composite|null $condition = null,
protected string|Comparison|Composite|Func|null $condition = null,
protected string|null $indexBy = null,
) {
}
Expand All @@ -55,7 +55,7 @@ public function getConditionType(): string|null
return $this->conditionType;
}

public function getCondition(): string|Comparison|Composite|null
public function getCondition(): string|Comparison|Composite|Func|null
{
return $this->condition;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/QueryBuilder.php
Expand Up @@ -818,7 +818,7 @@ public function join(
string $join,
string $alias,
string|null $conditionType = null,
string|Expr\Composite|Expr\Comparison|null $condition = null,
string|Expr\Composite|Expr\Comparison|Expr\Func|null $condition = null,
string|null $indexBy = null,
): static {
return $this->innerJoin($join, $alias, $conditionType, $condition, $indexBy);
Expand All @@ -845,7 +845,7 @@ public function innerJoin(
string $join,
string $alias,
string|null $conditionType = null,
string|Expr\Composite|Expr\Comparison|null $condition = null,
string|Expr\Composite|Expr\Comparison|Expr\Func|null $condition = null,
string|null $indexBy = null,
): static {
$parentAlias = substr($join, 0, (int) strpos($join, '.'));
Expand Down Expand Up @@ -886,7 +886,7 @@ public function leftJoin(
string $join,
string $alias,
string|null $conditionType = null,
string|Expr\Composite|Expr\Comparison|null $condition = null,
string|Expr\Composite|Expr\Comparison|Expr\Func|null $condition = null,
string|null $indexBy = null,
): static {
$parentAlias = substr($join, 0, (int) strpos($join, '.'));
Expand Down
16 changes: 8 additions & 8 deletions lib/Doctrine/ORM/Tools/SchemaTool.php
Expand Up @@ -92,7 +92,7 @@ public function createSchema(array $classes): void
*
* @psalm-param list<ClassMetadata> $classes
*
* @return string[] The SQL statements needed to create the schema for the classes.
* @return list<string> The SQL statements needed to create the schema for the classes.
*/
public function getCreateSchemaSql(array $classes): array
{
Expand Down Expand Up @@ -122,7 +122,7 @@ private function processingNotRequired(
*
* @param mixed[] $indexData index or unique constraint data
*
* @return string[] Column names from combined fields and columns mappings
* @return list<string> Column names from combined fields and columns mappings
*/
private function getIndexColumns(ClassMetadata $class, array $indexData): array
{
Expand Down Expand Up @@ -832,7 +832,7 @@ public function dropDatabase(): void
/**
* Gets the SQL needed to drop the database schema for the connections database.
*
* @return string[]
* @return list<string>
*/
public function getDropDatabaseSQL(): array
{
Expand All @@ -846,7 +846,7 @@ public function getDropDatabaseSQL(): array
*
* @psalm-param list<ClassMetadata> $classes
*
* @return string[]
* @return list<string>
*/
public function getDropSchemaSQL(array $classes): array
{
Expand Down Expand Up @@ -917,11 +917,11 @@ public function updateSchema(array $classes, bool $saveMode = false): void
* Gets the sequence of SQL statements that need to be performed in order
* to bring the given class mappings in-synch with the relational schema.
*
* @param mixed[] $classes The classes to consider.
* @param bool $saveMode If TRUE, only generates SQL for a partial update
* that does not include SQL for dropping assets which are scheduled for deletion.
* @param bool $saveMode If TRUE, only generates SQL for a partial update
* that does not include SQL for dropping assets which are scheduled for deletion.
* @param list<ClassMetadata> $classes The classes to consider.
*
* @return string[] The sequence of SQL statements.
* @return list<string> The sequence of SQL statements.
*/
public function getUpdateSchemaSql(array $classes, bool $saveMode = false): array
{
Expand Down
13 changes: 2 additions & 11 deletions psalm-baseline.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.29.0@7ec5ffbd5f68ae03782d7fd33fff0c45a69f95b3">
<files psalm-version="4.30.0@d0bc6e25d89f649e4f36a534f330f8bb4643dd69">
<file src="lib/Doctrine/ORM/AbstractQuery.php">
<FalsableReturnStatement occurrences="1">
<code>! $filteredParameters-&gt;isEmpty() ? $filteredParameters-&gt;first() : null</code>
Expand Down Expand Up @@ -1323,18 +1323,9 @@
<code>$parts</code>
</NonInvariantDocblockPropertyType>
</file>
<file src="lib/Doctrine/ORM/Query/Expr/Base.php">
<ArgumentTypeCoercion occurrences="1">
<code>$this-&gt;parts</code>
</ArgumentTypeCoercion>
<PossiblyInvalidCast occurrences="1">
<code>$this-&gt;parts[0]</code>
</PossiblyInvalidCast>
</file>
<file src="lib/Doctrine/ORM/Query/Expr/Composite.php">
<PossiblyInvalidCast occurrences="2">
<PossiblyInvalidCast occurrences="1">
<code>$part</code>
<code>$this-&gt;parts[0]</code>
</PossiblyInvalidCast>
</file>
<file src="lib/Doctrine/ORM/Query/Expr/GroupBy.php">
Expand Down
6 changes: 6 additions & 0 deletions psalm.xml
Expand Up @@ -78,6 +78,12 @@
<file name="lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php"/>
</errorLevel>
</MissingParamType>
<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<!-- Remove on 3.0.x -->
<referencedProperty name="Doctrine\ORM\Cache\CacheKey::$hash"/>
</errorLevel>
</PropertyNotSetInConstructor>
<RedundantCastGivenDocblockType>
<errorLevel type="suppress">
<!-- Can be removed once the "getMaxResults" methods of those classes have native parameter types -->
Expand Down
9 changes: 9 additions & 0 deletions tests/Doctrine/Tests/ORM/Cache/CacheKeyTest.php
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\Tests\ORM\Cache;

use Doctrine\ORM\Cache\CacheKey;
use Doctrine\ORM\Cache\CollectionCacheKey;
use Doctrine\ORM\Cache\EntityCacheKey;
use Doctrine\Tests\DoctrineTestCase;
Expand Down Expand Up @@ -66,4 +67,12 @@ public function testCollectionCacheKeyAssociationCollision(): void

self::assertNotEquals($key1->hash, $key2->hash);
}

public function testConstructor(): void
{
$key = new class ('my-hash') extends CacheKey {
};

self::assertSame('my-hash', $key->hash);
}
}
17 changes: 17 additions & 0 deletions tests/Doctrine/Tests/ORM/QueryBuilderTest.php
Expand Up @@ -169,6 +169,23 @@ public function testComplexInnerJoinWithCompositeCondition(): void
);
}

public function testComplexInnerJoinWithFuncCondition(): void
{
$qb = $this->entityManager->createQueryBuilder();
$qb
->select('u', 'a')
->from(CmsUser::class, 'u')
->innerJoin('u.articles', 'a', Join::WITH, $qb->expr()->in(
'u.id',
[1, 2, 3],
));

$this->assertValidQueryBuilder(
$qb,
'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a WITH u.id IN(1, 2, 3)',
);
}

public function testComplexInnerJoinWithIndexBy(): void
{
$qb = $this->entityManager->createQueryBuilder()
Expand Down

0 comments on commit 46b8e20

Please sign in to comment.