Skip to content

Commit

Permalink
Merge branch '2.12.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.12.x:
  Fix types on QueryBuilder (doctrine#9492)
  Fix types on EntityRepository (doctrine#9474)
  Avoid calling merge() (doctrine#9489)
  PHPStan 1.4.6, Psalm 4.20.0 (doctrine#9491)
  Fix `#[DiscriminatorMap]` params (doctrine#9487)
  Run tests with stricter error handling (doctrine#9482)
  • Loading branch information
derrabus committed Feb 9, 2022
2 parents d13d0f5 + 6017280 commit 3a43f92
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 172 deletions.
4 changes: 3 additions & 1 deletion ci/github/phpunit/mysqli.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="../../../vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
convertDeprecationsToExceptions="true"
>
<php>
<ini name="error_reporting" value="-1" />
<var name="db_driver" value="mysqli"/>
<var name="db_host" value="127.0.0.1" />
<var name="db_port" value="3306"/>
Expand Down
4 changes: 3 additions & 1 deletion ci/github/phpunit/pdo_mysql.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="../../../vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
convertDeprecationsToExceptions="true"
>
<php>
<ini name="error_reporting" value="-1" />
<var name="db_driver" value="pdo_mysql"/>
<var name="db_host" value="127.0.0.1" />
<var name="db_port" value="3306"/>
Expand Down
4 changes: 3 additions & 1 deletion ci/github/phpunit/pdo_pgsql.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="../../../vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
convertDeprecationsToExceptions="true"
>
<php>
<ini name="error_reporting" value="-1" />
<var name="db_driver" value="pdo_pgsql"/>
<var name="db_host" value="localhost" />
<var name="db_user" value="postgres" />
Expand Down
4 changes: 3 additions & 1 deletion ci/github/phpunit/sqlite.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="../../../vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
convertDeprecationsToExceptions="true"
>
<php>
<ini name="error_reporting" value="-1" />
<!-- use an in-memory sqlite database -->
<var name="db_driver" value="pdo_sqlite"/>
<var name="db_memory" value="true"/>
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
"doctrine/annotations": "^1.13",
"doctrine/coding-standard": "^9.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "1.4.3",
"phpstan/phpstan": "1.4.6",
"phpunit/phpunit": "^9.5",
"psr/log": "^1 || ^2 || ^3",
"squizlabs/php_codesniffer": "3.6.2",
"symfony/cache": "^4.4 || ^5.4 || ^6.0",
"vimeo/psalm": "4.19.0"
"vimeo/psalm": "4.20.0"
},
"conflict": {
"doctrine/annotations": "<1.13 || >= 2.0"
Expand Down
4 changes: 2 additions & 2 deletions docs/en/reference/attributes-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ Examples:
#[Entity]
#[InheritanceType("SINGLE_TABLE")]
#[DiscriminatorColumn(name: "discr", type: "string")]
#[DiscriminatorMap({"person" = "Person", "employee" = "Employee"})]
#[DiscriminatorMap(["person" => "Person", "employee" => "Employee"])]
class Person
{
// ...
Expand All @@ -637,7 +637,7 @@ Examples:
#[Entity]
#[InheritanceType("JOINED")]
#[DiscriminatorColumn(name: "discr", type: "string")]
#[DiscriminatorMap({"person" = "Person", "employee" = "Employee"})]
#[DiscriminatorMap(["person" => "Person", "employee" => "Employee"])]
class Person
{
// ...
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ public function lock(object $entity, int $lockMode, $lockVersion = null): void
* @return ObjectRepository|EntityRepository The repository class.
* @psalm-return EntityRepository<T>
*
* @template T
* @template T of object
*/
public function getRepository($entityName): EntityRepository
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/EntityManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface EntityManagerInterface extends ObjectManager
*
* @psalm-return EntityRepository<T>
*
* @template T
* @template T of object
*/
public function getRepository($className): EntityRepository;

Expand Down
39 changes: 24 additions & 15 deletions lib/Doctrine/ORM/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Doctrine\ORM;

use BadMethodCallException;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\AbstractLazyCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Selectable;
use Doctrine\DBAL\LockMode;
Expand All @@ -29,28 +29,37 @@
* This class is designed for inheritance and users can subclass this class to
* write their own repositories with business-specific methods to locate entities.
*
* @template T
* @template T of object
* @template-implements Selectable<int,T>
* @template-implements ObjectRepository<T>
*/
class EntityRepository implements ObjectRepository, Selectable
{
/** @var string */
/**
* @internal This property will be private in 3.0, call {@see getEntityName()} instead.
*
* @var string
*/
protected $_entityName;

/** @var EntityManagerInterface */
/**
* @internal This property will be private in 3.0, call {@see getEntityManager()} instead.
*
* @var EntityManagerInterface
*/
protected $_em;

/** @var ClassMetadata */
/**
* @internal This property will be private in 3.0, call {@see getClassMetadata()} instead.
*
* @var ClassMetadata
*/
protected $_class;

/** @var Inflector */
/** @var Inflector|null */
private static $inflector;

/**
* Initializes a new <tt>EntityRepository</tt>.
*/
public function __construct(EntityManagerInterface $em, Mapping\ClassMetadata $class)
public function __construct(EntityManagerInterface $em, ClassMetadata $class)
{
$this->_entityName = $class->name;
$this->_em = $em;
Expand All @@ -60,8 +69,8 @@ public function __construct(EntityManagerInterface $em, Mapping\ClassMetadata $c
/**
* Creates a new QueryBuilder instance that is prepopulated for this entity name.
*
* @param string $alias
* @param string $indexBy The index for the from.
* @param string $alias
* @param string|null $indexBy The index for the from.
*
* @return QueryBuilder
*/
Expand Down Expand Up @@ -222,7 +231,7 @@ protected function getEntityManager()
}

/**
* @return Mapping\ClassMetadata
* @return ClassMetadata
*/
protected function getClassMetadata()
{
Expand All @@ -233,8 +242,8 @@ protected function getClassMetadata()
* Select all elements from a selectable that match the expression and
* return a new collection containing these elements.
*
* @return LazyCriteriaCollection
* @psalm-return Collection<int, T>
* @return AbstractLazyCollection
* @psalm-return AbstractLazyCollection<int, T>&Selectable<int, T>
*/
public function matching(Criteria $criteria)
{
Expand Down
9 changes: 9 additions & 0 deletions lib/Doctrine/ORM/LazyCriteriaCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@
use Doctrine\ORM\Persisters\Entity\EntityPersister;
use ReturnTypeWillChange;

use function assert;

/**
* A lazy collection that allows a fast count when using criteria object
* Once count gets executed once without collection being initialized, result
* is cached and returned on subsequent calls until collection gets loaded,
* then returning the number of loaded results.
*
* @template TKey of array-key
* @template TValue of object
* @extends AbstractLazyCollection<TKey, TValue>
* @implements Selectable<TKey, TValue>
*/
class LazyCriteriaCollection extends AbstractLazyCollection implements Selectable
{
Expand Down Expand Up @@ -72,6 +79,7 @@ public function isEmpty()
* Do an optimized search of an element
*
* @param object $element
* @psalm-param TValue $element
*
* @return bool
*/
Expand All @@ -90,6 +98,7 @@ public function contains($element)
public function matching(Criteria $criteria)
{
$this->initialize();
assert($this->collection instanceof Selectable);

return $this->collection->matching($criteria);
}
Expand Down
14 changes: 12 additions & 2 deletions lib/Doctrine/ORM/Query/Expr/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class Join
public const ON = 'ON';
public const WITH = 'WITH';

/** @var string */
/**
* @var string
* @psalm-var self::INNER_JOIN|self::LEFT_JOIN
*/
protected $joinType;

/** @var string */
Expand All @@ -28,7 +31,10 @@ class Join
/** @var string|null */
protected $alias;

/** @var string|null */
/**
* @var string|null
* @psalm-var self::ON|self::WITH|null
*/
protected $conditionType;

/** @var string|Comparison|Composite|null */
Expand All @@ -44,6 +50,8 @@ class Join
* @param string|null $conditionType The condition type constant. Either ON or WITH.
* @param string|Comparison|Composite|null $condition The condition for the join.
* @param string|null $indexBy The index for the join.
* @psalm-param self::INNER_JOIN|self::LEFT_JOIN $joinType
* @psalm-param self::ON|self::WITH|null $conditionType
*/
public function __construct($joinType, $join, $alias = null, $conditionType = null, $condition = null, $indexBy = null)
{
Expand All @@ -57,6 +65,7 @@ public function __construct($joinType, $join, $alias = null, $conditionType = nu

/**
* @return string
* @psalm-return self::INNER_JOIN|self::LEFT_JOIN
*/
public function getJoinType()
{
Expand All @@ -81,6 +90,7 @@ public function getAlias()

/**
* @return string|null
* @psalm-return self::ON|self::WITH|null
*/
public function getConditionType()
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Query/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public static function normalizeName($name)
private $typeSpecified;

/**
* @param string $name Parameter name
* @param mixed $value Parameter value
* @param mixed $type Parameter type
* @param string|int $name Parameter name
* @param mixed $value Parameter value
* @param mixed $type Parameter type
*/
public function __construct($name, $value, $type = null)
{
Expand Down
27 changes: 16 additions & 11 deletions lib/Doctrine/ORM/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ public function setCacheable($cacheable)
}

/**
* @return bool TRUE if the query results are enable for second level cache, FALSE otherwise.
* Are the query results enabled for second level cache?
*
* @return bool
*/
public function isCacheable()
{
Expand Down Expand Up @@ -606,7 +608,7 @@ public function getParameters()
/**
* Gets a (previously set) query parameter of the query being constructed.
*
* @param mixed $key The key (index or name) of the bound parameter.
* @param string|int $key The key (index or name) of the bound parameter.
*
* @return Parameter|null The value of the bound parameter.
*/
Expand Down Expand Up @@ -828,8 +830,8 @@ public function addSelect(...$select)
* ->setParameter('user_id', 1);
* </code>
*
* @param string $delete The class/type whose instances are subject to the deletion.
* @param string $alias The class/type alias used in the constructed query.
* @param string|null $delete The class/type whose instances are subject to the deletion.
* @param string|null $alias The class/type alias used in the constructed query.
*
* @return $this
*/
Expand All @@ -855,8 +857,8 @@ public function delete($delete = null, $alias = null)
* ->where('u.id = ?2');
* </code>
*
* @param string $update The class/type whose instances are subject to the update.
* @param string $alias The class/type alias used in the constructed query.
* @param string|null $update The class/type whose instances are subject to the update.
* @param string|null $alias The class/type alias used in the constructed query.
*
* @return $this
*/
Expand All @@ -881,9 +883,9 @@ public function update($update = null, $alias = null)
* ->from('User', 'u');
* </code>
*
* @param string $from The class name.
* @param string $alias The alias of the class.
* @param string $indexBy The index for the from.
* @param string $from The class name.
* @param string $alias The alias of the class.
* @param string|null $indexBy The index for the from.
*
* @return $this
*/
Expand Down Expand Up @@ -956,6 +958,7 @@ public function indexBy($alias, $indexBy)
* @param string|null $conditionType The condition type constant. Either ON or WITH.
* @param string|Expr\Comparison|Expr\Composite|null $condition The condition for the join.
* @param string|null $indexBy The index for the join.
* @psalm-param Expr\Join::ON|Expr\Join::WITH|null $conditionType
*
* @return $this
*/
Expand All @@ -982,6 +985,7 @@ public function join($join, $alias, $conditionType = null, $condition = null, $i
* @param string|null $conditionType The condition type constant. Either ON or WITH.
* @param string|Expr\Comparison|Expr\Composite|null $condition The condition for the join.
* @param string|null $indexBy The index for the join.
* @psalm-param Expr\Join::ON|Expr\Join::WITH|null $conditionType
*
* @return $this
*/
Expand Down Expand Up @@ -1022,6 +1026,7 @@ public function innerJoin($join, $alias, $conditionType = null, $condition = nul
* @param string|null $conditionType The condition type constant. Either ON or WITH.
* @param string|Expr\Comparison|Expr\Composite|null $condition The condition for the join.
* @param string|null $indexBy The index for the join.
* @psalm-param Expr\Join::ON|Expr\Join::WITH|null $conditionType
*
* @return $this
*/
Expand Down Expand Up @@ -1268,7 +1273,7 @@ public function orHaving(...$having)
* Replaces any previously specified orderings, if any.
*
* @param string|Expr\OrderBy $sort The ordering expression.
* @param string $order The ordering direction.
* @param string|null $order The ordering direction.
*
* @return $this
*/
Expand All @@ -1283,7 +1288,7 @@ public function orderBy($sort, $order = null)
* Adds an ordering to the query results.
*
* @param string|Expr\OrderBy $sort The ordering expression.
* @param string $order The ordering direction.
* @param string|null $order The ordering direction.
*
* @return $this
*/
Expand Down
Loading

0 comments on commit 3a43f92

Please sign in to comment.