Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Added template for phpstan #1859

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Propel/Generator/Builder/Om/ObjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4463,7 +4463,7 @@ protected function addInitRelations(string &$script, array $referrers): void
* @param string \$relationName The name of the relation to initialize
* @return void
*/
public function initRelation(\$relationName)
public function initRelation(string \$relationName): void
{";
foreach ($referrers as $refFK) {
if (!$refFK->isLocalPrimaryKey()) {
Expand Down
48 changes: 44 additions & 4 deletions src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,32 @@

use ArrayIterator;
use IteratorAggregate;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\InvalidArgumentException;
use Propel\Runtime\Exception\LogicException;
use Propel\Runtime\Formatter\AbstractFormatter;
use Propel\Runtime\Map\TableMap;
use Propel\Runtime\Propel;
use Traversable;

class BaseModelCriteria extends Criteria implements IteratorAggregate
/**
* @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface
* @phpstan-template TColl of \Propel\Runtime\Collection\Collection
* @phpstan-template TReturn
*/
abstract class BaseModelCriteria extends Criteria implements IteratorAggregate
{
/**
* @phpstan-var class-string<T>|null
*
* @var string|null
*/
protected $modelName;

/**
* @var string|null
* @phpstan-var class-string<\Propel\Runtime\Map\TableMap>|null
*
* @var string|null
*/
protected $modelTableMapName;

Expand All @@ -41,7 +50,7 @@ class BaseModelCriteria extends Criteria implements IteratorAggregate
protected $modelAlias;

/**
* @var \Propel\Runtime\Map\TableMap
* @var \Propel\Runtime\Map\TableMap|T[]
dereuromark marked this conversation as resolved.
Show resolved Hide resolved
*/
protected $tableMap;

Expand All @@ -66,6 +75,8 @@ class BaseModelCriteria extends Criteria implements IteratorAggregate
* Creates a new instance with the default capacity which corresponds to
* the specified database.
*
* @phpstan-param class-string<T> $modelName
*
* @param string|null $dbName The database name
* @param string|null $modelName The phpName of a model, e.g. 'Book'
* @param string|null $modelAlias The alias for the model in this query, e.g. 'b'
Expand Down Expand Up @@ -113,6 +124,13 @@ public function setWith(array $with)
* $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
* </code>
*
* @phpstan-template AColl of \Propel\Runtime\Collection\Collection
* @phpstan-template AReturn
*
* @phpstan-param \Propel\Runtime\Formatter\AbstractFormatter<T, AColl, AReturn>|class-string<\Propel\Runtime\Formatter\AbstractFormatter> $formatter
*
* @phpstan-return $this<T, AColl, AReturn>
*
* @param \Propel\Runtime\Formatter\AbstractFormatter|string $formatter a formatter class name, or a formatter instance
*
* @throws \Propel\Runtime\Exception\InvalidArgumentException
Expand Down Expand Up @@ -153,6 +171,8 @@ public function getFormatter(): AbstractFormatter
/**
* Returns the name of the class for this model criteria
*
* @phpstan-return class-string<T>
*
* @return string|null
*/
public function getModelName(): ?string
Expand Down Expand Up @@ -182,6 +202,8 @@ public function getModelNameOrFail(): string
* Sets the model name.
* This also sets `this->modelTableMapName` and `this->tableMap`.
*
* @phpstan-param class-string<T>|null $modelName
*
* @param string|null $modelName
*
* @return $this The current object, for fluid interface
Expand All @@ -194,6 +216,7 @@ public function setModelName(?string $modelName)
return $this;
}
if (strpos($modelName, '\\') === 0) {
/** @phpstan-var class-string<T> $modelName */
$modelName = substr($modelName, 1);
}

Expand All @@ -209,6 +232,8 @@ public function setModelName(?string $modelName)
}

/**
* @phpstan-return class-string<T>
*
* @return string
*/
public function getFullyQualifiedModelName(): string
Expand Down Expand Up @@ -283,6 +308,8 @@ public static function getShortName(string $fullyQualifiedClassName): string
/**
* Returns the TableMap object for this Criteria
*
* @phpstan-return \Propel\Runtime\Map\TableMap<T>
*
* @return \Propel\Runtime\Map\TableMap|null
*/
public function getTableMap(): ?TableMap
Expand Down Expand Up @@ -333,7 +360,7 @@ public function getTableNameInQuery(): ?string
*
* @throws \Propel\Runtime\Exception\LogicException
*
* @return \Traversable
* @return \Traversable<T>
*/
public function getIterator(): Traversable
{
Expand All @@ -350,4 +377,17 @@ public function getIterator(): Traversable

throw new LogicException('The current formatter doesn\'t return an iterable result');
}

/**
* Issue a SELECT query based on the current ModelCriteria
* and format the list of results with the current formatter
* By default, returns an array of model objects
*
* @phpstan-return T|mixed
*
* @param \Propel\Runtime\Connection\ConnectionInterface|null $con an optional connection object
*
* @return \Propel\Runtime\Collection\ObjectCollection|\Propel\Runtime\ActiveRecord\ActiveRecordInterface[]|mixed the list of results, formatted by the current formatter
*/
abstract public function find(?ConnectionInterface $con = null);
}
21 changes: 21 additions & 0 deletions src/Propel/Runtime/ActiveQuery/ModelCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
* @method \Propel\Runtime\ActiveQuery\ModelCriteria rightJoin($relation) Adds a RIGHT JOIN clause to the query
* @method \Propel\Runtime\ActiveQuery\ModelCriteria innerJoin($relation) Adds a INNER JOIN clause to the query
*
* @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface
* @phpstan-template TColl of \Propel\Runtime\Collection\Collection
* @phpstan-template TReturn
* @phpstan-extends \Propel\Runtime\ActiveQuery\BaseModelCriteria<T, TColl, TReturn>
*
* @author François Zaninotto
*/
class ModelCriteria extends BaseModelCriteria
Expand All @@ -78,6 +83,8 @@ class ModelCriteria extends BaseModelCriteria
public const FORMAT_ON_DEMAND = '\Propel\Runtime\Formatter\OnDemandFormatter';

/**
* @phpstan-var self<T, TColl, TReturn>|null
*
* @var \Propel\Runtime\ActiveQuery\ModelCriteria|null
*/
protected $primaryCriteria;
Expand Down Expand Up @@ -493,6 +500,8 @@ public function offset($offset)
* ArticleQuery::create()->select(array('Id', 'Name'))->findOne();
* => array('Id' => 1, 'Name' => 'Foo')
*
* @phpstan-return $this<T, \Propel\Runtime\Collection\ArrayCollection<T>, mixed[]>
*
* @param mixed $columnArray A list of column names (e.g. array('Title', 'Category.Name', 'c.Content')) or a single column name (e.g. 'Name')
*
* @throws \Propel\Runtime\Exception\PropelException
Expand Down Expand Up @@ -861,6 +870,12 @@ public function withColumn(string $clause, ?string $name = null)
*
* @psalm-param class-string<self>|null $secondaryCriteriaClass
*
* @phpstan-template TRel of \Propel\Runtime\ActiveRecord\ActiveRecordInterface
*
* @phpstan-param class-string<TRel> $secondaryCriteriaClass
*
* @phpstan-return \Propel\Runtime\ActiveQuery\ModelCriteria<TRel, TColl, TReturn>
*
* @see ModelCriteria::endUse()
*
* @param string $relationName Relation name or alias
Expand Down Expand Up @@ -1014,6 +1029,8 @@ public function mergeWith(Criteria $criteria, ?string $operator = null)
* Clear the conditions to allow the reuse of the query object.
* The ModelCriteria's Model and alias 'all the properties set by construct) will remain.
*
* @phpstan-return $this<T, \Propel\Runtime\Collection\ObjectCollection<T>, T>
*
* @return $this
*/
public function clear()
Expand All @@ -1032,6 +1049,8 @@ public function clear()
/**
* Sets the primary Criteria for this secondary Criteria
*
* @phpstan-param \Propel\Runtime\ActiveQuery\ModelCriteria<T, TColl, TReturn> $criteria
*
* @param \Propel\Runtime\ActiveQuery\ModelCriteria $criteria The primary criteria
* @param \Propel\Runtime\ActiveQuery\Join $previousJoin The previousJoin for this ModelCriteria
*
Expand Down Expand Up @@ -1280,6 +1299,8 @@ protected function preSelect(ConnectionInterface $con): void
* and format the list of results with the current formatter
* By default, returns an array of model objects
*
* @phpstan-return T|mixed
*
* @param \Propel\Runtime\Connection\ConnectionInterface|null $con an optional connection object
*
* @return \Propel\Runtime\Collection\ObjectCollection|\Propel\Runtime\ActiveRecord\ActiveRecordInterface[]|mixed the list of results, formatted by the current formatter
Expand Down
6 changes: 5 additions & 1 deletion src/Propel/Runtime/ActiveRecord/ActiveRecordInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
*
* @author jaugustin
*
* @method array toArray(string $keyType = \Propel\Runtime\Map\TableMap::TYPE_FIELDNAME, bool $includeLazyLoadColumns = true, array $alreadyDumpedObjects = [], bool $includeForeignObjects = false): array
* @method array toArray(string $keyType = \Propel\Runtime\Map\TableMap::TYPE_FIELDNAME, bool $includeLazyLoadColumns = true, array $alreadyDumpedObjects = [], bool $includeForeignObjects = false)
* @method void initRelation(string $relationName)
* @method self setVirtualColumn(string $name, $value)
* @method int hydrate(array $row, int $startcol = 0, bool $rehydrate = false, string $indexType = \Propel\Runtime\Map\TableMap::TYPE_NUM)
* @method mixed getPrimaryKey()
*/
interface ActiveRecordInterface
{
Expand Down
5 changes: 5 additions & 0 deletions src/Propel/Runtime/Collection/ArrayCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
* Class for iterating over a list of Propel objects stored as arrays
*
* @author Francois Zaninotto
*
* @phpstan-template TType of \Propel\Runtime\ActiveRecord\ActiveRecordInterface
* @phpstan-extends \Propel\Runtime\Collection\Collection<TType, array>
*/
class ArrayCollection extends Collection
{
/**
* @phpstan-var TType
*
* @var \Propel\Runtime\ActiveRecord\ActiveRecordInterface
*/
protected $workerObject;
Expand Down
Loading