From 8137e3ae207ac08b6fad81b5e7c5991ff6aa9e88 Mon Sep 17 00:00:00 2001 From: Dmytro Dymarchuk Date: Thu, 7 Apr 2022 00:31:25 +0300 Subject: [PATCH 1/2] Add template for phpstan --- .../Generator/Builder/Om/ObjectBuilder.php | 2 +- .../Runtime/ActiveQuery/BaseModelCriteria.php | 48 ++++++++++- .../Runtime/ActiveQuery/ModelCriteria.php | 21 +++++ .../ActiveRecord/ActiveRecordInterface.php | 6 +- .../Runtime/Collection/ArrayCollection.php | 5 ++ src/Propel/Runtime/Collection/Collection.php | 86 ++++++++++++++++--- .../Runtime/Collection/CollectionIterator.php | 21 +++++ .../Runtime/Collection/ObjectCollection.php | 12 ++- .../Runtime/Collection/OnDemandCollection.php | 10 +++ .../Runtime/Collection/OnDemandIterator.php | 11 ++- .../Runtime/Formatter/AbstractFormatter.php | 35 ++++++++ .../AbstractFormatterWithHydration.php | 6 ++ .../Runtime/Formatter/ArrayFormatter.php | 10 ++- .../Runtime/Formatter/ObjectFormatter.php | 15 +++- .../Runtime/Formatter/OnDemandFormatter.php | 18 +++- .../Formatter/SimpleArrayFormatter.php | 5 ++ .../Runtime/Formatter/StatementFormatter.php | 5 ++ src/Propel/Runtime/Map/TableMap.php | 10 +++ src/Propel/Runtime/Util/PropelModelPager.php | 4 +- .../Collection/ArrayCollectionTest.php | 2 + 20 files changed, 303 insertions(+), 29 deletions(-) diff --git a/src/Propel/Generator/Builder/Om/ObjectBuilder.php b/src/Propel/Generator/Builder/Om/ObjectBuilder.php index 47d016ef53..397ab07e4d 100644 --- a/src/Propel/Generator/Builder/Om/ObjectBuilder.php +++ b/src/Propel/Generator/Builder/Om/ObjectBuilder.php @@ -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()) { diff --git a/src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php b/src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php index 829fb42fc7..1a14148903 100644 --- a/src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php +++ b/src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php @@ -10,6 +10,7 @@ use ArrayIterator; use IteratorAggregate; +use Propel\Runtime\Connection\ConnectionInterface; use Propel\Runtime\Exception\InvalidArgumentException; use Propel\Runtime\Exception\LogicException; use Propel\Runtime\Formatter\AbstractFormatter; @@ -17,16 +18,24 @@ 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|null + * * @var string|null */ protected $modelName; /** - * @var string|null * @phpstan-var class-string<\Propel\Runtime\Map\TableMap>|null + * + * @var string|null */ protected $modelTableMapName; @@ -41,7 +50,7 @@ class BaseModelCriteria extends Criteria implements IteratorAggregate protected $modelAlias; /** - * @var \Propel\Runtime\Map\TableMap + * @var \Propel\Runtime\Map\TableMap|T[] */ protected $tableMap; @@ -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 $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' @@ -113,6 +124,13 @@ public function setWith(array $with) * $c->setFormatter(ModelCriteria::FORMAT_ARRAY); * * + * @phpstan-template AColl of \Propel\Runtime\Collection\Collection + * @phpstan-template AReturn + * + * @phpstan-param \Propel\Runtime\Formatter\AbstractFormatter|class-string<\Propel\Runtime\Formatter\AbstractFormatter> $formatter + * + * @phpstan-return $this + * * @param \Propel\Runtime\Formatter\AbstractFormatter|string $formatter a formatter class name, or a formatter instance * * @throws \Propel\Runtime\Exception\InvalidArgumentException @@ -153,6 +171,8 @@ public function getFormatter(): AbstractFormatter /** * Returns the name of the class for this model criteria * + * @phpstan-return class-string + * * @return string|null */ public function getModelName(): ?string @@ -182,6 +202,8 @@ public function getModelNameOrFail(): string * Sets the model name. * This also sets `this->modelTableMapName` and `this->tableMap`. * + * @phpstan-param class-string|null $modelName + * * @param string|null $modelName * * @return $this The current object, for fluid interface @@ -194,6 +216,7 @@ public function setModelName(?string $modelName) return $this; } if (strpos($modelName, '\\') === 0) { + /** @phpstan-var class-string $modelName */ $modelName = substr($modelName, 1); } @@ -209,6 +232,8 @@ public function setModelName(?string $modelName) } /** + * @phpstan-return class-string + * * @return string */ public function getFullyQualifiedModelName(): string @@ -283,6 +308,8 @@ public static function getShortName(string $fullyQualifiedClassName): string /** * Returns the TableMap object for this Criteria * + * @phpstan-return \Propel\Runtime\Map\TableMap + * * @return \Propel\Runtime\Map\TableMap|null */ public function getTableMap(): ?TableMap @@ -333,7 +360,7 @@ public function getTableNameInQuery(): ?string * * @throws \Propel\Runtime\Exception\LogicException * - * @return \Traversable + * @return \Traversable */ public function getIterator(): Traversable { @@ -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); } diff --git a/src/Propel/Runtime/ActiveQuery/ModelCriteria.php b/src/Propel/Runtime/ActiveQuery/ModelCriteria.php index e7f619a90d..d953446e84 100644 --- a/src/Propel/Runtime/ActiveQuery/ModelCriteria.php +++ b/src/Propel/Runtime/ActiveQuery/ModelCriteria.php @@ -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 + * * @author François Zaninotto */ class ModelCriteria extends BaseModelCriteria @@ -78,6 +83,8 @@ class ModelCriteria extends BaseModelCriteria public const FORMAT_ON_DEMAND = '\Propel\Runtime\Formatter\OnDemandFormatter'; /** + * @phpstan-var self|null + * * @var \Propel\Runtime\ActiveQuery\ModelCriteria|null */ protected $primaryCriteria; @@ -493,6 +500,8 @@ public function offset($offset) * ArticleQuery::create()->select(array('Id', 'Name'))->findOne(); * => array('Id' => 1, 'Name' => 'Foo') * + * @phpstan-return $this, 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 @@ -861,6 +870,12 @@ public function withColumn(string $clause, ?string $name = null) * * @psalm-param class-string|null $secondaryCriteriaClass * + * @phpstan-template TRel of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * + * @phpstan-param class-string $secondaryCriteriaClass + * + * @phpstan-return \Propel\Runtime\ActiveQuery\ModelCriteria + * * @see ModelCriteria::endUse() * * @param string $relationName Relation name or alias @@ -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> + * * @return $this */ public function clear() @@ -1032,6 +1049,8 @@ public function clear() /** * Sets the primary Criteria for this secondary Criteria * + * @phpstan-param \Propel\Runtime\ActiveQuery\ModelCriteria $criteria + * * @param \Propel\Runtime\ActiveQuery\ModelCriteria $criteria The primary criteria * @param \Propel\Runtime\ActiveQuery\Join $previousJoin The previousJoin for this ModelCriteria * @@ -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 diff --git a/src/Propel/Runtime/ActiveRecord/ActiveRecordInterface.php b/src/Propel/Runtime/ActiveRecord/ActiveRecordInterface.php index 0d358475a4..2ece3d3371 100644 --- a/src/Propel/Runtime/ActiveRecord/ActiveRecordInterface.php +++ b/src/Propel/Runtime/ActiveRecord/ActiveRecordInterface.php @@ -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 { diff --git a/src/Propel/Runtime/Collection/ArrayCollection.php b/src/Propel/Runtime/Collection/ArrayCollection.php index a8d9d7d7d0..c08fc348d4 100644 --- a/src/Propel/Runtime/Collection/ArrayCollection.php +++ b/src/Propel/Runtime/Collection/ArrayCollection.php @@ -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 */ class ArrayCollection extends Collection { /** + * @phpstan-var TType + * * @var \Propel\Runtime\ActiveRecord\ActiveRecordInterface */ protected $workerObject; diff --git a/src/Propel/Runtime/Collection/Collection.php b/src/Propel/Runtime/Collection/Collection.php index a723643ae2..81aafb1a54 100644 --- a/src/Propel/Runtime/Collection/Collection.php +++ b/src/Propel/Runtime/Collection/Collection.php @@ -37,30 +37,43 @@ * @method string toYAML(bool $usePrefix = true, bool $includeLazyLoadColumns = true) Export the collection to a YAML string * @method string toJSON(bool $usePrefix = true, bool $includeLazyLoadColumns = true) Export the collection to a JSON string * @method string toCSV(bool $usePrefix = true, bool $includeLazyLoadColumns = true) Export the collection to a CSV string + * @method void fromArray(array $arr) Populates the collection from an array + * @method array toArray(?string $keyColumn = null, bool $usePrefix = false, string $keyType = \Propel\Runtime\Map\TableMap::TYPE_PHPNAME, bool $includeLazyLoadColumns = true, array $alreadyDumpedObjects = []) Get an array representation of the collection * * @author Francois Zaninotto + * + * @phpstan-template TType of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * @phpstan-template T + * @phpstan-implements \ArrayAccess + * @phpstan-implements \IteratorAggregate */ class Collection implements ArrayAccess, IteratorAggregate, Countable, Serializable { /** - * @var string + * @phpstan-var class-string + * + * @var string|null */ - protected $model = ''; + protected $model; /** * The fully qualified classname of the model * - * @var string + * @phpstan-var class-string + * + * @var string|null */ - protected $fullyQualifiedModel = ''; + protected $fullyQualifiedModel; /** + * @phpstan-var \Propel\Runtime\Formatter\AbstractFormatter + * * @var \Propel\Runtime\Formatter\AbstractFormatter */ protected $formatter; /** - * @var array + * @var array */ protected $data = []; @@ -70,7 +83,7 @@ class Collection implements ArrayAccess, IteratorAggregate, Countable, Serializa private $pluralizer; /** - * @param array $data + * @param array $data */ public function __construct(array $data = []) { @@ -96,6 +109,8 @@ public function __unserialize(array $data): void } /** + * @phpstan-param T $value + * * @param mixed $value * * @return void @@ -118,6 +133,8 @@ public function offsetExists($offset): bool /** * @psalm-suppress ReservedWord * + * @phpstan-return T|null + * * @param mixed $offset * * @return mixed @@ -129,10 +146,14 @@ public function &offsetGet($offset) return $this->data[$offset]; } - return null; + $result = null; + + return $result; } /** + * @phpstan-param T $value + * * @param mixed $offset * @param mixed $value * @@ -158,7 +179,7 @@ public function offsetUnset($offset): void } /** - * @param array $input + * @param array $input * * @return void */ @@ -170,7 +191,7 @@ public function exchangeArray(array $input): void /** * Get the data in the collection * - * @return array + * @return array */ public function getData(): array { @@ -178,7 +199,7 @@ public function getData(): array } /** - * @return array + * @return array */ public function getArrayCopy(): array { @@ -188,7 +209,7 @@ public function getArrayCopy(): array /** * Set the data in the collection * - * @param array $data + * @param array $data * * @return void */ @@ -198,6 +219,8 @@ public function setData(array $data): void } /** + * @phpstan-return \Iterator + * * @return \Propel\Runtime\Collection\CollectionIterator */ public function getIterator(): Traversable @@ -218,6 +241,8 @@ public function count(): int /** * Get the first element in the collection * + * @phpstan-return T|null + * * @return mixed */ public function getFirst() @@ -233,6 +258,8 @@ public function getFirst() /** * Get the last element in the collection * + * @phpstan-return T|null + * * @return mixed */ public function getLast() @@ -260,6 +287,8 @@ public function isEmpty(): bool * Get an element from its key * Alias for ArrayObject::offsetGet() * + * @phpstan-return T + * * @param mixed $key * * @throws \Propel\Runtime\Exception\UnexpectedValueException @@ -278,6 +307,8 @@ public function get($key) /** * Pops an element off the end of the collection * + * @phpstan-return T|null + * * @return mixed The popped element */ public function pop() @@ -296,6 +327,8 @@ public function pop() /** * Pops an element off the beginning of the collection * + * @phpstan-return T|null + * * @return mixed The popped element */ public function shift() @@ -312,6 +345,8 @@ public function shift() /** * Prepend one elements to the end of the collection * + * @phpstan-param T $value + * * @param mixed $value the element to prepend * * @return void @@ -324,6 +359,8 @@ public function push($value): void /** * Prepend one or more elements to the beginning of the collection * + * @phpstan-param T $value + * * @param mixed $value the element to prepend * * @return int The number of new elements in the array @@ -343,6 +380,8 @@ public function prepend($value): int * Add an element to the collection with the given key * Alias for ArrayObject::offsetSet() * + * @phpstan-param T $value + * * @param mixed $key * @param mixed $value * @@ -385,6 +424,8 @@ public function clear(): void /** * Whether this collection contains a specified element * + * @phpstan-param T $element + * * @param mixed $element * * @return bool @@ -397,6 +438,8 @@ public function contains($element): bool /** * Search an element in the collection * + * @phpstan-param T $element + * * @param mixed $element * * @return mixed Returns the key for the element if it is found in the collection, FALSE otherwise @@ -410,6 +453,10 @@ public function search($element) * Returns an array of objects present in the collection that * are not presents in the given collection. * + * @phpstan-param \Propel\Runtime\Collection\Collection $collection + * + * @phpstan-return self + * * @param \Propel\Runtime\Collection\Collection $collection A Propel collection. * * @return self An array of Propel objects from the collection that are not presents in the given collection. @@ -464,6 +511,8 @@ public function unserialize($data): void /** * Set the model of the elements in the collection * + * @phpstan-param class-string $model + * * @param string $model Name of the Propel object classes stored in the collection * * @return void @@ -482,6 +531,8 @@ public function setModel(string $model): void /** * Get the model of the elements in the collection * + * @phpstan-return class-string + * * @return string Name of the Propel object class stored in the collection */ public function getModel(): string @@ -492,6 +543,8 @@ public function getModel(): string /** * Get the model of the elements in the collection * + * @phpstan-return class-string + * * @return string Fully qualified Name of the Propel object class stored in the collection */ public function getFullyQualifiedModel(): string @@ -500,7 +553,7 @@ public function getFullyQualifiedModel(): string } /** - * @psalm-return class-string<\Propel\Runtime\Map\TableMap> + * @phpstan-return class-string<\Propel\Runtime\Map\TableMap> * * @throws \Propel\Runtime\Collection\Exception\ModelNotFoundException * @@ -518,6 +571,8 @@ public function getTableMapClass(): string } /** + * @phpstan-param \Propel\Runtime\Formatter\AbstractFormatter $formatter + * * @param \Propel\Runtime\Formatter\AbstractFormatter $formatter * * @return void @@ -528,6 +583,8 @@ public function setFormatter(AbstractFormatter $formatter): void } /** + * @phpstan-return \Propel\Runtime\Formatter\AbstractFormatter + * * @return \Propel\Runtime\Formatter\AbstractFormatter */ public function getFormatter(): AbstractFormatter @@ -566,7 +623,9 @@ public function importFrom($parser, string $data) $parser = AbstractParser::getParser($parser); } - return $this->fromArray($parser->listToArray($data, $this->getPluralModelName()), TableMap::TYPE_PHPNAME); + $this->fromArray($parser->listToArray($data, $this->getPluralModelName())); + + return $this; } /** @@ -653,6 +712,7 @@ public function __toString(): string */ public function __clone() { + /** @phpstan-var T $obj */ foreach ($this as $key => $obj) { if (is_object($obj)) { $this[$key] = clone $obj; diff --git a/src/Propel/Runtime/Collection/CollectionIterator.php b/src/Propel/Runtime/Collection/CollectionIterator.php index df06ff7aae..5296cc99de 100644 --- a/src/Propel/Runtime/Collection/CollectionIterator.php +++ b/src/Propel/Runtime/Collection/CollectionIterator.php @@ -12,10 +12,15 @@ /** * Iterator class for iterating over Collection data + * + * @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * @phpstan-extends \ArrayIterator */ class CollectionIterator extends ArrayIterator { /** + * @phpstan-var \Propel\Runtime\Collection\Collection + * * @var \Propel\Runtime\Collection\Collection */ protected Collection $collection; @@ -28,6 +33,8 @@ class CollectionIterator extends ArrayIterator /** * Constructor * + * @phpstan-param \Propel\Runtime\Collection\Collection $collection + * * @param \Propel\Runtime\Collection\Collection $collection */ public function __construct(Collection $collection) @@ -41,6 +48,8 @@ public function __construct(Collection $collection) /** * Returns the collection instance * + * @phpstan-return \Propel\Runtime\Collection\Collection + * * @return \Propel\Runtime\Collection\Collection */ public function getCollection(): Collection @@ -79,6 +88,8 @@ public function getPosition(): int * * @psalm-suppress ReservedWord * + * @phpstan-return T|null + * * @return mixed */ #[\ReturnTypeWillChange] @@ -108,6 +119,8 @@ public function isFirst(): bool * * @psalm-suppress ReservedWord * + * @phpstan-return T|null + * * @return mixed */ #[\ReturnTypeWillChange] @@ -127,6 +140,8 @@ public function getPrevious() * * @psalm-suppress ReservedWord * + * @phpstan-return T|null + * * @return mixed */ #[\ReturnTypeWillChange] @@ -141,6 +156,8 @@ public function getCurrent() * * @psalm-suppress ReservedWord * + * @phpstan-return T|null + * * @return mixed */ #[\ReturnTypeWillChange] @@ -157,6 +174,8 @@ public function getNext() * * @psalm-suppress ReservedWord * + * @phpstan-return T|null + * * @return mixed */ #[\ReturnTypeWillChange] @@ -207,6 +226,8 @@ public function isEven(): bool } /** + * @phpstan-param T $value + * * @param string $index * @param string $value * diff --git a/src/Propel/Runtime/Collection/ObjectCollection.php b/src/Propel/Runtime/Collection/ObjectCollection.php index a7e57a8414..fddd11e78a 100644 --- a/src/Propel/Runtime/Collection/ObjectCollection.php +++ b/src/Propel/Runtime/Collection/ObjectCollection.php @@ -22,6 +22,10 @@ * Class for iterating over a list of Propel objects * * @author Francois Zaninotto + * + * @phpstan-template TType of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * @phpstan-template T + * @phpstan-extends \Propel\Runtime\Collection\Collection */ class ObjectCollection extends Collection { @@ -36,7 +40,7 @@ class ObjectCollection extends Collection protected $indexSplHash = []; /** - * @param array $data + * @param array $data */ public function __construct(array $data = []) { @@ -457,6 +461,8 @@ public function offsetUnset($offset): void } /** + * @phpstan-param TType $element + * * @param mixed $element * * @return void @@ -469,6 +475,8 @@ public function removeObject($element): void } /** + * @phpstan-param TType $value + * * @param mixed $value * * @return void @@ -491,6 +499,8 @@ public function append($value): void } /** + * @phpstan-param TType $value + * * @param mixed $offset * @param mixed $value * diff --git a/src/Propel/Runtime/Collection/OnDemandCollection.php b/src/Propel/Runtime/Collection/OnDemandCollection.php index f9490f18f0..aa72cfe647 100644 --- a/src/Propel/Runtime/Collection/OnDemandCollection.php +++ b/src/Propel/Runtime/Collection/OnDemandCollection.php @@ -19,15 +19,23 @@ * Class for iterating over a statement and returning one Propel object at a time * * @author Francois Zaninotto + * + * @phpstan-template TType of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * @phpstan-extends \Propel\Runtime\Collection\Collection */ class OnDemandCollection extends Collection { /** + * @phpstan-var \Propel\Runtime\Collection\OnDemandIterator + * * @var \Propel\Runtime\Collection\OnDemandIterator */ private $lastIterator; /** + * @phpstan-param \Propel\Runtime\Formatter\OnDemandFormatter $formatter + * * @param \Propel\Runtime\Formatter\ObjectFormatter $formatter * @param \Propel\Runtime\DataFetcher\DataFetcherInterface $dataFetcher * @@ -111,6 +119,8 @@ public function fromArray(array $arr): void // IteratorAggregate Interface /** + * @phpstan-return \Propel\Runtime\Collection\OnDemandIterator + * * @return \Propel\Runtime\Collection\OnDemandIterator */ public function getIterator(): Traversable diff --git a/src/Propel/Runtime/Collection/OnDemandIterator.php b/src/Propel/Runtime/Collection/OnDemandIterator.php index 53815554a8..a21fe846f6 100644 --- a/src/Propel/Runtime/Collection/OnDemandIterator.php +++ b/src/Propel/Runtime/Collection/OnDemandIterator.php @@ -19,11 +19,16 @@ * Class for iterating over a statement and returning one Propel object at a time * * @author Francois Zaninotto + * + * @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * @phpstan-implements \Iterator */ class OnDemandIterator implements Iterator { /** - * @var \Propel\Runtime\Formatter\ObjectFormatter + * @phpstan-var \Propel\Runtime\Formatter\OnDemandFormatter + * + * @var \Propel\Runtime\Formatter\OnDemandFormatter */ protected $formatter; @@ -53,7 +58,7 @@ class OnDemandIterator implements Iterator protected $enableInstancePoolingOnFinish; /** - * @param \Propel\Runtime\Formatter\ObjectFormatter $formatter + * @param \Propel\Runtime\Formatter\OnDemandFormatter $formatter * @param \Propel\Runtime\DataFetcher\DataFetcherInterface $dataFetcher */ public function __construct(AbstractFormatter $formatter, DataFetcherInterface $dataFetcher) @@ -94,6 +99,8 @@ public function count(): int * * @psalm-suppress ReservedWord * + * @phpstan-return T + * * @see ObjectFormatter::getAllObjectsFromRow() * * @return \Propel\Runtime\ActiveRecord\ActiveRecordInterface diff --git a/src/Propel/Runtime/Formatter/AbstractFormatter.php b/src/Propel/Runtime/Formatter/AbstractFormatter.php index 6857000920..38a54a4d62 100644 --- a/src/Propel/Runtime/Formatter/AbstractFormatter.php +++ b/src/Propel/Runtime/Formatter/AbstractFormatter.php @@ -19,6 +19,10 @@ * Abstract class for query formatter * * @author Francois Zaninotto + * + * @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * @phpstan-template TColl of \Propel\Runtime\Collection\Collection + * @phpstan-template TReturn */ abstract class AbstractFormatter { @@ -28,11 +32,15 @@ abstract class AbstractFormatter protected $dbName; /** + * @phpstan-var class-string|null + * * @var string|null */ protected $class; /** + * @phpstan-var \Propel\Runtime\Map\TableMap|null + * * @var \Propel\Runtime\Map\TableMap|null */ protected $tableMap; @@ -63,6 +71,8 @@ abstract class AbstractFormatter protected $dataFetcher; /** + * @phpstan-param \Propel\Runtime\ActiveQuery\BaseModelCriteria $criteria + * * @param \Propel\Runtime\ActiveQuery\BaseModelCriteria|null $criteria * @param \Propel\Runtime\DataFetcher\DataFetcherInterface|null $dataFetcher */ @@ -99,6 +109,13 @@ public function getDataFetcher(): DataFetcherInterface * Define the hydration schema based on a query object. * Fills the Formatter's properties using a Criteria as source * + * @phpstan-template AColl of \Propel\Runtime\Collection\Collection + * @phpstan-template AReturn + * + * @phpstan-param \Propel\Runtime\ActiveQuery\BaseModelCriteria $criteria + * + * @phpstan-return $this + * * @param \Propel\Runtime\ActiveQuery\BaseModelCriteria $criteria * @param \Propel\Runtime\DataFetcher\DataFetcherInterface|null $dataFetcher * @@ -139,6 +156,8 @@ public function getDbName(): ?string } /** + * @phpstan-param class-string $class + * * @param string $class * * @return void @@ -150,6 +169,8 @@ public function setClass(string $class): void } /** + * @phpstan-return class-string|null + * * @return string|null */ public function getClass(): ?string @@ -214,6 +235,8 @@ public function hasLimit(): bool /** * Returns a Collection object or a simple array. * + * @phpstan-return TColl|array + * * @return \Propel\Runtime\Collection\Collection|array */ protected function getCollection() @@ -234,6 +257,8 @@ protected function getCollection() /** * @psalm-return class-string<\Propel\Runtime\Collection\Collection>|null * + * @phpstan-return class-string>|null + * * @return string|null */ public function getCollectionClassName(): ?string @@ -244,6 +269,10 @@ public function getCollectionClassName(): ?string /** * Formats an ActiveRecord object * + * @phpstan-param T|null $record + * + * @phpstan-return T|array|null + * * @param \Propel\Runtime\ActiveRecord\ActiveRecordInterface|null $record the object to format * * @return mixed The original record @@ -285,6 +314,8 @@ public function checkInit(): void } /** + * @phpstan-return \Propel\Runtime\Map\TableMap + * * @return \Propel\Runtime\Map\TableMap */ public function getTableMap(): TableMap @@ -309,6 +340,10 @@ protected function isWithOneToMany(): bool /** * Gets a Propel object hydrated from a selection of columns in statement row * + * @phpstan-param class-string $class + * + * @phpstan-return T + * * @param array $row associative array indexed by column number, * as returned by DataFetcher::fetch() * @param string $class The classname of the object to create diff --git a/src/Propel/Runtime/Formatter/AbstractFormatterWithHydration.php b/src/Propel/Runtime/Formatter/AbstractFormatterWithHydration.php index a8a872e1fe..dcccc5b74d 100644 --- a/src/Propel/Runtime/Formatter/AbstractFormatterWithHydration.php +++ b/src/Propel/Runtime/Formatter/AbstractFormatterWithHydration.php @@ -12,6 +12,12 @@ use Propel\Runtime\Collection\ArrayCollection; use ReflectionClass; +/** + * @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * @phpstan-template TColl of \Propel\Runtime\Collection\Collection + * @phpstan-template TReturn + * @phpstan-extends \Propel\Runtime\Formatter\AbstractFormatter + */ abstract class AbstractFormatterWithHydration extends AbstractFormatter { /** diff --git a/src/Propel/Runtime/Formatter/ArrayFormatter.php b/src/Propel/Runtime/Formatter/ArrayFormatter.php index 0038b53cf7..d70f412c3d 100644 --- a/src/Propel/Runtime/Formatter/ArrayFormatter.php +++ b/src/Propel/Runtime/Formatter/ArrayFormatter.php @@ -9,6 +9,7 @@ namespace Propel\Runtime\Formatter; use Propel\Runtime\ActiveRecord\ActiveRecordInterface; +use Propel\Runtime\Collection\ArrayCollection; use Propel\Runtime\DataFetcher\DataFetcherInterface; use Propel\Runtime\Exception\LogicException; @@ -17,6 +18,11 @@ * format() returns a ArrayCollection of associative arrays * * @author Francois Zaninotto + * + * @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * @phpstan-template TColl of \Propel\Runtime\Collection\ArrayCollection + * @phpstan-template TReturn + * @phpstan-extends \Propel\Runtime\Formatter\AbstractFormatterWithHydration */ class ArrayFormatter extends AbstractFormatterWithHydration { @@ -67,7 +73,7 @@ public function format(?DataFetcherInterface $dataFetcher = null) */ public function getCollectionClassName(): ?string { - return '\Propel\Runtime\Collection\ArrayCollection'; + return ArrayCollection::class; } /** @@ -108,6 +114,8 @@ public function formatOne(?DataFetcherInterface $dataFetcher = null): ?array /** * Formats an ActiveRecord object * + * @phpstan-param T|null $record + * * @param \Propel\Runtime\ActiveRecord\ActiveRecordInterface|null $record the object to format * * @return array The original record turned into an array diff --git a/src/Propel/Runtime/Formatter/ObjectFormatter.php b/src/Propel/Runtime/Formatter/ObjectFormatter.php index e7eb6f1f47..668e953ad5 100644 --- a/src/Propel/Runtime/Formatter/ObjectFormatter.php +++ b/src/Propel/Runtime/Formatter/ObjectFormatter.php @@ -17,15 +17,22 @@ * format() returns a ObjectCollection of Propel model objects * * @author Francois Zaninotto + * + * @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * @phpstan-template TColl of \Propel\Runtime\Collection\Collection + * @phpstan-template TReturn + * @phpstan-extends \Propel\Runtime\Formatter\AbstractFormatter */ class ObjectFormatter extends AbstractFormatter { /** - * @var array + * @var array */ protected $objects = []; /** + * @phpstan-return TColl|array + * * @param \Propel\Runtime\DataFetcher\DataFetcherInterface|null $dataFetcher * * @throws \Propel\Runtime\Exception\LogicException @@ -69,6 +76,8 @@ public function format(?DataFetcherInterface $dataFetcher = null) } /** + * @phpstan-return class-string + * * @return string|null */ public function getCollectionClassName(): ?string @@ -77,6 +86,8 @@ public function getCollectionClassName(): ?string } /** + * @phpstan-return T|null + * * @param \Propel\Runtime\DataFetcher\DataFetcherInterface|null $dataFetcher * * @throws \Propel\Runtime\Exception\LogicException @@ -118,6 +129,8 @@ public function isObjectFormatter(): bool * The first object to hydrate is the model of the Criteria * The following objects (the ones added by way of ModelCriteria::with()) are linked to the first one * + * @phpstan-return T + * * @param array $row associative array indexed by column number, * as returned by DataFetcher::fetch() * diff --git a/src/Propel/Runtime/Formatter/OnDemandFormatter.php b/src/Propel/Runtime/Formatter/OnDemandFormatter.php index 62fbf40397..a31aa3c465 100644 --- a/src/Propel/Runtime/Formatter/OnDemandFormatter.php +++ b/src/Propel/Runtime/Formatter/OnDemandFormatter.php @@ -21,6 +21,11 @@ * This formatter consumes less memory than the ObjectFormatter, but doesn't use Instance Pool * * @author Francois Zaninotto + * + * @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * @phpstan-template TColl of \Propel\Runtime\Collection\OnDemandCollection + * @phpstan-template TReturn of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * @phpstan-extends \Propel\Runtime\Formatter\ObjectFormatter */ class OnDemandFormatter extends ObjectFormatter { @@ -30,6 +35,8 @@ class OnDemandFormatter extends ObjectFormatter protected $isSingleTableInheritance = false; /** + * @phpstan-return $this + * * @param \Propel\Runtime\ActiveQuery\BaseModelCriteria|null $criteria * @param \Propel\Runtime\DataFetcher\DataFetcherInterface|null $dataFetcher * @@ -45,6 +52,8 @@ public function init(?BaseModelCriteria $criteria = null, ?DataFetcherInterface } /** + * @phpstan-return TColl + * * @param \Propel\Runtime\DataFetcher\DataFetcherInterface|null $dataFetcher * * @throws \Propel\Runtime\Exception\LogicException @@ -73,21 +82,24 @@ public function format(?DataFetcherInterface $dataFetcher = null): OnDemandColle /** * @psalm-return class-string<\Propel\Runtime\Collection\OnDemandCollection> * + * @phpstan-return class-string<\Propel\Runtime\Collection\OnDemandCollection> + * * @return string */ public function getCollectionClassName(): string { - return '\Propel\Runtime\Collection\OnDemandCollection'; + return OnDemandCollection::class; } /** + * @phpstan-return \Propel\Runtime\Collection\OnDemandCollection + * * @return \Propel\Runtime\Collection\OnDemandCollection */ public function getCollection(): OnDemandCollection { $class = $this->getCollectionClassName(); - /** @var \Propel\Runtime\Collection\OnDemandCollection $collection */ $collection = new $class(); $collection->setModel($this->class); @@ -99,6 +111,8 @@ public function getCollection(): OnDemandCollection * The first object to hydrate is the model of the Criteria * The following objects (the ones added by way of ModelCriteria::with()) are linked to the first one * + * @phpstan-return T + * * @param array $row associative array with data * * @return \Propel\Runtime\ActiveRecord\ActiveRecordInterface diff --git a/src/Propel/Runtime/Formatter/SimpleArrayFormatter.php b/src/Propel/Runtime/Formatter/SimpleArrayFormatter.php index e03ef43a5e..22ff44fd7b 100644 --- a/src/Propel/Runtime/Formatter/SimpleArrayFormatter.php +++ b/src/Propel/Runtime/Formatter/SimpleArrayFormatter.php @@ -18,6 +18,11 @@ * or an array * * @author Benjamin Runnels + * + * @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * @phpstan-template TColl of \Propel\Runtime\Collection\ObjectCollection + * @phpstan-template TReturn + * @phpstan-extends \Propel\Runtime\Formatter\AbstractFormatter */ class SimpleArrayFormatter extends AbstractFormatter { diff --git a/src/Propel/Runtime/Formatter/StatementFormatter.php b/src/Propel/Runtime/Formatter/StatementFormatter.php index f3692048bb..30ea4ce9d6 100644 --- a/src/Propel/Runtime/Formatter/StatementFormatter.php +++ b/src/Propel/Runtime/Formatter/StatementFormatter.php @@ -17,6 +17,11 @@ * format() returns a PDO statement * * @author Francois Zaninotto + * + * @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface + * @phpstan-template TColl of \Propel\Runtime\Collection\ObjectCollection + * @phpstan-template TReturn + * @phpstan-extends \Propel\Runtime\Formatter\AbstractFormatter */ class StatementFormatter extends AbstractFormatter { diff --git a/src/Propel/Runtime/Map/TableMap.php b/src/Propel/Runtime/Map/TableMap.php index ce10ddf1c5..a1cdb47d89 100644 --- a/src/Propel/Runtime/Map/TableMap.php +++ b/src/Propel/Runtime/Map/TableMap.php @@ -25,6 +25,10 @@ * * @method static string getOMClass(array $row, int $column, bool $withPrefix = true) * @method static string|null getPrimaryKeyHashFromRow(array $row, int $offset = 0, string $indexType = \Propel\Runtime\Map\TableMap::TYPE_NUM): ?string;getPrimaryKeyHashFromRow(array $row, int $offset = 0, string $indexType = TableMap::TYPE_NUM) + * @method static static getPrimaryKeyFromRow($row, $offset = 0, $indexType = \Propel\Runtime\Map\TableMap::TYPE_NUM) + * @method array populateObject(array $row, int $offset = 0, string $indexType = \Propel\Runtime\Map\TableMap::TYPE_NUM) + * + * @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface */ class TableMap { @@ -111,6 +115,8 @@ class TableMap /** * The ClassName for this table * + * @phpstan-var class-string + * * @var string */ protected $classname; @@ -318,6 +324,8 @@ public function getPhpNameOrFail(): string * Set the ClassName of the Table. Could be useful for calling * tableMap and Object methods dynamically. * + * @phpstan-param class-string $classname + * * @param string $classname The ClassName * * @return void @@ -358,6 +366,8 @@ public function getClassNameOrFail(): string /** * Get the Collection ClassName to this table. * + * @phpstan-return class-string<\Propel\Runtime\Collection\Collection> + * * @return string */ public function getCollectionClassName(): string diff --git a/src/Propel/Runtime/Util/PropelModelPager.php b/src/Propel/Runtime/Util/PropelModelPager.php index 7d5975fccb..e08d77d835 100644 --- a/src/Propel/Runtime/Util/PropelModelPager.php +++ b/src/Propel/Runtime/Util/PropelModelPager.php @@ -166,9 +166,7 @@ public function getResults(): Collection ->find($this->con); } - return is_array($this->results) - ? new Collection($this->results) - : $this->results; + return $this->results; } /** diff --git a/tests/Propel/Tests/Runtime/Collection/ArrayCollectionTest.php b/tests/Propel/Tests/Runtime/Collection/ArrayCollectionTest.php index 46c76a2606..9d3524b62a 100644 --- a/tests/Propel/Tests/Runtime/Collection/ArrayCollectionTest.php +++ b/tests/Propel/Tests/Runtime/Collection/ArrayCollectionTest.php @@ -263,6 +263,8 @@ public function testGetWorkerObjectNoModel() class TestableArrayCollection extends ArrayCollection { + protected $model = ''; + public function getWorkerObject(): ActiveRecordInterface { return parent::getWorkerObject(); From 38af0196939d20d8dcbe060329f4d208a93586dd Mon Sep 17 00:00:00 2001 From: Dmytro Dymarchuk Date: Thu, 7 Apr 2022 15:41:48 +0300 Subject: [PATCH 2/2] Add template for phpstan --- .../Runtime/ActiveQuery/BaseModelCriteria.php | 6 ++++-- .../Runtime/Collection/ArrayCollection.php | 5 ++--- src/Propel/Runtime/Collection/Collection.php | 19 +++++++++---------- .../Runtime/Collection/ObjectCollection.php | 11 +++++------ .../ObjectCombinationCollection.php | 3 +++ .../Runtime/Collection/OnDemandCollection.php | 5 ++--- .../Runtime/Formatter/OnDemandFormatter.php | 4 ++-- 7 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php b/src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php index 1a14148903..5f396f103c 100644 --- a/src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php +++ b/src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php @@ -50,7 +50,9 @@ abstract class BaseModelCriteria extends Criteria implements IteratorAggregate protected $modelAlias; /** - * @var \Propel\Runtime\Map\TableMap|T[] + * @phpstan-var \Propel\Runtime\Map\TableMap|null + * + * @var \Propel\Runtime\Map\TableMap|null */ protected $tableMap; @@ -308,7 +310,7 @@ public static function getShortName(string $fullyQualifiedClassName): string /** * Returns the TableMap object for this Criteria * - * @phpstan-return \Propel\Runtime\Map\TableMap + * @phpstan-return \Propel\Runtime\Map\TableMap|null * * @return \Propel\Runtime\Map\TableMap|null */ diff --git a/src/Propel/Runtime/Collection/ArrayCollection.php b/src/Propel/Runtime/Collection/ArrayCollection.php index c08fc348d4..213360bf84 100644 --- a/src/Propel/Runtime/Collection/ArrayCollection.php +++ b/src/Propel/Runtime/Collection/ArrayCollection.php @@ -18,13 +18,12 @@ * * @author Francois Zaninotto * - * @phpstan-template TType of \Propel\Runtime\ActiveRecord\ActiveRecordInterface - * @phpstan-extends \Propel\Runtime\Collection\Collection + * @phpstan-extends \Propel\Runtime\Collection\Collection */ class ArrayCollection extends Collection { /** - * @phpstan-var TType + * @phpstan-var \Propel\Runtime\ActiveRecord\ActiveRecordInterface * * @var \Propel\Runtime\ActiveRecord\ActiveRecordInterface */ diff --git a/src/Propel/Runtime/Collection/Collection.php b/src/Propel/Runtime/Collection/Collection.php index 81aafb1a54..06ef8835b2 100644 --- a/src/Propel/Runtime/Collection/Collection.php +++ b/src/Propel/Runtime/Collection/Collection.php @@ -42,7 +42,6 @@ * * @author Francois Zaninotto * - * @phpstan-template TType of \Propel\Runtime\ActiveRecord\ActiveRecordInterface * @phpstan-template T * @phpstan-implements \ArrayAccess * @phpstan-implements \IteratorAggregate @@ -50,7 +49,7 @@ class Collection implements ArrayAccess, IteratorAggregate, Countable, Serializable { /** - * @phpstan-var class-string + * @phpstan-var class-string<\Propel\Runtime\ActiveRecord\ActiveRecordInterface> * * @var string|null */ @@ -59,14 +58,14 @@ class Collection implements ArrayAccess, IteratorAggregate, Countable, Serializa /** * The fully qualified classname of the model * - * @phpstan-var class-string + * @phpstan-var class-string<\Propel\Runtime\ActiveRecord\ActiveRecordInterface> * * @var string|null */ protected $fullyQualifiedModel; /** - * @phpstan-var \Propel\Runtime\Formatter\AbstractFormatter + * @phpstan-var \Propel\Runtime\Formatter\AbstractFormatter<\Propel\Runtime\ActiveRecord\ActiveRecordInterface, \Propel\Runtime\Collection\Collection, T> * * @var \Propel\Runtime\Formatter\AbstractFormatter */ @@ -453,7 +452,7 @@ public function search($element) * Returns an array of objects present in the collection that * are not presents in the given collection. * - * @phpstan-param \Propel\Runtime\Collection\Collection $collection + * @phpstan-param \Propel\Runtime\Collection\Collection $collection * * @phpstan-return self * @@ -511,7 +510,7 @@ public function unserialize($data): void /** * Set the model of the elements in the collection * - * @phpstan-param class-string $model + * @phpstan-param class-string<\Propel\Runtime\ActiveRecord\ActiveRecordInterface> $model * * @param string $model Name of the Propel object classes stored in the collection * @@ -531,7 +530,7 @@ public function setModel(string $model): void /** * Get the model of the elements in the collection * - * @phpstan-return class-string + * @phpstan-return class-string<\Propel\Runtime\ActiveRecord\ActiveRecordInterface> * * @return string Name of the Propel object class stored in the collection */ @@ -543,7 +542,7 @@ public function getModel(): string /** * Get the model of the elements in the collection * - * @phpstan-return class-string + * @phpstan-return class-string<\Propel\Runtime\ActiveRecord\ActiveRecordInterface> * * @return string Fully qualified Name of the Propel object class stored in the collection */ @@ -571,7 +570,7 @@ public function getTableMapClass(): string } /** - * @phpstan-param \Propel\Runtime\Formatter\AbstractFormatter $formatter + * @phpstan-param \Propel\Runtime\Formatter\AbstractFormatter<\Propel\Runtime\ActiveRecord\ActiveRecordInterface, self, T> $formatter * * @param \Propel\Runtime\Formatter\AbstractFormatter $formatter * @@ -583,7 +582,7 @@ public function setFormatter(AbstractFormatter $formatter): void } /** - * @phpstan-return \Propel\Runtime\Formatter\AbstractFormatter + * @phpstan-return \Propel\Runtime\Formatter\AbstractFormatter<\Propel\Runtime\ActiveRecord\ActiveRecordInterface, \Propel\Runtime\Collection\Collection, T> * * @return \Propel\Runtime\Formatter\AbstractFormatter */ diff --git a/src/Propel/Runtime/Collection/ObjectCollection.php b/src/Propel/Runtime/Collection/ObjectCollection.php index fddd11e78a..cc4a54604c 100644 --- a/src/Propel/Runtime/Collection/ObjectCollection.php +++ b/src/Propel/Runtime/Collection/ObjectCollection.php @@ -23,9 +23,8 @@ * * @author Francois Zaninotto * - * @phpstan-template TType of \Propel\Runtime\ActiveRecord\ActiveRecordInterface * @phpstan-template T - * @phpstan-extends \Propel\Runtime\Collection\Collection + * @phpstan-extends \Propel\Runtime\Collection\Collection */ class ObjectCollection extends Collection { @@ -40,7 +39,7 @@ class ObjectCollection extends Collection protected $indexSplHash = []; /** - * @param array $data + * @param array<\Propel\Runtime\ActiveRecord\ActiveRecordInterface> $data */ public function __construct(array $data = []) { @@ -461,7 +460,7 @@ public function offsetUnset($offset): void } /** - * @phpstan-param TType $element + * @phpstan-param \Propel\Runtime\ActiveRecord\ActiveRecordInterface $element * * @param mixed $element * @@ -475,7 +474,7 @@ public function removeObject($element): void } /** - * @phpstan-param TType $value + * @phpstan-param \Propel\Runtime\ActiveRecord\ActiveRecordInterface $value * * @param mixed $value * @@ -499,7 +498,7 @@ public function append($value): void } /** - * @phpstan-param TType $value + * @phpstan-param \Propel\Runtime\ActiveRecord\ActiveRecordInterface $value * * @param mixed $offset * @param mixed $value diff --git a/src/Propel/Runtime/Collection/ObjectCombinationCollection.php b/src/Propel/Runtime/Collection/ObjectCombinationCollection.php index 9ad6a4f551..e5f7e261c4 100644 --- a/src/Propel/Runtime/Collection/ObjectCombinationCollection.php +++ b/src/Propel/Runtime/Collection/ObjectCombinationCollection.php @@ -14,6 +14,9 @@ * Class for iterating over a list of Propel objects * * @author Francois Zaninotto + * + * @phpstan-template T array<\Propel\Runtime\ActiveRecord\ActiveRecordInterface> + * @phpstan-extends \Propel\Runtime\Collection\ObjectCollection */ class ObjectCombinationCollection extends ObjectCollection { diff --git a/src/Propel/Runtime/Collection/OnDemandCollection.php b/src/Propel/Runtime/Collection/OnDemandCollection.php index aa72cfe647..1f39fd1c0f 100644 --- a/src/Propel/Runtime/Collection/OnDemandCollection.php +++ b/src/Propel/Runtime/Collection/OnDemandCollection.php @@ -20,9 +20,8 @@ * * @author Francois Zaninotto * - * @phpstan-template TType of \Propel\Runtime\ActiveRecord\ActiveRecordInterface * @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface - * @phpstan-extends \Propel\Runtime\Collection\Collection + * @phpstan-extends \Propel\Runtime\Collection\Collection */ class OnDemandCollection extends Collection { @@ -34,7 +33,7 @@ class OnDemandCollection extends Collection private $lastIterator; /** - * @phpstan-param \Propel\Runtime\Formatter\OnDemandFormatter $formatter + * @phpstan-param \Propel\Runtime\Formatter\OnDemandFormatter<\Propel\Runtime\ActiveRecord\ActiveRecordInterface, \Propel\Runtime\Collection\OnDemandCollection, T> $formatter * * @param \Propel\Runtime\Formatter\ObjectFormatter $formatter * @param \Propel\Runtime\DataFetcher\DataFetcherInterface $dataFetcher diff --git a/src/Propel/Runtime/Formatter/OnDemandFormatter.php b/src/Propel/Runtime/Formatter/OnDemandFormatter.php index a31aa3c465..b2dee6be3b 100644 --- a/src/Propel/Runtime/Formatter/OnDemandFormatter.php +++ b/src/Propel/Runtime/Formatter/OnDemandFormatter.php @@ -52,7 +52,7 @@ public function init(?BaseModelCriteria $criteria = null, ?DataFetcherInterface } /** - * @phpstan-return TColl + * @phpstan-return TColl * * @param \Propel\Runtime\DataFetcher\DataFetcherInterface|null $dataFetcher * @@ -92,7 +92,7 @@ public function getCollectionClassName(): string } /** - * @phpstan-return \Propel\Runtime\Collection\OnDemandCollection + * @phpstan-return \Propel\Runtime\Collection\OnDemandCollection * * @return \Propel\Runtime\Collection\OnDemandCollection */