Skip to content

Commit 2ecd9ee

Browse files
author
Dmytro Dymarchuk
committed
Add template for phpstan
1 parent 0cfea4e commit 2ecd9ee

19 files changed

+301
-29
lines changed

src/Propel/Generator/Builder/Om/ObjectBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4463,7 +4463,7 @@ protected function addInitRelations(string &$script, array $referrers): void
44634463
* @param string \$relationName The name of the relation to initialize
44644464
* @return void
44654465
*/
4466-
public function initRelation(\$relationName)
4466+
public function initRelation(string \$relationName): void
44674467
{";
44684468
foreach ($referrers as $refFK) {
44694469
if (!$refFK->isLocalPrimaryKey()) {

src/Propel/Runtime/ActiveQuery/BaseModelCriteria.php

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,32 @@
1010

1111
use ArrayIterator;
1212
use IteratorAggregate;
13+
use Propel\Runtime\Connection\ConnectionInterface;
1314
use Propel\Runtime\Exception\InvalidArgumentException;
1415
use Propel\Runtime\Exception\LogicException;
1516
use Propel\Runtime\Formatter\AbstractFormatter;
1617
use Propel\Runtime\Map\TableMap;
1718
use Propel\Runtime\Propel;
1819
use Traversable;
1920

20-
class BaseModelCriteria extends Criteria implements IteratorAggregate
21+
/**
22+
* @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface
23+
* @phpstan-template TColl of \Propel\Runtime\Collection\Collection
24+
* @phpstan-template TReturn
25+
*/
26+
abstract class BaseModelCriteria extends Criteria implements IteratorAggregate
2127
{
2228
/**
29+
* @phpstan-var class-string<T>|null
30+
*
2331
* @var string|null
2432
*/
2533
protected $modelName;
2634

2735
/**
28-
* @var string|null
2936
* @phpstan-var class-string<\Propel\Runtime\Map\TableMap>|null
37+
*
38+
* @var string|null
3039
*/
3140
protected $modelTableMapName;
3241

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

4352
/**
44-
* @var \Propel\Runtime\Map\TableMap
53+
* @var \Propel\Runtime\Map\TableMap|T[]
4554
*/
4655
protected $tableMap;
4756

@@ -66,6 +75,8 @@ class BaseModelCriteria extends Criteria implements IteratorAggregate
6675
* Creates a new instance with the default capacity which corresponds to
6776
* the specified database.
6877
*
78+
* @phpstan-param class-string<T> $modelName
79+
*
6980
* @param string|null $dbName The database name
7081
* @param string|null $modelName The phpName of a model, e.g. 'Book'
7182
* @param string|null $modelAlias The alias for the model in this query, e.g. 'b'
@@ -113,6 +124,13 @@ public function setWith(array $with)
113124
* $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
114125
* </code>
115126
*
127+
* @phpstan-template AColl of \Propel\Runtime\Collection\Collection
128+
* @phpstan-template AReturn
129+
*
130+
* @phpstan-param \Propel\Runtime\Formatter\AbstractFormatter<T, AColl, AReturn>|class-string<\Propel\Runtime\Formatter\AbstractFormatter> $formatter
131+
*
132+
* @phpstan-return $this<T, AColl, AReturn>
133+
*
116134
* @param \Propel\Runtime\Formatter\AbstractFormatter|string $formatter a formatter class name, or a formatter instance
117135
*
118136
* @throws \Propel\Runtime\Exception\InvalidArgumentException
@@ -153,6 +171,8 @@ public function getFormatter(): AbstractFormatter
153171
/**
154172
* Returns the name of the class for this model criteria
155173
*
174+
* @phpstan-return class-string<T>
175+
*
156176
* @return string|null
157177
*/
158178
public function getModelName(): ?string
@@ -182,6 +202,8 @@ public function getModelNameOrFail(): string
182202
* Sets the model name.
183203
* This also sets `this->modelTableMapName` and `this->tableMap`.
184204
*
205+
* @phpstan-param class-string<T>|null $modelName
206+
*
185207
* @param string|null $modelName
186208
*
187209
* @return $this The current object, for fluid interface
@@ -194,6 +216,7 @@ public function setModelName(?string $modelName)
194216
return $this;
195217
}
196218
if (strpos($modelName, '\\') === 0) {
219+
/** @phpstan-var class-string<T> $modelName */
197220
$modelName = substr($modelName, 1);
198221
}
199222

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

211234
/**
235+
* @phpstan-return class-string<T>
236+
*
212237
* @return string
213238
*/
214239
public function getFullyQualifiedModelName(): string
@@ -283,6 +308,8 @@ public static function getShortName(string $fullyQualifiedClassName): string
283308
/**
284309
* Returns the TableMap object for this Criteria
285310
*
311+
* @phpstan-return \Propel\Runtime\Map\TableMap<T>
312+
*
286313
* @return \Propel\Runtime\Map\TableMap|null
287314
*/
288315
public function getTableMap(): ?TableMap
@@ -333,7 +360,7 @@ public function getTableNameInQuery(): ?string
333360
*
334361
* @throws \Propel\Runtime\Exception\LogicException
335362
*
336-
* @return \Traversable
363+
* @return \Traversable<T>
337364
*/
338365
public function getIterator(): Traversable
339366
{
@@ -350,4 +377,17 @@ public function getIterator(): Traversable
350377

351378
throw new LogicException('The current formatter doesn\'t return an iterable result');
352379
}
380+
381+
/**
382+
* Issue a SELECT query based on the current ModelCriteria
383+
* and format the list of results with the current formatter
384+
* By default, returns an array of model objects
385+
*
386+
* @phpstan-return T|mixed
387+
*
388+
* @param \Propel\Runtime\Connection\ConnectionInterface|null $con an optional connection object
389+
*
390+
* @return \Propel\Runtime\Collection\ObjectCollection|\Propel\Runtime\ActiveRecord\ActiveRecordInterface[]|mixed the list of results, formatted by the current formatter
391+
*/
392+
abstract public function find(?ConnectionInterface $con = null);
353393
}

src/Propel/Runtime/ActiveQuery/ModelCriteria.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
* @method \Propel\Runtime\ActiveQuery\ModelCriteria rightJoin($relation) Adds a RIGHT JOIN clause to the query
5454
* @method \Propel\Runtime\ActiveQuery\ModelCriteria innerJoin($relation) Adds a INNER JOIN clause to the query
5555
*
56+
* @phpstan-template T of \Propel\Runtime\ActiveRecord\ActiveRecordInterface
57+
* @phpstan-template TColl of \Propel\Runtime\Collection\Collection
58+
* @phpstan-template TReturn
59+
* @phpstan-extends \Propel\Runtime\ActiveQuery\BaseModelCriteria<T, TColl, TReturn>
60+
*
5661
* @author François Zaninotto
5762
*/
5863
class ModelCriteria extends BaseModelCriteria
@@ -78,6 +83,8 @@ class ModelCriteria extends BaseModelCriteria
7883
public const FORMAT_ON_DEMAND = '\Propel\Runtime\Formatter\OnDemandFormatter';
7984

8085
/**
86+
* @phpstan-var self<T, TColl, TReturn>|null
87+
*
8188
* @var \Propel\Runtime\ActiveQuery\ModelCriteria|null
8289
*/
8390
protected $primaryCriteria;
@@ -493,6 +500,8 @@ public function offset($offset)
493500
* ArticleQuery::create()->select(array('Id', 'Name'))->findOne();
494501
* => array('Id' => 1, 'Name' => 'Foo')
495502
*
503+
* @phpstan-return $this<T, \Propel\Runtime\Collection\ArrayCollection<T>, mixed[]>
504+
*
496505
* @param mixed $columnArray A list of column names (e.g. array('Title', 'Category.Name', 'c.Content')) or a single column name (e.g. 'Name')
497506
*
498507
* @throws \Propel\Runtime\Exception\PropelException
@@ -861,6 +870,12 @@ public function withColumn(string $clause, ?string $name = null)
861870
*
862871
* @psalm-param class-string<self>|null $secondaryCriteriaClass
863872
*
873+
* @phpstan-template TRel of \Propel\Runtime\ActiveRecord\ActiveRecordInterface
874+
*
875+
* @phpstan-param class-string<TRel> $secondaryCriteriaClass
876+
*
877+
* @phpstan-return \Propel\Runtime\ActiveQuery\ModelCriteria<TRel, TColl, TReturn>
878+
*
864879
* @see ModelCriteria::endUse()
865880
*
866881
* @param string $relationName Relation name or alias
@@ -1014,6 +1029,8 @@ public function mergeWith(Criteria $criteria, ?string $operator = null)
10141029
* Clear the conditions to allow the reuse of the query object.
10151030
* The ModelCriteria's Model and alias 'all the properties set by construct) will remain.
10161031
*
1032+
* @phpstan-return $this<T, \Propel\Runtime\Collection\ObjectCollection<T>, T>
1033+
*
10171034
* @return $this
10181035
*/
10191036
public function clear()
@@ -1032,6 +1049,8 @@ public function clear()
10321049
/**
10331050
* Sets the primary Criteria for this secondary Criteria
10341051
*
1052+
* @phpstan-param \Propel\Runtime\ActiveQuery\ModelCriteria<T, TColl, TReturn> $criteria
1053+
*
10351054
* @param \Propel\Runtime\ActiveQuery\ModelCriteria $criteria The primary criteria
10361055
* @param \Propel\Runtime\ActiveQuery\Join $previousJoin The previousJoin for this ModelCriteria
10371056
*
@@ -1280,6 +1299,8 @@ protected function preSelect(ConnectionInterface $con): void
12801299
* and format the list of results with the current formatter
12811300
* By default, returns an array of model objects
12821301
*
1302+
* @phpstan-return T|mixed
1303+
*
12831304
* @param \Propel\Runtime\Connection\ConnectionInterface|null $con an optional connection object
12841305
*
12851306
* @return \Propel\Runtime\Collection\ObjectCollection|\Propel\Runtime\ActiveRecord\ActiveRecordInterface[]|mixed the list of results, formatted by the current formatter

src/Propel/Runtime/ActiveRecord/ActiveRecordInterface.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
*
1414
* @author jaugustin
1515
*
16-
* @method array toArray(string $keyType = \Propel\Runtime\Map\TableMap::TYPE_FIELDNAME, bool $includeLazyLoadColumns = true, array $alreadyDumpedObjects = [], bool $includeForeignObjects = false): array
16+
* @method array toArray(string $keyType = \Propel\Runtime\Map\TableMap::TYPE_FIELDNAME, bool $includeLazyLoadColumns = true, array $alreadyDumpedObjects = [], bool $includeForeignObjects = false)
17+
* @method void initRelation(string $relationName)
18+
* @method self setVirtualColumn(string $name, $value)
19+
* @method int hydrate(array $row, int $startcol = 0, bool $rehydrate = false, string $indexType = \Propel\Runtime\Map\TableMap::TYPE_NUM)
20+
* @method mixed getPrimaryKey()
1721
*/
1822
interface ActiveRecordInterface
1923
{

src/Propel/Runtime/Collection/ArrayCollection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717
* Class for iterating over a list of Propel objects stored as arrays
1818
*
1919
* @author Francois Zaninotto
20+
*
21+
* @phpstan-template TType of \Propel\Runtime\ActiveRecord\ActiveRecordInterface
22+
* @phpstan-extends \Propel\Runtime\Collection\Collection<TType, array>
2023
*/
2124
class ArrayCollection extends Collection
2225
{
2326
/**
27+
* @phpstan-var TType
28+
*
2429
* @var \Propel\Runtime\ActiveRecord\ActiveRecordInterface
2530
*/
2631
protected $workerObject;

0 commit comments

Comments
 (0)