Skip to content

Commit

Permalink
@template for Query and update docs for EntityRepository (#107)
Browse files Browse the repository at this point in the history
* prevent false-positive ERROR: PropertyNotSetInConstructor

* Revert "prevent false-positive ERROR: PropertyNotSetInConstructor"

This reverts commit 35ef09a.

* prevent false-positive ERROR: PropertyNotSetInConstructor

* added template for Query
  • Loading branch information
dimajolkin authored Jan 16, 2022
1 parent 9cc5c54 commit b9dc248
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
composer.lock
tests/_output
studio.json
.idea
23 changes: 20 additions & 3 deletions stubs/EntityRepository.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@ use Doctrine\Persistence\ObjectRepository;
*/
class EntityRepository implements ObjectRepository, Selectable
{
/** @var string */
/**
* @var string
* @psalm-supress PropertyNotSetInConstructor
*/
protected $_entityName;

/** @var EntityManagerInterface */
/**
* @var EntityManagerInterface
* @psalm-supress PropertyNotSetInConstructor
*/
protected $_em;

/** @var Mapping\ClassMetadata */
/**
* @var Mapping\ClassMetadata
* @psalm-supress PropertyNotSetInConstructor
*/
protected $_class;

/** @param Mapping\ClassMetadata<T> $class */
Expand Down Expand Up @@ -64,4 +73,12 @@ class EntityRepository implements ObjectRepository, Selectable
public function matching(Criteria $criteria)
{
}

/**
* @return QueryBuilder<T>
*/
public function createQueryBuilder($alias, $indexBy = null): QueryBuilder
{

}
}
23 changes: 23 additions & 0 deletions stubs/Query.phpstub
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Doctrine\ORM;

/**
* @template T
*/
class Query extends AbstractQuery
{
/**
* @param int $hydrationMode
*
* @psalm-return (
* $hydrationMode is self::HYDRATE_OBJECT
* ? list<T>
* : mixed
* )
*/
public function getResult($hydrationMode = self::HYDRATE_OBJECT)
{

}
}
10 changes: 10 additions & 0 deletions stubs/QueryBuilder.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use Doctrine\ORM\Query\Expr;
/**
* @psalm-type _WhereExpr=Expr\Base|Expr\Comparison|Expr\Func|string
* @psalm-type _SelectExpr=Expr\Func|string
* @template T
*/
class QueryBuilder
{
Expand Down Expand Up @@ -89,4 +90,13 @@ class QueryBuilder
public function orHaving($predicate, ...$predicates): self
{
}


/**
* @return Query<T>
*/
public function getQuery(): Query
{

}
}

0 comments on commit b9dc248

Please sign in to comment.